You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After experimenting in the playground for a bit I decided that this library seemed like the perfect fit for my project. In case you're curious, I'm trying to create a DSL for REST-api generation.
All was well until I tried adding grammar for generic types. In case you need a memory refresher, generics basically have a structure like this:
TypeA<TypeB>
Looks pretty simple and harmless doesn't it? Well what if TypeB is a generic type too?
TypeA<TypeB<TypeC>>
We get a recursive structure. I expressed this in my parser like this:
This worked fine for me, until I tried to use a typeReference in an OR-rule (full code + error below). I tried increasing maxLookahead, but that didn't help.
I'm not sure if this is left recursion (I know it's unsupported), the fact that it works just fine when it's not wrapped in an OR-rule makes me think it isn't. If it is left-recursion then the warning about it doesn't work.
So my question is: how do I express this grammar in chevrotain? Is it impossible and should I drop support for generics-in-generics? Did I increase my maxLookahead not far enough (I tried till 10)?
Thanks in advance! (if you need anymore information feel free to ask)
Output
Error: Parser Definition Errors detected:
Ambiguous alternatives: <1 ,3> in <OR> inside <handlerReturnDeclaration> Rule,
<NamespacedIdentifier, '<', NamespacedIdentifier, '<'> may appears as a prefix path in all these alternatives.To Resolve this, try one of of the following:
1. Refactor your grammar to be LL(K) for the current value of k (by default k=4})
2. Increase the value of K for your grammar by providing a larger 'maxLookahead' value in the parser's config
3. This issue can be ignored (if you know what you are doing...), see https://sap.github.io/chevrotain/documentation/4_2_0/interfaces/iparserconfig.html#ignoredissues for more details
-------------------------------
Ambiguous alternatives: <1 ,3> in <OR> inside <handlerReturnDeclaration> Rule,
<NamespacedIdentifier, '<', NamespacedIdentifier, '['> may appears as a prefix path in all these alternatives.To Resolve this, try one of of the following:
1. Refactor your grammar to be LL(K) for the current value of k (by default k=4})
2. Increase the value of K for your grammar by providing a larger 'maxLookahead' value in the parser's config
3. This issue can be ignored (if you know what you are doing...), see https://sap.github.io/chevrotain/documentation/4_2_0/interfaces/iparserconfig.html#ignoredissues for more details
-------------------------------
Ambiguous alternatives: <1 ,3> in <OR> inside <handlerReturnDeclaration> Rule,
<NamespacedIdentifier, '<', NamespacedIdentifier, ','> may appears as a prefix path in all these alternatives.To Resolve this, try one of of the following:
1. Refactor your grammar to be LL(K) for the current value of k (by default k=4})
2. Increase the value of K for your grammar by providing a larger 'maxLookahead' value in the parser's config
3. This issue can be ignored (if you know what you are doing...), see https://sap.github.io/chevrotain/documentation/4_2_0/interfaces/iparserconfig.html#ignoredissues for more details
-------------------------------
Ambiguous alternatives: <1 ,3> in <OR> inside <handlerReturnDeclaration> Rule,
<NamespacedIdentifier, '<', NamespacedIdentifier, '>'> may appears as a prefix path in all these alternatives.To Resolve this, try one of of the following:
1. Refactor your grammar to be LL(K) for the current value of k (by default k=4})
2. Increase the value of K for your grammar by providing a larger 'maxLookahead' value in the parser's configy providing a larger 'maxLookahead' value in t you are doing...), see https://sap.github.io/chevrotain/documenthe parser's config noredissues for more details
3. This issue can be ignored (if you know what you are doing...), see https://sap.github.i:\VOLATILE\workspace-2\TSAG\node_modules\chevrotain\lib\src\parseo/chevrotain/documentation/4_2_0/interfaces/iparserconfig.html#ignoredissues for more details
The first and third options of that OR both start with "typeReference".
"typeReference" may have infinite length. That is to say for every K (maxlookahead) there would
be N > K thus that the "typeReference" rule would consume N tokens.
Chevrotain is a Recursive decent LL(K) parser, this means it needs to lookahead to choose between alternatives, and that it can look ahead at most K tokens ahead. but in our case because the prefix of these two alternatives is infinity long it can never be sure it picked the correct alternative.
You need to refactor this to something equivelent such as:
After experimenting in the playground for a bit I decided that this library seemed like the perfect fit for my project. In case you're curious, I'm trying to create a DSL for REST-api generation.
All was well until I tried adding grammar for generic types. In case you need a memory refresher, generics basically have a structure like this:
Looks pretty simple and harmless doesn't it? Well what if
TypeB
is a generic type too?We get a recursive structure. I expressed this in my parser like this:
This worked fine for me, until I tried to use a
typeReference
in anOR
-rule (full code + error below). I tried increasingmaxLookahead
, but that didn't help.I'm not sure if this is left recursion (I know it's unsupported), the fact that it works just fine when it's not wrapped in an
OR
-rule makes me think it isn't. If it is left-recursion then the warning about it doesn't work.So my question is: how do I express this grammar in chevrotain? Is it impossible and should I drop support for generics-in-generics? Did I increase my
maxLookahead
not far enough (I tried till 10)?Thanks in advance!
(if you need anymore information feel free to ask)
Output
Lexer
Parser
The text was updated successfully, but these errors were encountered: