Problem solving resync failing on a specific rule #2022
Unanswered
LordOfDragons
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using Chevrotain for code editing so resync is important. I managed to fix most resync problems I had but one situation I did not manage to fix. The language in question supports code like this:
This is not a problem. The problem is a user typing something like this:
The function declaration is incomplete and the user expects a list of possible types to be shown. The problem is that Chevrotain fails all possible rules and resync straight into the function body. This is by itself not totally wrong since Chevrotain looks for the next "end" tag it finds and considers all in between the function body. The problem is that the function beginning is not resynced.
So on to the rules in question.
This is part of the rules but it is the important part I think. As you can see a function declaration rule can be one of three things: a constructor, a destructor or a regular function. The constructor and destructor are gated and are ignored in this example. Only the "regularFunction" rule can apply. Inside the "regularFunction" rule the "fullyQualifiedClassName" does match the "M" character. Everything afterwards will fail and has to be resynced with imaginary token.
But Chevrotain fails to resync this rule and returns a "functionBegin" object with all three productions ("classConstructor", "classDestructor" and "regularFunction") set to "undefined".
I expect "regularFunction" to be a valid instance with "fullyQualifiedClassName" to be a valid instance and "regularFunctionName", "functionArguments" and "endOfCommand" to be "undefined".
Any ideas why I can't get this rule working? Do I have to rewrite it in a way to get Chevrotain to correctly resync the "regularFunction" rule?
EDIT: As a side note both "classConstructor" and "classDestructor" rule do not allow a "fullyQualifiedClassName" to be specified. Hence these rules start with an identifier which can be only "new" or "destructor". From a logic point of view Chevrotain should see that neither of these two rules can possibly match since their first token does not match. The "regularFunction" rule though has a first production that does match. So I'm astonished it gets rejected.
EDIT: EDIT:
This is a log output from the situation:
The first error suggests Chevrotain is inside the "regularFunction" rule but "[identifier, leftParanthesis, ..." is not a valid production for this rule.
I'm not sure if the second error message output by Chevrotain hints at the problem.
The following code produced this errors:
Beta Was this translation helpful? Give feedback.
All reactions