Skip to main content

quote_

Macro quote_ 

Source
macro_rules! quote_ {
    ( $root:ident { $($tree:tt)* } ) => { ... };
}
Expand description

A quote!-like API for crafting AST nodes.

Syntax: AST nodes are created with Node { children }, where Node is the node name in ast (ast::Node). Tokens are creates with their syntax enclosed by brackets, e.g. [::] or ['{']. Alternatively, tokens can be created with the syntax [token_kind token_text], where token_kind is a variant of SyntaxKind (e.g. IDENT) and token_text is an expression producing String or &str. Whitespaces can be added as string literals (i.e. "\n " is a whitespace token). Interpolation is allowed with # (#variable), from AstNodes and Options of them. Repetition is also supported, with only one repeating variable and no separator (#("\n" #variable [>])*), for any IntoIterator. Note that Options are also IntoIterator, which can help when you want to conditionally include something along with an optional node.

There needs to be one root node, and its type is returned.

Be careful to closely match the Ungrammar AST, there is no validation for this!