-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Silent atomic rule #520
Comments
+1 |
+1 |
Could kindly someone explain what the atomic rule mean? I tried to understand it from here https://pest.rs/book/grammars/syntax.html#atomic but failed :) Silent one was easy to grasp but the atomic seems totally new thing to me in parsing. |
Go on the pest.rs editor and put this into the grammar field:
You will find that "ab" matches both
In other words, an nonatomic rule ignores everything that matches WHITESPACE or COMMENT, an atomic rule does not. Hope that helps. |
I also wish silent atomic to be implemented. In my opinion, silentness and atomicity should be 2 separate properties of the rules. My suggestion is to implement the following behaviors:
And the corresponding change in
to
|
I've looked into the codes that generate parsers and rules from pest files, and successfully separated the silent modifier from the other modifiers ( However, I have difficulty understanding the current codes implementing the functionalities of the modifiers. I've posted a question in discussion #864. I would really appreciate it if someone could answer it. |
@WHMHammer BTW you can include this commit in your fork 867da2e then it should be possible to use pet as a git dependency (if other people want to use the fork at the moment and don't want to clone it locally):
but note that the compilation time will be higher due to the |
@tomtau pulled. Thank you! |
@WHMHammer FYI for the upstream, you can add this as feature-guarded under "grammar-extras", so that the semver backwards compatibility with 2.X is preserved (see #871 and https://github.com/pest-parser/pest/pull/878/files ) |
This is something I am struggling with greatly in my own project. I am also not sure if the reason I am getting unexpected results is because non-silent rules inside of silent rules do produce pairs. Definitely a +1 from me on this issue. |
@lthoerner non-silent rules inside silent rules producing pairs is an expected behavior. You need to explicitly make them silent as well if you do not want them to produce pairs. |
How do I apply both modifiers to one rule? If I try to make a silent rule, it includes whitespace, which I need it to exclude, and if I make it atomic, it isn't silent. |
@WHMHammer Sorry for the ping, I forgot to add it in the original reply. |
Currently, I have found a workaround, but it is not very pleasant. Do not use the special WHITESPACE rule, instead declare your own |
It might feel cumbersome but I think you've found the best solution, @pamburus. Relying on |
Atomic means the repetition can't be backtracked, so I guess non-atomic expressions have performance penalties. Is that correct? |
Hello,
The book says that
@{...}
creates an atomic rule and_{...}
creates a silent rule.But (afaik) there is currently no way to create a rule that is both silent and atomic (neither
@_{...}
nor_@{...}
compiles ).The text was updated successfully, but these errors were encountered: