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

not finding ambiguous parse #536

Closed
christolmicrosoft opened this issue Mar 24, 2020 · 2 comments
Closed

not finding ambiguous parse #536

christolmicrosoft opened this issue Mar 24, 2020 · 2 comments
Labels

Comments

@christolmicrosoft
Copy link

christolmicrosoft commented Mar 24, 2020

Greetings, and thank you for your excellent package.

I'm not sure if I'm doing something wrong here, but the following CFG gives me an unambiguous parse on the input "a b", when I believe it should be ambiguous

%import common.WS
%ignore WS
start: a -> start_0
a: "a" b -> a_0
| "a" "b" -> a_1
b: "b" -> b_0

this grammar works though, and provides an ambiguous parse for "a b":

%import common.WS
%ignore WS
start: a -> start_0
| a2 -> start_1
a: "a" b -> a_0
a2: "a" "b" -> a_1
b: "b" -> b_0
@erezsh
Copy link
Member

erezsh commented Mar 24, 2020

I think you're right, and this is a bug. I'll mark it as such.

I hope you can work around it for now.

I'll also add another version of this bug, which is even more innocent.

from lark import Lark

g1 = """
start: a
a: "a" "b" -> a_0
 | a2
a2: "a" b -> a_1
b: "b"
"""

g2 = """
start: a
a: "a" b -> a_0
 | a2
a2: "a" "b" -> a_1
b: "b"
"""

print(Lark(g1, ambiguity='explicit').parse("ab"))
print(Lark(g2, ambiguity='explicit').parse("ab"))

# Tree(start, [Tree(a_0, [])])
# Tree(start, [Tree(_ambig, [Tree(a_0, [Tree(b, [])]), Tree(a, [Tree(a_1, [])])])])

@erezsh
Copy link
Member

erezsh commented Jun 22, 2024

This bug has been fixed in #1427 , and will make it into v1.2 🎉

Only took 4 years.

@erezsh erezsh closed this as completed Jun 22, 2024
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