You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
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 thedescription
rule in the below grammar. Given@Annotation(title, some longer description)
, thedescription
rule sometimes matchessome longer description
and sometimes it matchessome 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:
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 thedescription
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 forsome longer description
:The text was updated successfully, but these errors were encountered: