Comments (5)
I was wondering about the same issue. As a fix, I suggest to continue to interpret the remaining rule when returning from a referenced rule. This can be easily done by replacing ll. 266-268 with
ruleStack.push(ruleTransition.target.ruleIndex);
this.collectFollowSets(transition.target, stopState, followSets, seen, ruleStack);
ruleStack.pop();
this.collectFollowSets(ruleTransition.followState, stopState, followSets, seen, ruleStack);
Two limitations still remain:
- The added call should only be done iff the previous call did not find any token, or only tokens inside a
(...)*
. A boolean return value ofcollectFollowSets
could pass the information when a mandatory token was found. This requires to detect if a token is added while inside aStarLoopEntry
andStarLoopBack
state. - Only after finding the state of the caret in
processRule
, we start tocollectFollowSets
based on this state alone. By doing so we lose our context until that moment, particularly uninterpreted parts of rule expression which lead us to the caret, and which could add useful tokens to the follow set. Of course, there is definitely a trade-off between speed and exactness.
from antlr4-c3.
I'm working on the fix for this (and some related issues such as handling for an empty rule body at, below, or after the rule transitioned to at the caret position). But @mike-lischke can you provide some clarity on whether we intend to return the Epsilon token as a candidate when parsing is successful terminated at the caret (without any subsequent tokens being required)? The epsilon is returned in some cases (when a rule can be parsed at the caret) but not in others. For example the test case "Most simple setup" does not take this into account - it expects Epsilon is not a candidate token but var c = a
is parseable as-is.
from antlr4-c3.
The Token.EPSILON
value is not really a token, but a mark for prediction (and hence also for code completion). As such it should not be returned, as it has no real value for the caller (what would you use it for?). If there's no candidate then the empty list says it all, no need to also check for EPSILON, right?
The fact that it is returned sometimes is probably just an oversight and if you can fix that, you are welcome to do so!
from antlr4-c3.
Understood. But to explain, the idea would be that if we return a list of tokens including the epsilon (or via a separate boolean property) we could tell the caller if one of the returned tokens is required - or if they are all optional. That said, they should already have that information from parsing in advance. And the situation becomes complicated taking into account rules and ignored tokens.
from antlr4-c3.
Hmm, what if there's a mix of mandatory and optional tokens? It would be more useful if that information is available for each candidate. If you return a flag or the EPSILON token then the caller can only assume that all candidates are optional.
from antlr4-c3.
Related Issues (20)
- Java port-> NPE happen when followSets contains FollowSetWithPath with null following member HOT 1
- Class extends value undefined is not a constructor or null when using yarn pnp and typescript4 HOT 1
- Infinite loop in processRule()
- Port for Antlr4 runtime HOT 2
- Simple expression parser tests fail when executing out-of-order HOT 3
- About Typescript Runtime (antlr4s) HOT 3
- Candidate token's follow TokenList is inaccurate when the candidate's origin is ambiguous HOT 1
- nameless ScopedSymbol problem HOT 2
- [Question] Antlr-c3 with antlr4-ng runtime, issue with parser.getVocabulary() HOT 2
- How to use with plain JavaScript? HOT 2
- CodeCompleteCore constructor now references getVocabulary is this correct or should it be vocabulary HOT 2
- function to convert editor cursor position to token position HOT 1
- Symbol Tabel HOT 3
- About using esbuild to building HOT 3
- the library ist going to infinity loop HOT 1
- [Bug]: Unexpected behaviour in getAllSymbolsSync of ScopeSymbol
- Add command to esbuild HOT 2
- Autocompleting empty string causes error HOT 1
- Add .cjs output to package HOT 1
- Option to choose the parser rule for which we need the candidates HOT 2
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-c3.