Closed joranmulderij closed 2 years ago
After looking through the code I found that there is already a todo in the code. expressions.py
line 183. This would be really nice to get solved.
@joranmulderij could you post the example that's causing the infinite recursion, or a simplified version of it? That would make addressing the bug much easier because it can be turned into a test case. Thanks!
Here is a pretty minimal example of what would cause this issue. This is a stripped down version of my grammar.
from parsimonious.grammar import Grammar
language_grammar = r"""
expression = operator_expression / non_operator_expression
non_operator_expression = number_expression
operator_expression = expression "+" non_operator_expression
number_expression = ~"[0-9]+"
"""
grammar = Grammar(language_grammar)
grammar.parse('1 + 2')
When this script is run, infinite recursion occurs.
I was trying to write left associative operators in grammar, but an issue that kept coming up was infinite recursion. This could be solved by making every operator right associative, because the parser would cut out the option of just going down the same node over and over. Making it so that the parser can only visit one node twice if characters have been used up would completely solve this issue.