Getting Stack Overflow error when using chumsky #58
-
So I tried implementing chumsky as a parser into a lang I'm working on, however when executing the test I wrote, I get a stack overflow error. Posting the entire code here would be a huge thing so, I put it into a repo. It can be found in this branch: https://github.com/FussballAndy/unreal-lang/tree/chumsky The files with chumsky content are the following:
And files with AST are located in I mainly used the nano rust example for reference, if this information is helpful to anybody. In order to only build and run the necessary test you can run the following I hope for anyone trying to help me, it is not too bad that the code is embedded in an entire project instead of some code snippets. Additionally, I hope the entire structure of me having expressions as well as statements being completely separated is not too big of a deal too. It would be very nice if someone could help me here hence so far I really like chumsky as a parser. If there happen to be any questions about my code don't hesitate to ask them! Note: I put this up as a discussion as I am not sure if it is my code being not well written or a problem with the api. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I've not fully looked into the code, but this sounds very typical of left-recursion. Chumsky is, underneath, a PEG parser and left recursion will cause infinite recursion. You can resolve this by restating your grammar in a way that avoids left recursion. For example, the left-recursive pattern
can be restated as
This section in the tutorial about binary operators demonstrates using this technique to properly parse binary operators with precedence in this way. |
Beta Was this translation helpful? Give feedback.
I've not fully looked into the code, but this sounds very typical of left-recursion. Chumsky is, underneath, a PEG parser and left recursion will cause infinite recursion.
You can resolve this by restating your grammar in a way that avoids left recursion.
For example, the left-recursive pattern
can be restated as
This section in the tutorial about binary operators demonstrates using this technique to properly parse binary operators with precedence in this way.