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

@@nameguard not honored in simple grammar #95

Closed
dvdrndlph opened this issue Apr 19, 2019 · 4 comments · Fixed by #97
Closed

@@nameguard not honored in simple grammar #95

dvdrndlph opened this issue Apr 19, 2019 · 4 comments · Fixed by #97

Comments

@dvdrndlph
Copy link

I am puzzled by this behavior:

from pprint import pprint
from tatsu import parse

GRAMMAR = """
sequence = {fingering}+ ;
fingering = '1' | '2' | '3' | '4' | '5' | 'x' ;
"""

test = "22"
ast = parse(GRAMMAR, test)
pprint(ast)  # Prints ['2', '2']

test = "xx"
ast = parse(GRAMMAR, test)
pprint(ast)  # tatsu.exceptions.FailedParse: (1:1) no available options :

Setting the grammar to the following works as expected:

GRAMMAR = """
sequence = {fingering}+ ;
fingering = /[1-5x]/ ; 
"""

Am I missing something?

@Victorious3
Copy link
Collaborator

You either have to tell the parser what rule to start with or name it "start".
I'm not sure why the other one works in the first place. There's also $ to specify the end of input, I'd add that to your starting rule.

@apalala
Copy link
Collaborator

apalala commented Apr 19, 2019

These are questions better asked on StackOverflow.

You probably need to check interactions with @@nameguard, which is turned on by default.

@apalala
Copy link
Collaborator

apalala commented Apr 21, 2019

Confirmed that the results is unexpected even with @@nameguard :: False

@apalala apalala changed the title Simple grammar throws exception @@nameguard not honored in simple grammar Apr 21, 2019
@dvdrndlph
Copy link
Author

Thanks for the quick turnaround. I learned a lot.

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

Successfully merging a pull request may close this issue.

3 participants