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

request for collectCandidates work even if there is syntax error #29

Closed
kingfolk opened this issue Jun 21, 2019 · 3 comments
Closed

request for collectCandidates work even if there is syntax error #29

kingfolk opened this issue Jun 21, 2019 · 3 comments

Comments

@kingfolk
Copy link

kingfolk commented Jun 21, 2019

Very appreciate about the work! I came across a problem and believe walker should have ability to go further even if there is syntax error before caret position. Suppose I have defined mysql grammar. And editing the following sentence,

select from |

where '|' represents caret position and it will get nothing by calling collectCandidates. Well, I can still do a little work to make it work. But It is also reasonable the walker keep walking if there is potential road to current request position. And I believe this is achievable by search algorithm like A-star. When walker walked to select and find no bridge to from, it search all neighbor rules until it finally reach from. And this search should be constrained because it maybe very time-consuming.

Is it make sense? Thanks!

@mike-lischke
Copy link
Owner

mike-lischke commented Jun 21, 2019

The problem is: what path should the walker take then? If the syntax is not correct before the caret there's no way to even find a path to the from keyword here. And walking all possible ways until you match the next given word is way too slow and can even lead to wrong paths when that following word appears in multiple sub rules.

Your request is impossible to implement.

Note: already the existing approach is sometimes consuming too much time and I had to apply several optimizations to make it passably work.

@kingfolk
Copy link
Author

kingfolk commented Jun 27, 2019

Yes, you are right. I tried implemented a different version of collectCandidates which is error tolerant(include all follwoing states if syntax error happens) and search will soon expand at syntax error and become very slow. I am reading "the definitive reference of antlr4" and it talks about the error recovery strategy. Can c3 handle error the similar way?

@mike-lischke
Copy link
Owner

ANTL4's error strategy is to try re-synching the ATN walk to the actual input. However, that goes only so far to find either a single additional token or a single missing token. This won't help in this scenario, which would require to (theoretically) skip an unknown number of tokens and resynch.

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

2 participants