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

tokens section in combined grammar files can't work #338

Open
exKAZUu opened this issue Oct 3, 2013 · 2 comments
Open

tokens section in combined grammar files can't work #338

exKAZUu opened this issue Oct 3, 2013 · 2 comments

Comments

@exKAZUu
Copy link
Contributor

exKAZUu commented Oct 3, 2013

I modified your Java.g4 to the following file to make it suitable for the 4.1-opt release of ANTLR.
https://github.com/exKAZUu/Code2Xml/blob/92f3abaf173ebe31b5755c1d3cba7b3906e2d0ec/Code2Xml.Languages.ANTLRv4/Processors/Java/Java.g4

However, IntegerLiteral that is declared in the tokens section appears wrongly in JavaParser class instead of JavaLexer class.
Currently, both ANTLR 4.1 Java and C# targets generate such classes.

Note that the following issue shows the background to find this bug.
https://github.com/sharwell/antlr4cs/issues/28

@sharwell
Copy link
Member

sharwell commented Oct 3, 2013

More specifically, the tokens{} block does work in a combined grammar, but it only adds the specified tokens to the generated parser. This prevents the lexer from using the tokens in a ->type() command.

@ghost ghost assigned sharwell Oct 3, 2013
@sharwell
Copy link
Member

Apparently making this work is non-trivial. If you need access to items from the tokens{} block within your lexer rules (e.g. for a ->type command), you'll need to use separate lexer and parser grammars for now.

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

No branches or pull requests

2 participants