Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 894 Bytes

changing_actions_for_terminals.md

File metadata and controls

40 lines (27 loc) · 894 Bytes

Changing Actions For Terminals

We can change the default action for terminals. For a regular expression terminal, we can change the fn that will be executed when the terminal is parsed. For example:

S: A;

terminals

A: /[a-z]+/;

Terminal A is converted to:

pub type A = String;

pub fn a(_ctx: &Ctx, token: Token) -> A {
    token.value.into()
}

We can add a println! to fn a:

pub fn a(_ctx: &Ctx, token: Token) -> A {
    println!("A is parsed");
    token.value.into()
}

In the output, A is parsed will come before Accept, which means fn a is executed before the whole input is parsed completely.

Since there is no actions for string terminals, we cannot change its behavior.

➡️ Next: Changing Actions For Grammar Rules

📘 Back: Table of contents