nom_peg/lib.rs
1extern crate proc_macro;
2extern crate proc_macro2;
3
4extern crate syn;
5use syn::parse_macro_input;
6
7extern crate quote;
8use quote::ToTokens;
9
10
11// PEG paper: http://bford.info/pub/lang/peg.pdf
12
13mod parser;
14mod codegen;
15
16// TODO: rewrite AST enum to facilitate `impl Parse` for each variant
17// TODO: support for using external non-terminals (i.e. other nom based parsers)
18// TODO: parser templates maybe? (like lalrpop)
19// TODO: extra functionality
20// - character classes `[a-zA-z]`
21// - any character, `.`
22// - repetition: exactly n times `{n}`, n or more times `{n,}`, at least n and at most m times `{n, m}`
23// - more regex features?
24// - handle named captures inside looping constucts
25
26// TODO: option to skip whitespace
27
28#[proc_macro]
29pub fn grammar(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
30 let parse_tree = parse_macro_input!(tokens as parser::ParseTree);
31 // eprintln!("!! input: {:?}", parse_tree);
32
33 parse_tree.into_token_stream().into()
34}