-
Here's a simple demo of what I'm trying to do. from lark import Lark
parser = Lark(
r"""
start: closure
closure: "(" ")"
// Works:
COMMENT: "#" /[^\n]/*
// Doesn't work:
// COMMENT: /#.*$/
%import common.WS
%ignore WS
%ignore COMMENT
""",
start="start",
)
print(parser.parse(
"""
()
# (
"""
)) I'm new to parsing. I started off with what I thought was the obvious way to write a Terminal for comments: This definition is incidentally also used here in the docs. It doesn't work, and the above test yields this error:
If I switch the Terminal definition to What's the difference between these two definitions? And why doesn't the "obvious" regex work? There is a similar discussion over on #1281. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
$
matches the end of the string by default. If you want it to match the end of the line, add them
flag./#.*$/m
. This is clearly documented in the python regex docs.