Skip to the content.

Consume text

These are the basic building blocks of your grammar. They consume text if they match, meaning that they will advance the current parsing position.

syntax meaning notes
. any character Match exactly one character and return it as a string. This will fail only if the end of the text is reached.
"literal"
'literal'
literal string Match the exact string and return it. You can use the same escape sequences as in JavaScript. You can use single or double qoutes.
"literal"i
'literal'i
literal string, ignore case As above, except the match is case-insensitive.
[chars] one of characters Match one character from a set and return it as a string. The syntax is the same as in javascript regular expressions. You can use - for character ranges and ^ for matching anything except the listed characters. You can also use character classes like \s or \w.
[chars]i one of characters, ignore case As above, except the match is case-insensitive.

Repetition

Repetition operators, as in regular expressions, indicate that the preceding expression should be matched repeatedly.

syntax meaning notes
expr ? zero or one Match the expression, and return its result. Otherwise, return undefined, but do not fail the match.
expr * zero or more Match the expression zero or more times. Return an array of results.
expr + one or more As above, except the match will fail if the expression is not matched at least once.

Look-ahead

Look-ahead operators allow you to check if the following expression will/will not match, without advancing the current parsing position.

syntax meaning notes
& expr positive look ahead Match the expression, and return its result. Otherwise, return undefined, but do not fail the match.
! expr negative look ahead As above, except the match will fail if the expression matches.

Sequence

*expr1 expr2* ... match all expressions in sequence