Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 796 Bytes

default_actions_for_grammar_rules.md

File metadata and controls

40 lines (28 loc) · 796 Bytes

Default Actions For Grammar Rules

Recall that each production of a grammar rule has a corresponding fn in the action file. The fn describes the action that will be taken when a substring of the input is parsed according to the production.

Let us look at an example.

S: A | B;

terminals

A: 'a';
B: 'b';

The fns of production A and B are:

pub fn s_a(_ctx: &Ctx) -> S {
    S::A
}

pub fn s_b(_ctx: &Ctx) -> S {
    S::B
}

These fns are generated by rcomp automatically and thus perform the default action, which returns the corresponding variant of the enum.

pub enum S {
    A,
    B,
}

➡️ Next: Changing Actions For Terminals

📘 Back: Table of contents