Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Token in parser #20

Open
afonso360 opened this issue Apr 19, 2017 · 3 comments
Open

Optional Token in parser #20

afonso360 opened this issue Apr 19, 2017 · 3 comments

Comments

@afonso360
Copy link

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.

@goffrie
Copy link
Owner

goffrie commented Apr 19, 2017

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.

@afonso360
Copy link
Author

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

The shorthand would be awesome tho!

@maxrdz
Copy link

maxrdz commented Oct 30, 2023

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.

Correct me if i'm wrong, but I believe this causes a shift-reduce conflict?

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants