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

Go target has syntax errors when MODE() is used #2324

Open
peterderivaz opened this issue Jul 6, 2018 · 0 comments
Open

Go target has syntax errors when MODE() is used #2324

peterderivaz opened this issue Jul 6, 2018 · 0 comments

Comments

@peterderivaz
Copy link

With the file SimpleLexer.g4:
lexer grammar SimpleLexer;
RULE0: 'a' -> pushMode(MODE1);
mode MODE1;
RULE1: 'b' -> Mode(MODE2);
mode MODE2;
RULE2: 'c' -> popMode;

If I build using Antlr downloaded today (4.7.1)
antlr4 -Dlanguage=Go -o parser SimpleLexer.g4

The emitted code contains:
p.SetMode(MODE2)

However, p and MODE2 are not defined in the file resulting in syntax errors.

Instead, the following symbols are defined:
const (
SimpleLexerMODE1 = iota + 1
SimpleLexerMODE2
)

My guess is there is a bug in:
https://github.com/antlr/antlr4/tree/master/tool/resources/org/antlr/v4/tool/templates/codegen/Go
but I am not sure how to fix it.

Other targets (e.g. Python2 and Java) seem to work fine because MODE2 is defined in the file (instead of SimpleLexerMODE2).

For the moment I am working around this by using pushMode(MODE2) in RULE1 and popmode,popmode in RULE2.

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

1 participant