pub enum GrNode {
Symbol(Symbol),
Concat,
Or,
Maybe,
Plus,
Star,
LForm(VarId),
RAssoc,
PrecEq,
Instance,
}Variants§
Symbol(Symbol)
Concat
Or
Maybe
Plus
Star
LForm(VarId)
L-form attribute of an alternative or a + / * repetition expression.
+and*expressions are either folded or iterative (also called “low latency”, since the listener is called back immediately after parsing each item, whereas the folded form is only called once all the items have been parsed and gathered).- The default form is folded. With that form, the items of the repetitions are automatically gathered and handed
to the listener callback as an array (if the items have a value) once all items have been parsed. For example,
A -> a (b)* cgives a context with the values of a, b, c as variantenum CtxA { A { a: String, b: Vec<String>, c: String } }. - If the L-form is specified, the listener callback is called at each iteration, with a context giving the parsed
items of that iteration which have a value. The NT used in that loop is defined with the L-form (
LForm(VarId)), and its value serves as accumulator to fold all the successive items into a single value presented in the context of the alternative that includes the+or*repetition. For example,A -> a (<L=AIter> b)* cusesAIter, and each time abvalue is parsed, the listener callback receives a context variantenum CtxAIter { AIter1 { iter: SynAIter, b: String } }. The callback must return the newSynAItervalue. Once all the iterations are parsed,cis parsed, and the listener callback receives the context forA:CtxA { A { a: String, star: SynAIter, c: String } }.
- The default form is folded. With that form, the items of the repetitions are automatically gathered and handed
to the listener callback as an array (if the items have a value) once all items have been parsed. For example,
- Right-recursive rules are either stacked or “low-latency”.
-
The default form is stacked. A rule
A -> id A | stopparsing “id1 id2 id3 stop1” yields a sequenceA -> id1 A(1),A(1) -> id2 A(2),A(2) -> id3 A(3),A(3) -> stop1
Since it’s recursive, the listener callback is first called for A(3), then A(2), A(1), and finally A. The parser puts the intermediate values of
idon the stack, and oncestop1is reached, it calls the callback with it, then unstacks all theidvalues for the successive callbacks withid = id3,id2, and finallyid1, together with the loop valueA, which is updated each time by the callback. -
The low-latency form, whose
VarIdpoints to its own NT, calls the listener callback at each iteration and doesn’t accumulate values on the stack. In the example above, it’s first called withid = id1,id2,id3, and finallystop = stop1, together with the loop valueA, which is updated each time by the callback.
-
RAssoc
PrecEq
Instance
Implementations§
Trait Implementations§
impl Copy for GrNode
impl StructuralPartialEq for GrNode
Auto Trait Implementations§
impl Freeze for GrNode
impl RefUnwindSafe for GrNode
impl Send for GrNode
impl Sync for GrNode
impl Unpin for GrNode
impl UnwindSafe for GrNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> BuildFrom<S> for S
impl<S> BuildFrom<S> for S
Source§fn build_from(source: S) -> S
fn build_from(source: S) -> S
Source§impl<S, T> BuildInto<T> for Swhere
T: BuildFrom<S>,
impl<S, T> BuildInto<T> for Swhere
T: BuildFrom<S>,
Source§fn build_into(self) -> T
fn build_into(self) -> T
Calls T::from(self) to convert a [S] into a [T].