1
#![doc(html_root_url = "https://docs.rs/pest_consume_macros/1.1.0")]
2

            
3
//! This crate contains the code-generation primitives for the [pest_consume](https://docs.rs/pest_consume) crate.
4
//! See there for documentation.
5
//!
6
//! It provides two main macro functionalities:
7
//! - `parser`: Generates the implementation for a pest_consume parser
8
//! - `match_nodes`: Provides pattern matching capabilities for parsing nodes
9

            
10
extern crate proc_macro;
11

            
12
mod make_parser;
13
mod match_nodes;
14

            
15
use proc_macro::TokenStream;
16

            
17
/// Attribute macro for generating a pest_consume parser implementation.
18
#[proc_macro_attribute]
19
8
pub fn parser(attrs: TokenStream, input: TokenStream) -> TokenStream {
20
8
    TokenStream::from(match make_parser::make_parser(attrs, input) {
21
8
        Ok(tokens) => tokens,
22
        Err(err) => err.to_compile_error(),
23
    })
24
8
}
25

            
26
/// Procedural macro for pattern matching against parse nodes.
27
///
28
/// Provides a pattern matching syntax for working with parse trees,
29
/// supporting complex patterns with rule matching and binding.
30
#[proc_macro]
31
236
pub fn match_nodes(input: TokenStream) -> TokenStream {
32
236
    TokenStream::from(match match_nodes::match_nodes(input) {
33
236
        Ok(tokens) => tokens,
34
        Err(err) => err.to_compile_error(),
35
    })
36
236
}