Attribute Macro rust_sitter::prec_left

source ·
#[prec_left]
Expand description

Defines a precedence level for a non-terminal that should be left-associative. For example, with subtraction we expect 1 - 2 - 3 to be parsed as (1 - 2) - 3, which corresponds to a left-associativity.

This annotation takes a single, unnamed parameter, which specifies the precedence level. This is used to resolve conflicts with other non-terminals, so that the one with the higher precedence will bind more tightly (appear lower in the parse tree).

§Example

#[rust_sitter::prec_left(1)]
Subtract(Box<Expr>, Box<Expr>)