Recall that a grammar rule may have a few productions.
To change an action when a substring is parsed as a production, we change the corresponding fn of the production.
For example:
S: S Plus S {left}
| A
;
terminals
Plus: '+';
A: /\d+/;
S has a production A and the corresponding action fn of the production is
pub fn s_a(_ctx: &Ctx, a: A) -> S {
S::A(a)
}We can add a println! to the fn such as
pub fn s_a(_ctx: &Ctx, a: A) -> S {
println!("{a}");
S::A(a)
}By running the parser on input 1 + 2 + 3, we can see 1, 2 and 3 accordingly in the output.
➡️ Next: Changing Types For Terminals
📘 Back: Table of contents