plex
plex copied to clipboard
Optional Token in parser
Would it be possible to add support for an optional token in the parser?
I'm trying to implement a parser that allows me to parse a language with an optional semicolon. If this is already implemented it probably should be documented.
It should work to do this:
optionalSemicolon: () {
=> (),
Semicolon => (),
}
...
manyStatements: ... {
=> ...
manyStatements[sts] statement[st] optionalSemicolon => ...
}
Here's an example for demo.rs: https://gist.github.com/goffrie/2dacbe5aefe7e4ea83d4b4da876ef39e
If you're asking for a convenient shorthand (like Semicolon? instead of adding a new nonterminal), then that's a valid feature request.
Sorry, didn't realize that I could do that.
The shorthand would be awesome tho!