sighingnow / parsec.py

A universal Python parser combinator library inspired by Parsec library of Haskell.

Home Page:https://parsecpy.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compose breaks down quite fast, two many recursions

seppeljordan opened this issue · comments

First of all: I really like parsec. It is solid work, but I encountered a problem. I really don't know what one can do about that in python but (at least on my machine) one can only compose ~200 parsers. I used python 3.6.2.

#!/usr/bin/env python

import parsec

n = 198

p = parsec.string('')
for x in range(0,n):
    p = p.compose(parsec.string('a'))
print(p.parse('a' * n))

gives

...
  File "/nix/store/fikb92d9was1qg3h4lwnay70i2ayzzd4-python3.6-parsec-3.3/lib/python3.6/site-packages/parsec/__init__.py", line 57, in success
    return Value(True, index, actual, None)
RecursionError: maximum recursion depth exceeded while calling a Python object

Thanks for your report. I will check it as soon as possible.

I think the only for your problem is to increase the system's recursion limit, using sys.setrecursionlimit. You even will encounter the same problem in a trivial hand-written recursive decent parser when you stack the same parser (call the same function recursively) so many times.

The default recursion depth limit is 1000 and it is too small for specific applications.