Skip to content
Discussion options

You must be logged in to vote

Hey @ymc9,

Does such a rule generate a token implicitly?

Yes, every unique usage of keywords (anything wrapped inside of a string) generates a token type for the lexer. This is expected behavior for basically all parser generators (such as ANTLR). The obvious fix is to modify the Person rule slightly:

Person:
    'person' name=ID (array?='[' ']')?;

The issue is that since [] is a longer token type pattern, it has precedence over shorter ones, such as [. So during the lexing phase, encountering the string [] will always yield the [] token instead of separate [ and ] tokens.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ymc9
Comment options

Answer selected by ymc9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants