Replies: 4 comments 3 replies
-
This is a very cool idea. Python's new PEG parser has the same feature, detailed here. |
Beta Was this translation helpful? Give feedback.
-
Similarly, we can also add the branch tag expr = {
"(" ~ expr ~ ")" // branch: None
| term ~ ("/"|"*") ~ term #Mul // branch: Some("Mul")
| term ~ ("+"|"-") ~ term #Add // branch: Some("Add")
} which call after |
Beta Was this translation helpful? Give feedback.
-
This seems reasonable to me! It's a nice middle-ground between pest's fully "untyped" parse tree and something more strongly typed like the pest-ast draft or the mythical pest@3. |
Beta Was this translation helpful? Give feedback.
-
I was looking into reviving #552 and also looked into extending the meta grammar. @oovm @CAD97 @NoahTheDuke have you looked into or thought about the meta grammar implementation? Given how the code is written, there are a few ways:
I tried the first one but it's likely a no-go... I'm thinking the last may be the path of least resistance, as the explicit variant may fix up the potential issues with the optimizer... anyway, any thoughts? or should this be left for a simpler v3 grammar/implementation? |
Beta Was this translation helpful? Give feedback.
-
Motivation
Name-binding refers to the name of a node in the specified syntax tree, for example
=
in ANTLR,field
in tree-sitter.Very useful when the name is repeated, such as distinguishing the left and right nodes of an expression.
Design
pest/pest/src/iterators/pairs.rs
Lines 34 to 39 in f0a85d1
Then you can use a very convenient interface to find the node you want.
The current process is more cumbersome.
Specific changes
pest/pest/src/parser_state.rs
Lines 77 to 86 in f0a85d1
Here to extract the value from the state:
And add a primitive operation here:
Ideally it should be able to correspond to such code:
Compatibility
Does not break existing features.
Beta Was this translation helpful? Give feedback.
All reactions