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 with backslashes need to be escaped in tokens file #163

Closed
robstoll opened this issue Sep 29, 2014 · 1 comment
Closed

tokens with backslashes need to be escaped in tokens file #163

robstoll opened this issue Sep 29, 2014 · 1 comment
Assignees

Comments

@robstoll
Copy link
Contributor

I have defined a token as follows:

tokens{ Backslash = '\\';}

and I am reusing the resulting tokens file in another grammar like this

options{tokenVocab=OtherGrammar;}

Unfortunately, I get a NullPointerException when reusing it since the token is defined as follows in the tokens file

' \\' = 78

it should be defined as follows (then I get no NullPointerException any more):

'\\\\' = 78

Stackstrace

[13:17:57] java.lang.NullPointerException
    at org.antlr.tool.AssignTokenTypesBehavior.aliasTokenIDsAndLiterals(AssignTokenTypesBehavior.java:288)
    at org.antlr.tool.AssignTokenTypesBehavior.defineTokens(AssignTokenTypesBehavior.java:225)
    at org.antlr.tool.CompositeGrammar.assignTokenTypes(CompositeGrammar.java:347)
    at org.antlr.tool.Grammar.setGrammarContent(Grammar.java:649)
    at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createNewGrammar(ANTLRGrammarEngineImpl.java:192)
    at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createParserGrammar(ANTLRGrammarEngineImpl.java:225)
    at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createCombinedGrammar(ANTLRGrammarEngineImpl.java:203)
    at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createGrammars(ANTLRGrammarEngineImpl.java:165)
    at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.analyze(ANTLRGrammarEngineImpl.java:272)
    at org.antlr.works.grammar.engine.GrammarEngineImpl.analyze(GrammarEngineImpl.java:325)
    at org.antlr.works.grammar.CheckGrammar.run(CheckGrammar.java:70)
    at java.lang.Thread.run(Thread.java:745)
@sharwell
Copy link
Member

If the following appears in a grammar:

tokens{ Backslash = '\\';}

Then the following should appear in the .tokens file:

Backslash=78
'\\'=78

According to the issue description, the tokens file generation process is working correctly.

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

Successfully merging a pull request may close this issue.

2 participants