Comments (10)
Do you happen to know which commit you're using? (Ideally the SHA hash for it)
from antlr4.
Yes, it is
28ee391
from parrt/antlr4
from antlr4.
Can you add the following assertions to track down the source of failure?
In the two ATNConfig
constructors that set state
and semanticContext
, add:
assert state != null;
assert semanticContext != null;
from antlr4.
okay, here we go:
Exception in thread "main" java.lang.AssertionError: state is null
at org.antlr.v4.runtime.atn.ATNConfig.<init>(ATNConfig.java:112)
at org.antlr.v4.runtime.atn.ATNConfig.<init>(ATNConfig.java:98)
at org.antlr.v4.runtime.atn.ParserATNSimulator.actionTransition(ParserATNSimulator.java:1043)
at org.antlr.v4.runtime.atn.ParserATNSimulator.getEpsilonTarget(ParserATNSimulator.java:1032)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:990)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:946)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:912)
at org.antlr.v4.runtime.atn.ParserATNSimulator.computeReachSet(ParserATNSimulator.java:711)
at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:521)
at org.antlr.v4.runtime.atn.ParserATNSimulator.predictATN(ParserATNSimulator.java:331)
at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:296)
at org.eeve.antlrgen.parser.ANTLRv4Parser.strongExpr(ANTLRv4Parser.java:886)
at org.eeve.antlrgen.parser.ANTLRv4Parser.expr(ANTLRv4Parser.java:1146)
at org.eeve.antlrgen.parser.ANTLRv4Parser.grammarRule(ANTLRv4Parser.java:398)
at org.eeve.antlrgen.parser.ANTLRv4Parser.gramma(ANTLRv4Parser.java:150)
at org.eeve.antlrgen.ANTLRGenTest.parseStatic(ANTLRGenTest.java:92)
at org.eeve.antlrgen.ANTLRGenTest.main(ANTLRGenTest.java:38)
from antlr4.
It would definitely help if you are able to post an example grammar and input for me to duplicate this issue. You may not have to post input - it looks like you have a case where Transition
is being constructed with target==null
. You could add an assertion to the Transition
constructor as a check.
Have you tried regenerating the code?
from antlr4.
Okay, here is the grammar
grammar ANTLRv4;
ruler returns [String r]
: t=ID ':' alts+=expr ('|' alts+= expr)* ';'
{ $r = "x"; }
;
strongExpr returns [String r]
: ID { $r = "x"; }
| '(' ep=parenExpr ')' { $r = "x"; }
| e1=strongExpr '?' { $r = "x"; }
;
expr returns [String r]
: e=strongExpr (e2=expr)? { $r = "x"; }
| e1=expr '->' ID {$r = "x"; }
;
parenExpr returns [String r]
: e1=expr '|' e2=parenExpr { $r = "x"; }
| expr {$r = $expr.r; }
;
ID : ('A'..'Z'|'a'..'z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
And here is a test input:
x:x;
Code for parser execution:
ANTLRv4Lexer lex = new ANTLRv4Lexer(new ANTLRInputStream(new FileInputStream(new File("test.input"))));
CommonTokenStream tokens = new CommonTokenStream(lex);
new ANTLRv4Parser(tokens).ruler();
from antlr4.
Thanks, that's perfect. I was able to derive the following grammar as a unit test for the issue which I'm now working to fix.
grammar T;
start
: ID ':' expr
;
expr
: primary expr? {}
| expr '->' ID
;
primary
: ID
;
ID : [a-z]+;
Input: x:x
from antlr4.
well, after merging your commits, I get the anticipated exception during parser building
[java] Exception in thread "main" java.lang.IllegalStateException: Cannot serialize a transition to a removed state.
[java] at org.antlr.v4.automata.ATNSerializer.serialize(ATNSerializer.java:138)
[java] at org.antlr.v4.automata.ATNSerializer.getSerialized(ATNSerializer.java:281)
[java] at org.antlr.v4.codegen.model.SerializedATN.<init>(SerializedATN.java:43)
[java] at org.antlr.v4.codegen.model.Parser.<init>(Parser.java:86)
[java] at org.antlr.v4.codegen.ParserFactory.parser(ParserFactory.java:54)
[java] at org.antlr.v4.codegen.OutputModelController.parser(OutputModelController.java:145)
[java] at org.antlr.v4.codegen.OutputModelController.buildParserOutputModel(OutputModelController.java:84)
[java] at org.antlr.v4.codegen.CodeGenerator.generateParser(CodeGenerator.java:132)
[java] at org.antlr.v4.codegen.CodeGenPipeline.process(CodeGenPipeline.java:51)
[java] at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:353)
[java] at org.antlr.v4.Tool.process(Tool.java:319)
[java] at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:283)
[java] at org.antlr.v4.Tool.main(Tool.java:173)
While this is better than a fail at runtime, it is still not satisfactory, as I don't know what I have done wrong.
from antlr4.
Once this issue is corrected, it will be tagged with "status:pull-request" until it gets closed. :) The test I've implemented so far is in place to help track down the issue, but like you saw it doesn't create a working grammar.
from antlr4.
I am no longer able to reproduce this bug.
from antlr4.
Related Issues (20)
- Usage of `\p{Alpha}` does not work as expected on earlier versions of JDK 17
- ATN.NextToken(state) should be memoized HOT 3
- PL/SQL grammar cannot recognise identifiers that start with keywords HOT 2
- Migration bug in golang runtime HOT 5
- Could not deserialize ATN with version 3 (expected 4) with Hibernate 6 HOT 3
- Tool does not generate any constants for channels for the TypeScript target HOT 5
- Generate an abstract class/interface for rule containing only other parser rules as unnamed subrules
- [Swift] Add privacy manifest HOT 2
- [Go] Type signature error
- How can we write multiple parsers to use the same lexer? HOT 1
- [CSharp] Member GetMaxTokenType missing in IVocabulary
- Missing TypeScript methods
- [TorqueScript: C++]Old scripting language conversion HOT 2
- Inquiry Regarding Runtime Performance of ANTLR4 in Rust
- Left recursive rules that do not conform to a pattern ANTLR can handle HOT 1
- Android Tool run
- Separated package/artifactId when the minor version is upgraded for compatibility issues
- [Go] Can not use BailErrorStrategy since ParseCancellationException is not implement HOT 1
- Issue with using ANTLR4 from Julia via PyCall
- [TypeScript target] I would like to know how to create a custom visitor in TypeScript. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from antlr4.