Skip to content

RecursionError with moderately nested expressions #86

@ilkka-torma

Description

@ilkka-torma

It seems that idiomatically written expression parsers cannot handle more than a few dozen nesting levels before triggering a RecursionError with Python's default recursion limit. For example, the calculator example from the documentation can't handle the expression

1+(1+(1+( ... 1+(1) ... )))

with 46 pairs of nested parentheses. The number of nested function calls produced by parsy seems to increase more or less linearly with the nesting depth of the expression, so one workaround is to temporarily increase the recursion limit.

I ran into this issue when using a more complex parser on some computer-generated code. It seemed to have a nesting depth of about 10, but the number of calls per nesting level is likely higher than with the calculator example, since I have many more expression types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions