---
source: macro/src/lib.rs
expression: "rustfmt_code(&expand_grammar(parse_quote!\n{\n #[adze::grammar(\"test\")] mod grammar\n {\n #[adze::language] pub struct Identifier\n { #[adze::leaf(pattern = r\"[a-zA-Z_]\\w*\")] name: String, }\n }\n})? .to_token_stream().to_string())"
---
mod grammar {
pub struct Identifier {
name: String,
}
impl ::adze::Extract<Identifier> for Identifier {
type LeafFn = ();
#[allow(non_snake_case)]
fn extract(
node: Option<::adze::tree_sitter::Node>,
source: &[u8],
last_idx: usize,
_leaf_fn: Option<&Self::LeafFn>,
) -> Self {
let node = node.expect("Extract called with None node for struct");
::adze::__private::extract_struct_or_variant(node, move |cursor, last_idx| Identifier {
name: {
::adze::__private::extract_field::<String, _>(
cursor, source, last_idx, "name", None,
)
},
})
}
}
unsafe extern "C" {
fn tree_sitter_test() -> ::adze::tree_sitter::Language;
}
pub fn language() -> ::adze::tree_sitter::Language {
unsafe { tree_sitter_test() }
}
#[doc = r" Parse an input string according to the grammar. Returns either any parsing errors that happened, or a"]
#[doc = "[`Identifier`]"]
#[doc = r" instance containing the parsed structured data."]
pub fn parse(input: &str) -> core::result::Result<Identifier, Vec<::adze::errors::ParseError>> {
::adze::__private::parse::<Identifier>(input, language)
}
}