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

Multiple definition for Rule/Class error not consistent #23

Closed
alberth opened this issue Feb 5, 2018 · 2 comments
Closed

Multiple definition for Rule/Class error not consistent #23

alberth opened this issue Feb 5, 2018 · 2 comments
Assignees
Labels

Comments

@alberth
Copy link
Contributor

alberth commented Feb 5, 2018

  • parglare version: bc33add (Jan 27, 2018)
  • Python version: 3.5.2
  • Operating System: linux, ubuntu

Description

parglare sometimes accepts multiple definitions of the same non-terminal, and sometimes it doesn't.
Example case:

from parglare import Grammar
from parglare import Parser

text = "a"

gram1 = """\
A : "a" ;
A : "b" ;
"""

grammar = Grammar.from_string(gram1) # line 11
parser = Parser(grammar)
result = parser.parse(text)
print(result)

gram2 = """\
A : t="a" ;
A : t="b" ;
"""

grammar = Grammar.from_string(gram2) # line 21
parser = Parser(grammar)
result = parser.parse(text)
print(result)

Produces

a
Traceback (most recent call last):
  File "m.py", line 21, in <module>
    grammar = Grammar.from_string(gram2)
  File "~/compiler3/parglare/grammar.py", line 615, in from_string
    .parse(grammar_str, context=context),
  File "~/compiler3/parglare/parser.py", line 381, in parse
    context)
  File "~/compiler3/parglare/parser.py", line 619, in _call_reduce_action
    result = sem_action(context, subresults)
  File "~/compiler3/parglare/grammar.py", line 961, in act_production_rule
    .format(name))
parglare.exceptions.GrammarError: Multiple definition for Rule/Class "A"

Note that it crashes at line 21, but not line 11.

EDIT:

The only difference between both grammars are the t= additions in grammar2.

Merging both alternatives with a | avoids the crash.

@igordejanovic igordejanovic self-assigned this Feb 5, 2018
@igordejanovic
Copy link
Owner

Thanks for detailed report and test case. Looks like a bug. Will investigate.

@igordejanovic
Copy link
Owner

@alberth Fixed on master.

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

No branches or pull requests

2 participants