---
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 Code\n { #[adze::leaf(pattern = r\"\\w+\")] token: String, } #[adze::external]\n struct IndentToken { #[adze::leaf(pattern = r\"\\t+\")] _indent: (), }\n }\n})? .to_token_stream().to_string())"
---
mod grammar {
pub struct Code {
token: String,
}
impl ::adze::Extract<Code> for Code {
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| Code {
token: {
::adze::__private::extract_field::<String, _>(
cursor, source, last_idx, "token", None,
)
},
})
}
}
struct IndentToken {
_indent: (),
}
impl ::adze::Extract<IndentToken> for IndentToken {
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| {
IndentToken {
_indent: {
::adze::__private::extract_field::<(), _>(
cursor, source, last_idx, "_indent", 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 = "[`Code`]"]
#[doc = r" instance containing the parsed structured data."]
pub fn parse(input: &str) -> core::result::Result<Code, Vec<::adze::errors::ParseError>> {
::adze::__private::parse::<Code>(input, language)
}
}