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

Problem matching the body of annotations like @Annotation(title, some longer description) #1325

Closed
jjalowie opened this issue Aug 19, 2023 · 2 comments
Labels
Earley Issues regarding the Earley parser question

Comments

@jjalowie
Copy link

What is your question?

I'm trying to write a parser for annotations like @Annotation(title, some longer description). I have trouble achieving consistent parsing of the description rule in the below grammar. Given @Annotation(title, some longer description), the description rule sometimes matches some longer description and sometimes it matches some longer description (note the leading space). I want to always enforce matching without leading whitespaces.

If you're having trouble with your code or grammar

I believe it's either a problem with the below grammar or a bug in the parsing process.

Code reproduction:

# File: parser.py

import lark

grammar = """
start: "@Annotation" "(" title "," description ")"
title: /[^,]+/
description: /[^)]+/

%import common.WS
%ignore WS
"""

text = "@Annotation(title, some longer description)"

parser = lark.Lark(grammar)
ir = parser.parse(text)
print(ir.children[1])

Explain what you're trying to do, and what is obstructing your progress.

It seems to me that ignoring the WS rule sometimes takes precedence over the description rule and sometimes vice versaand it happens randomly. Output of executing the same script a few times gives (again, note the leading space that sometimes gets matched for some longer description:

user@machine:/dir> python parser.py 
Tree(Token('RULE', 'description'), [Token('__ANON_2', ' some longer description')])
user@machine:/dir> python parser.py 
Tree(Token('RULE', 'description'), [Token('__ANON_2', 'some longer description')])
user@machine:/dir> python parser.py 
Tree(Token('RULE', 'description'), [Token('__ANON_2', ' some longer description')])
user@machine:/dir> python parser.py 
Tree(Token('RULE', 'description'), [Token('__ANON_2', 'some longer description')])
user@machine:/dir> python parser.py 
Tree(Token('RULE', 'description'), [Token('__ANON_2', ' some longer description')])
@jjalowie jjalowie changed the title Problem matching arbitrary text in parenthesis Problem matching the body of annotations like @Annotation(title, some longer description) Aug 19, 2023
@erezsh erezsh added the Earley Issues regarding the Earley parser label Aug 23, 2023
@erezsh
Copy link
Member

erezsh commented Oct 2, 2023

Should be solved in the latest master.

@erezsh erezsh closed this as completed Oct 2, 2023
@jjalowie
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Earley Issues regarding the Earley parser question
Projects
None yet
Development

No branches or pull requests

2 participants