Replies: 2 comments 4 replies
-
Try to literally follow your description: include spaces to the Term
= _+ [A-Za-z0-9]+ (_+ / EOF)
_ "whitespace"
= [ \t\n\r]
EOF = !. |
Beta Was this translation helpful? Give feedback.
-
There are two approaches, depending on whether you want better performance of better error messages. Performant version:
Better error messages:
Then you should never try to use grammar as a linter: if you make whitespace as Notation:
|
Beta Was this translation helpful? Give feedback.
-
Hi! I'm trying to write a simple grammar to parse sets of numbers which allows to apply simple set operations such as conjunction
&&
, disjunction||
and complement (with respect to some superset)!
. When applying parentheses to construct more complex structures I want the primitive terms to be surrounded by whitespaces.Here's a simplified version of what I have (ignoring actions and parsing of sets from comma-sep'd lists of numbers):
This almost does the job, except that nested parentheses require whitespaces as well, as per Expr2, and this is precisely what I want to change: loosen up Expr2 to allow for contiguous nested parentheses without forced whitespces. E.g. what I want is
which, however, does not work, as there's no whitespace in between the first two parentheses. What works with the above grammar is
( ( abc || def ) && ghi ) || jkl
.I've been trying to solve this surprisingly elusive problem for hours but I just can't get hold of it. The greedy parsing always comes to bite me in the butt. May I kindly ask you to have a look at this?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions