1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! # teleparse-macros
//!
//! These are for use with the [`teleparse`](https://docs.rs/teleparse) crate and not meant to be used standalone.

mod prelude;
use prelude::*;


/// Transform an enum into a token type (a lexicon)
///
/// This will derive the lexicon trait as well as the super traits, and also generate
/// an implementation for the lexer, and implementation for terminal symbols for the AST
///
/// Note that this is not a derive macro, since it will transform the input.
#[proc_macro_attribute]
pub fn derive_lexicon(_: TokenStream, input: TokenStream) -> TokenStream {
    expand_with_mut(input, lexicon::expand)
}
mod lexicon;

/// Transform an enum or struct into a parse tree node, as well as deriving the production rule
/// (the AST nodes)
///
/// This will derive the AbstractSyntaxTree trait as well as the super traits, and also generate
/// an implementation for the lexer, and implementation for terminal symbols for the AST
///
/// Note that this is not a derive macro, since it will transform the input.
#[proc_macro_attribute]
pub fn derive_syntax(_: TokenStream, input: TokenStream) -> TokenStream {
    expand_with_mut(input, syntax::expand)
}
mod syntax;

/// Derive common traits for AST helper nodes (stores a Node as its first thing)
#[proc_macro_derive(Node)]
pub fn derive_node(input: TokenStream) -> TokenStream {
    expand_with(input, node::expand)
}
mod node;

/// Derive ToSpan from a type that stores a ToSpan as its first thing
#[proc_macro_derive(ToSpan)]
pub fn derive_to_span(input: TokenStream) -> TokenStream {
    expand_with(input, to_span::expand)
}
mod to_span;

/// Derive AbstractSyntaxTree from a struct with unnamed fields or an enum.
/// This is not a derive macro because it's internal
#[proc_macro_attribute]
pub fn derive_ast(attr: TokenStream, input: TokenStream) -> TokenStream {
    let name = parse_macro_input!(attr as syn::Ident);
    expand_with_args(input, name, ast::expand)
}
mod ast;

/// Derive AST for a tuple
#[proc_macro]
pub fn derive_tuple_ast(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as syn::ExprTuple);
    match tuple::expand(&input) {
        Ok(ts) => ts.into(),
        Err(e) => e.to_compile_error().into(),
    }
}
mod tuple;

// internal helpers

mod sequence;
mod root;