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

I got an unexpected parsing result when using Forward() #451

Open
JacobiSong opened this issue Nov 21, 2022 · 0 comments
Open

I got an unexpected parsing result when using Forward() #451

JacobiSong opened this issue Nov 21, 2022 · 0 comments
Assignees

Comments

@JacobiSong
Copy link

import pyparsing as pp
pp.ParserElement.enable_left_recursion()

# Parser 1
A = pp.Forward()
B = pp.Forward()

A <<= B + pp.Literal("a") + B
B <<= A | pp.Literal("b")
print(B.parse_string("bab"))

# Parser 2
B = pp.Forward()

B <<= B + pp.Literal("a") + B | pp.Literal("b")
print(B.parse_string("bab"))
# Parser 1 output
['b']
# Parser 2 output
['b', 'a', 'b']

I don't known why the ouputs are different.

@ptmcg ptmcg self-assigned this Nov 25, 2022
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

2 participants