mpl_macro/lib.rs
1mod generator;
2mod mplg;
3
4use proc_macro::TokenStream;
5
6/// This macro creates
7/// let ident = parser_ident.replace("Parser", "");
8/// `{ident}Variable` enum,
9/// `{ident}Rules` const {variable_i_ident}_RULE for each rule,
10/// and impl Parser for `{parser_ident}`.
11///
12/// # Examples
13///
14/// ``` ignore
15/// use mpl_macro::Parse;
16///
17/// #[derive(Parse)]
18/// #[mplg = "{your path}/my.mplg"]
19/// pub struct MyParser;
20/// ```
21#[proc_macro_derive(Parse, attributes(mplg))]
22pub fn derive_parse(input: TokenStream) -> TokenStream {
23 generator::derive_parser(input.into()).into()
24}
25
26/// Static-codegen variant of [`Parse`]. Emits one `fn` per grammar rule
27/// and inherent `fast_recognize` / `fast_parse` methods on the parser
28/// struct. The grammar file is read the same way (`#[mplg = "..."]`).
29///
30/// Uses `mpl::fast::ParserState` and the flat-token output instead of the
31/// trait-based `Parser` API.
32#[proc_macro_derive(FastParse, attributes(mplg))]
33pub fn derive_fast_parse(input: TokenStream) -> TokenStream {
34 generator::derive_fast_parser(input.into()).into()
35}