How to force an error token if resync recovery fails? #2013
Replies: 4 comments 11 replies
-
Hello @LordOfDragons For the https://github.com/LordOfDragons/vscode-langext-dragonscript/blob/dd59509907d098a65796dc36ed2f16bd51da5547/server/src/parser.ts#L926 I don't believe single token insertion recovery is applicable. That type of error recovery only happens within the scope of the current grammar rule. I also suspect the recovery problem is related to the general structure / pattern of the binary expressions.
I could try:
|
Beta Was this translation helpful? Give feedback.
-
Are there any tips on how to best design a CST grammar or known situations where such problems occur? Maybe this helps me to figure out what could be the problem. |
Beta Was this translation helpful? Give feedback.
-
I needed to create a small grammar (XML) outputting a CST in the past.
There was also a bug (fixed since) which was handled by overriding an internal Chevrotain function: I suspect you will need to dive into the Chevrotain internals:
Would this pattern also affect the recovery behavior of binary expressions? I don't know... |
Beta Was this translation helpful? Give feedback.
-
I tried recreating the problem using https://chevrotain.io/playground/ but I always get
Is the playground using an old chevrotain library? The strange thing is I do not use "tokenize" anywhere in the playground code so I have no idea where this one is coming from. |
Beta Was this translation helpful? Give feedback.
-
I've got this parser definition: https://github.com/LordOfDragons/vscode-langext-dragonscript/blob/dd59509907d098a65796dc36ed2f16bd51da5547/server/src/parser.ts .
The problem happens with a script like this:
Chevrotail totally breaks down in this situation. The problem is the function call "*" is missing an argument and thus this rule can not be completed:
https://github.com/LordOfDragons/vscode-langext-dragonscript/blob/dd59509907d098a65796dc36ed2f16bd51da5547/server/src/parser.ts#L737
What happens is that all code after this line is dead. The re-sync travels all the way up to the top production rule instead of stopping at something simple like the ")" token closing an expression group.
Hence what happens is that Chevrotain fails to realize it could fix the problem by simply adding an error token in the OR() clause in this rule:
https://github.com/LordOfDragons/vscode-langext-dragonscript/blob/dd59509907d098a65796dc36ed2f16bd51da5547/server/src/parser.ts#L926
Is there a way to explicitly add a "ERROR()" production to this OR() clause to tell Chevrotain to inject exactly here an error token should it fail to complete this rule?
I also tried using "{resyncEnabled: false}" to stop the re-syncing bubbling up but to no avail. The breaking just is differently but prevents all kind of editor helps to be deduced which customers expect to be present.
Beta Was this translation helpful? Give feedback.
All reactions