WIP
Typescript Parser generator based on chevrotain
npm install -g drivel
drivel gen ./grammar ./src/parser
Grammar can be defined using a yaml like synthax
The rules sections define the differents rules to follow during parsing. Currently as drivel is using generating a parser using chevrotain, the rules are expected to be left recursive.
You can directly inline string literal token
A start
rule is required as a parsing starting point
rules:
start: "hello" "world"
The following suffix can be added after a token:
?
: Pattern can either be matched 0 or 1 time*
: Pattern can be matched 0 or more times+
: Pattern can be matched 1 or more times
rules:
start: "hello"? "world"*
You can define a sub sequence by wrapping mulitple instructions inside parenthesis
rules:
start: ("hello" "world")+
You can define tokens that follow custom pattern using either regex a string literals
tokens:
singleQuoteString:
pattern: /'(?:[^'\\]|\\.)*'/
doubleQuoteString:
pattern: /"(?:[^"\\]|\\.)*"/
trueLiteral:
pattern: true
falseLiteral:
pattern: false
integer:
pattern: /[\d]+/
Tokens are then usable inside rules
rules:
start: value
value: singleQuoteString | doubleQuoteString | trueLiteral | falseLiteral | integer
rules:
start: value:"hello" "world"