Comments (10)
Hi @neon12345 I trying the demo but I get an error. Can you help me figuring out how to use the tool?
I also created several libraries to generate an AST on top of ANTLR's parse tree. One we created for TypeScript is called Tylasu https://github.com/Strumenta/tylasu . Maybe there are some overlaps with you work.
I think getting suggestions for ANTLR 5 is very useful, especially when coming from tool builders like you.
Regarding your question, I am not sure I get what you mean with "unique antlr state for as many positions in the grammar as possible". Could you give me an example?
from antlr5.
Your ISP needs to support IPv6. Other than that, when you press the Run button, the source code on the top left is sent to the server and the returned JavaScript AST is transformed with the script at the bottom into the top right result editor. There is also some help accessible with the bottom tab.
from antlr5.
For recursive rules, the parentState is set for the context. What we need from the context and currently have to patch in, is the state before the precpred.
_localctx = _tracker.createInstance<PatternContext>(parentContext, parentState);
pushNewRecursionContext(_localctx, startState, RulePattern);
setState(1913);
if (!(precpred(_ctx, 2))) throw FailedPredicateException(this, "precpred(_ctx, 2)");
setState(1914);
match(Swift5Parser::AS);
from antlr5.
@neon12345 this is how I see the demo: https://www.loom.com/share/1523249bd9f2458785db29ef2c4ea421
I guess my ISP should support IPv6
from antlr5.
@ftomassetti
Can you test IPv6 compatibility with for example https://ipv6-test.com or https://test-ipv6.com/ to be sure? Also try ping antlr.syncsocial.de
from antlr5.
For recursive rules, the parentState is set for the context. What we need from the context and currently have to patch in, is the state before the precpred.
Can't this be compute using "parentState" and the ATN containing that NFA state number? Given a parse tree, get "parentState" and "see if it is one of your recursive productions". Then, examine the ATN: follow the edges in the ATN back until you find a transition that involves "_p". Presumably, this would be a PrecedencePredicateTransition edge.
from antlr5.
Can't this be compute using "parentState" and the ATN containing that NFA state number?
The way how we work with antlr is a visitor that gives the information about the position in the grammar with the antlr states. From a parsing perspective, it is best to get the information from the current context without many calculations. Thus from our perspective, it would be more valuable to give another state to the context. But I don't know other use cases and why the state had to be stored this way.
from antlr5.
@ftomassetti Can you test IPv6 compatibility with for example https://ipv6-test.com or https://test-ipv6.com/ to be sure? Also try
ping antlr.syncsocial.de
Oh... surprisingly ipv6 does not work for me, so I am afraid I cannot watch the demo
from antlr5.
it would be more valuable to give another state to the context. But I don't know other use cases and why the state had to be stored this way.
Considering the result of a parse is a parse tree, it seems fine to "hang" the "calling state of the ATN to another ATN" in the parent parse tree node. (It really should have been an edge ID because, possibly, one could have multiple edges with the same non-terminal symbol from a state.)
To avoid computing the precedence predicate state in a parse tree traversal, you could pre-compute prior to parse the precedence predicate state from the ATNs, and place them in a O(1) map.
So, for the java grammar, state "1372" would be the "parentState" for an ExpressionContext, but the computed precedence predicate state be "1370".
from antlr5.
@kaby76
Thanks for the suggestions, I don't have a problem getting the values I need and it is fine for me to keep things like they are. I just wonder if the stored information is used as intended or could be improved, considering the state is also not consistently stored in the parse tree.
from antlr5.
Related Issues (20)
- Squashed errors for mutually left-recursive rules with incorrect positions HOT 6
- Integrate Kotlin runtime HOT 38
- Trim non-critical runtimes HOT 5
- Rename references to ANTLR v4 in references to ANTLR v5 HOT 2
- Renaming Modes.DEFAULT_MODE to Modes.DEFAULT in the Kotlin runtime and target HOT 1
- Rename grammars suffix from g4 to g5 HOT 3
- Update copyright message and package name HOT 9
- How to run test locally in a reproducible way? HOT 15
- Update docs for v5
- Remove reference to Python in GitHub Actions workflow
- Rename Antlr4MojoTest in Antlr5TMojoTest
- Help with kotlin-js HOT 17
- Design - Compile the runtime Lexer to WebAssembly HOT 16
- Migrate epsilon optimization related changes to Kotlin HOT 3
- Normalize target and folder capitalization
- Rename java runtime package to org.antlr.v5.runtime.java
- Migrate the build to Gradle HOT 4
- Change nullables to non-nullables in core runtime HOT 1
- Generate UnicodeData using Gradle HOT 1
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 antlr5.