Skip to main content

Crate adze_macro

Crate adze_macro 

Source
Expand description

Procedural macros for adze grammar definition

Attribute Macrosยง

delimited
On Vec<_> typed fields, specifies a non-terminal that should be parsed in between the elements. The #[adze::repeat] annotation must be used on the field as well.
external
Marks a rule as an external scanner token. External scanners are implemented in separate code and handle context-sensitive tokens like indentation or heredocs.
extra
This annotation marks a node as extra, which can safely be skipped while parsing. This is useful for handling whitespace/newlines/comments.
grammar
Mark a module to be analyzed for an Adze grammar. Takes a single, unnamed argument, which specifies the name of the grammar. This name must be unique across all Adze grammars within a compilation unit.
language
Marks the top-level AST node where parsing should start.
leaf
Defines a field which matches a specific token in the source string. The token can be defined by passing one of two arguments
prec
Defines a precedence level for a non-terminal that has no associativity.
prec_left
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.
prec_right
Defines a precedence level for a non-terminal that should be right-associative. For example, with cons we could have 1 :: 2 :: 3 to be parsed as 1 :: (2 :: 3), which corresponds to a right-associativity.
repeat
On Vec<_> typed fields, specifies additional config for how the repeated elements should be parsed. In particular, this annotation takes the following named arguments:
skip
Defines a field that does not correspond to anything in the input string, such as some metadata. Takes a single, unnamed argument, which is the value used to populate the field at runtime.
word
Marks a token as the word token for the grammar. Word tokens are used to handle keywords vs identifiers disambiguation.