-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 generated code for Java.g4 grammar doesn't compile #1397
Comments
I should also note, I have gotten JSON.g4 to work with the Go target, and have been able to play with the generated parser apis... |
You should remove target-specific (Java) semantic predicates from grammar such as {Character.isJavaIdentifierStart(_input.LA(-1))}? and other. |
I see, this makes sense. Thanks for the quick reply! I'll try this out later this evening... |
I removed the inline Java code from the grammar and now I'm left with:
In the generated code: decl1>>> _alt := p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 139, p.GetParserRuleContext())
for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
...
}
p.SetState(1232)
p.GetErrorHandler().Sync(p)
decl2>>> _alt := p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 140, p.GetParserRuleContext()) The code above was inside the parser for this rule in Java.g4:
Not sure if this is the same problem encountered in #1401 ? |
@pboyer for you, sir! |
Thank you @ereyes01! I'll take a look at this tomorrow. |
@ereyes01 Would you mind including your modified Java.g4 grammar as well? |
Here's the patch I applied to Java.g4:
Thanks! |
@pboyer it works 👍 thanks! |
Thanks so much for checking, @ereyes01! |
Fixed by #1436 |
I believe this still isn't good. It's using a predicate when a simple character class will do: according to the Java language specification there's no need for anything but ASCII letters and numbers.. See PR antlr/grammars-v4#762. |
@BurtHarris No. Identifiers may be written using any of the world's languages. For more than you ever wanted to know, see my comments elsewhere. |
This issue seems still there.. I'm using ANTLR 4.7.2 with go
I generated the code with
The errors are in java8_lexer.go
Snippet: L 756
L 769
|
Try to use Java.g4 grammar instead of Java8.g4. It does not contain actions, semantic predicates and it's suitable for 8 version. |
Hi @KvanTTT, thanks for the reply Unfortunately Java.g4 is not available in https://github.com/antlr/grammars-v4/tree/master/java |
I mean the ordinary java grammar that consists of JavaLexer.g4 and JavaParser.g4. |
I'm trying to build a Java.g4 from Lexer and Parser.. Apparently this is not well documented in the README (please correct me if I'm wrong) and the only valid reference seems this one #638 but is really messy... I tried with
but without any output... Any hint about it? EDIT:
|
Unfortunately the command ahead only generates
As you can see java_lexer.go is missing @KvanTTT |
You should generate lexer at first. |
If I use
I expect to see both the |
Before submitting an issue to ANTLR, please check off these boxes:
Expected behavior
antlr4 -Dlanguage=Go Java.g4
should generate Go code that compiles. Java.g4 was taken from github.com/antlr/grammars-v4Other info:
antlr4 command is:
alias antlr4='java -Xmx500M -cp "/home/ereyes/.m2/repository/org/antlr/antlr4/4.6-SNAPSHOT/antlr4-4.6-SNAPSHOT.jar:$CLASSPATH" org.antlr.v4.Tool'
Actual behavior
The generated code does not compile. Here's what the Go compiler says:
Steps to reproduce the behavior
I looked at the error and attempted to fix by applying the patch below, but it still doesn't fix the problem:
... I tried to fix the parentheses in the cast in java_lexer.go. I also wondered if the intention was to cast to
rune
instead of char, which isn't a built-in type in Go. Anyways, here are the compiler errors after applying this patch:... and after changing
char
torune
:The text was updated successfully, but these errors were encountered: