plex icon indicating copy to clipboard operation
plex copied to clipboard

Optional Token in parser

Open afonso360 opened this issue 8 years ago • 2 comments

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.

afonso360 avatar Apr 19 '17 14:04 afonso360

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.

goffrie avatar Apr 19 '17 17:04 goffrie

Sorry, didn't realize that I could do that.

The shorthand would be awesome tho!

afonso360 avatar Apr 21 '17 17:04 afonso360