delph-in / pydelphin

Python libraries for DELPH-IN
https://pydelphin.readthedocs.io/
MIT License
79 stars 27 forks source link

RecursionError in TDL parsing #294

Closed goodmami closed 4 years ago

goodmami commented 4 years ago

The openproof/inflate-op.tdl file of the ERG has a list with over 1000 items in it, and this is causing a recursion error:

>>> from delphin import tdl
>>> list(tdl.iterparse('openproof/inflate-op.tdl'))
Traceback (most recent call last):
  [...]
  File "/home/goodmami/delphin/pydelphin/delphin/tdl.py", line 207, in __setitem__
    super(AVM, self).__setitem__(key, val)
  File "/home/goodmami/delphin/pydelphin/delphin/tfs.py", line 58, in __setitem__
    subdef[subkeys[1]] = val
  File "/home/goodmami/delphin/pydelphin/delphin/tdl.py", line 204, in __setitem__
    if not (val is None or isinstance(val, (Term, Conjunction))):
RecursionError: maximum recursion depth exceeded while calling a Python object

The list is flat, though, so it's probably not parsing that has a problem, but the list construction (REST.REST.REST.REST...).

goodmami commented 4 years ago

The offending TDL definition in the ERG seems to have been removed, and anyway this is not something I expect to occur in normal TDL files. A simple solution is to just increase the recursion limit while parsing, so I'm not going to do a proper fix for this and instead catch the RecursionError and provide a more informative error for the user.