adze-macro 0.8.0

Procedural macros for Rust Sitter
Documentation
---
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 Language\n        {\n            #[adze::leaf(pattern = r\"\\d+\", transform = |v|\n            v.parse().unwrap())] v: Option<i32>, t: Option<Number>,\n        } pub struct Number\n        {\n            #[adze::leaf(pattern = r\"\\d+\", transform = |v|\n            v.parse().unwrap())] v: i32\n        }\n    }\n})? .to_token_stream().to_string())"
---
mod grammar {
    pub struct Language {
        v: Option<i32>,
        t: Option<Number>,
    }
    impl ::adze::Extract<Language> for Language {
        type LeafFn = ();
        const GRAMMAR_NAME: &'static str = "test";
        #[allow(non_snake_case)]
        fn extract(
            node: Option<&::adze::pure_parser::ParsedNode>,
            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| Language {
                v: {
                    ::adze::__private::extract_field::<Option<adze::WithLeaf<i32>>, _>(
                        cursor,
                        source,
                        last_idx,
                        "v",
                        Some(&|v| v.parse().unwrap()),
                    )
                },
                t: {
                    ::adze::__private::extract_field::<Option<Number>, _>(
                        cursor, source, last_idx, "t", None,
                    )
                },
            })
        }
    }
    pub struct Number {
        v: i32,
    }
    impl ::adze::Extract<Number> for Number {
        type LeafFn = ();
        const GRAMMAR_NAME: &'static str = "test";
        #[allow(non_snake_case)]
        fn extract(
            node: Option<&::adze::pure_parser::ParsedNode>,
            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| Number {
                v: {
                    ::adze::__private::extract_field::<adze::WithLeaf<i32>, _>(
                        cursor,
                        source,
                        last_idx,
                        "v",
                        Some(&|v| v.parse().unwrap()),
                    )
                },
            })
        }
    }
    include!(concat!(
        env!("OUT_DIR"),
        "/grammar_",
        "test",
        "/parser_",
        "test",
        ".rs"
    ));
    pub fn language() -> &'static ::adze::pure_parser::TSLanguage {
        &LANGUAGE
    }
    pub const LANGUAGE_REF: &'static ::adze::pure_parser::TSLanguage = &LANGUAGE;
    #[doc = r" Parse an input string according to the grammar. Returns either any parsing errors that happened, or a"]
    #[doc = "[`Language`]"]
    #[doc = r" instance containing the parsed structured data."]
    pub fn parse(input: &str) -> core::result::Result<Language, Vec<::adze::errors::ParseError>> {
        ::adze::__private::parse::<Language>(input, || language())
    }
}