Skip to main content

language

Attribute Macro language 

Source
#[language]
Expand description

Marks the top-level AST node where parsing should start.

Exactly one type inside an grammar module must carry this attribute. It can be applied to either a struct or an enum.

§Examples

As a struct (single production):

#[adze::language]
pub struct Program {
    statements: Vec<Statement>,
}

As an enum (multiple alternatives):

#[adze::language]
pub enum Expr {
    Number(
        #[adze::leaf(pattern = r"\d+", transform = |v| v.parse().unwrap())]
        i32
    ),
    #[adze::prec_left(1)]
    Add(Box<Expr>, #[adze::leaf(text = "+")] (), Box<Expr>),
}