Is there a way to ignore certain text from the output while still including it in the parsing? #635
Replies: 2 comments
-
Adding on top of this - is there a better way of writing this?
Because I would much prefer to write it more like this:
|
Beta Was this translation helpful? Give feedback.
-
I'm not an expert, but I think the reason your second piece feels hard to write is two-fold:
The first means that you have to negate your thinking to exclude everything not allowed, where I think it's easier to build what you will allow from the ground up. The second point of splitting the rules up a bit more will firstly make it easier to read/understand, and also solve your problem of not wanting to include things in the parse tree. You would be able to flag the necessary rules as silent under this method. For example, I would probably try to build up "the set of allowed tokens for a string" which would include escape characters but not quotes (where you have defined rules for escape characters and quotes). You could also do the same for brackets in your function example. Hopefully this helps! |
Beta Was this translation helpful? Give feedback.
-
For example let's say you have this:
The
(
needs to be there for it to be parsed as a function but you don't really want it in the output.It would be most ideal if
myfunc(
output justmyfunc
when parsed. Of course, it's not hard to just remove it in the Rust code, but that lacks convenience.Here's my suggestion:
It is much like the silent key except it can be used on expressions in addition to rules.
"("
is used during the parsing phase but ignored in the output.Beta Was this translation helpful? Give feedback.
All reactions