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

Pipe in terminal regex not working as expected #1414

Open
sidhiadkoli opened this issue May 14, 2024 · 1 comment · May be fixed by #1415
Open

Pipe in terminal regex not working as expected #1414

sidhiadkoli opened this issue May 14, 2024 · 1 comment · May be fixed by #1415
Labels

Comments

@sidhiadkoli
Copy link

What is your question?

Facing an issue with a pipe in terminal regex.

Here is a subset of the grammar in question:

from lark import Lark

grammar = """
start: START

START: QUARTER [WS+ YEAR]
QUARTER: /q[1-4]/
WS: /\s/
YEAR: /(19[0-9]{2})|(20[0-3][0-9])/
"""

print(Lark(grammar).parse("q1 1923"))    # works
print(Lark(grammar).parse("q1 2023"))    # doesn't work

However, when we add parenthesis around the full YEAR regex, both the string examples get parsed correctly.

This works:

from lark import Lark

grammar = """
start: START

START: QUARTER [WS+ YEAR]
QUARTER: /q[1-4]/
WS: /\s/
YEAR: /((19[0-9]{2})|(20[0-3][0-9]))/
"""

print(Lark(grammar).parse("q1 1923"))    # works
print(Lark(grammar).parse("q1 2023"))    # works now

What am I missing here?

@MegaIng
Copy link
Member

MegaIng commented May 16, 2024

This is a bug in the way lark combines terminals, #1415 fixes it.

@erezsh erezsh added bug and removed question labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants