Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'maximum recursion depth exceeded while calling a Python object' while Parser constructor call with rule defined via 'forward' #75

Open
slonoten opened this issue Oct 13, 2020 · 0 comments

Comments

@slonoten
Copy link

All examples which use 'forward' rule from 'getting started' page https://nbviewer.jupyter.org/github/natasha/yargy/blob/master/docs/index.ipynb crashed with maximum recursion depth error exceeded.

EXPR = forward()
EXPR.define(or_(
    rule('a'),
    rule('(', EXPR, '+', EXPR, ')')
).named('EXPR'))
EXPR.normalized.as_bnf
Parser(EXPR)
---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-5-24cb41b0dd36> in <module>
----> 1 Parser(rule(EXPR))

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/parser.py in __init__(self, rule, tokenizer, tagger)
    252         context = Context(tokenizer, tagger)
    253         rule = rule.activate(context)
--> 254         rule = rule.normalized
    255         self.rule = rule.as_bnf.start
    256 

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/constructors.py in normalized(self)
    114             ReplaceOrTransformator,
    115             ReplaceEmptyTransformator,
--> 116             FlattenTransformator,
    117         )
    118 

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/constructors.py in transform(self, *transformators)
     94 
     95     def transform(self, *transformators):
---> 96         return TransformatorsComposition(transformators)(self)
     97 
     98     def activate(self, context):

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/visitor.py in __call__(self, item)
     26     def __call__(self, item):
     27         for transformator in self.transformators:
---> 28             item = transformator()(item)
     29         return item

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in __call__(self, root)
     63         for item in root.walk(types=ForwardRule):
     64             if item.rule:
---> 65                 item.define(self.visit(item.rule))
     66         return self.visit(root)
     67 

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in visit(self, item)
     71             return self.visited[item_id]
     72         else:
---> 73             item = self.resolve_method(item)(item)
     74             self.visited[item_id] = item
     75             return item

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in visit_Rule(self, item)
     94 
     95     def visit_Rule(self, item):
---> 96         return Rule([self.visit(_) for _ in item.productions])
     97 
     98     def visit_OrRule(self, item):

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in <listcomp>(.0)
     94 
     95     def visit_Rule(self, item):
---> 96         return Rule([self.visit(_) for _ in item.productions])
     97 
     98     def visit_OrRule(self, item):

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in visit(self, item)
     71             return self.visited[item_id]
     72         else:
---> 73             item = self.resolve_method(item)(item)
     74             self.visited[item_id] = item
     75             return item

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in visit_Production(self, item)
     83     def visit_Production(self, item):
     84         return Production(
---> 85             [self.visit_term(_) for _ in item.terms],
     86             item.main
     87         )

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in <listcomp>(.0)
     83     def visit_Production(self, item):
     84         return Production(
---> 85             [self.visit_term(_) for _ in item.terms],
     86             item.main
     87         )

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in visit_term(self, item)
     77     def visit_term(self, item):
     78         if is_rule(item):
---> 79             return self.visit(item)
     80         else:
     81             return item

... last 7 frames repeated, from the frame below ...

~/miniconda3/envs/tmp/lib/python3.7/site-packages/yargy/rule/transformators.py in visit(self, item)
     71             return self.visited[item_id]
     72         else:
---> 73             item = self.resolve_method(item)(item)
     74             self.visited[item_id] = item
     75             return item

RecursionError: maximum recursion depth exceeded

I have checked all examples with python 3.7.7 and 3.8.2 and yargy 0.14.0

If I replace 'forward' with appropriate 'repeat' construction all work fine even if BNF representation is identical

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant