erezsh / plyplus

a friendly yet powerful LR-parser written in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Glitch when there are undefined rules

lelit opened this issue · comments

The script:

from plyplus import Grammar

grammar = Grammar("""
start: foo;
""")

generates the following traceback:

Traceback (most recent call last):
  File "err.py", line 5, in <module>
    """)
  File "/tmp/e/lib/python3.6/site-packages/plyplus/plyplus.py", line 560, in __init__
    self._grammar = self._create_grammar(grammar, source, tab_filename, options)
  File "/tmp/e/lib/python3.6/site-packages/plyplus/plyplus.py", line 569, in _create_grammar
    return _Grammar(grammar_tree, source, tab_filename, options)
  File "/tmp/e/lib/python3.6/site-packages/plyplus/plyplus.py", line 626, in __init__
    GrammarVerifier().verify(grammar_tree)
  File "/tmp/e/lib/python3.6/site-packages/plyplus/plyplus.py", line 620, in verify
    raise ParseError("Undefined rules: %s" % undefined_rules)
plyplus.common.ParseError: U
n
d
e
f
i
n
e
d
 
r
u
l
e
s
:
 
{
'
f
o
o
'
}

The two exceptions raised near line 620 of plyplus.py should probably be:

if undefined_tokens:
    raise ParseError(["Undefined tokens: %s" % undefined_tokens])
if undefined_rules:
    raise ParseError(["Undefined rules: %s" % undefined_rules])

Thanks for pointing it out!