Proc macro generated code for parsing seems to work
This commit is contained in:
parent
4ecf63c54d
commit
3b20b40eb7
@ -1,4 +1,5 @@
|
|||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
|
#![recursion_limit="128"]
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
@ -14,13 +15,30 @@ struct RecursiveDescentFn {
|
|||||||
impl Fold for RecursiveDescentFn {
|
impl Fold for RecursiveDescentFn {
|
||||||
fn fold_item_fn(&mut self, mut i: syn::ItemFn) -> syn::ItemFn {
|
fn fold_item_fn(&mut self, mut i: syn::ItemFn) -> syn::ItemFn {
|
||||||
let box block = i.block;
|
let box block = i.block;
|
||||||
let mut stmts = block.stmts;
|
let ref ident = i.ident;
|
||||||
let new_item: syn::Stmt = parse_quote! {
|
|
||||||
println!("FROM PROC MACRO");
|
let new_block: syn::Block = parse_quote! {
|
||||||
|
{
|
||||||
|
let next_token = self.peek_with_token_offset();
|
||||||
|
let record = ParseRecord {
|
||||||
|
production_name: stringify!(#ident).to_string(),
|
||||||
|
next_token: format!("{}", next_token.to_string_with_metadata()),
|
||||||
|
level: self.parse_level,
|
||||||
|
};
|
||||||
|
self.parse_level += 1;
|
||||||
|
self.parse_record.push(record);
|
||||||
|
let result = { #block };
|
||||||
|
|
||||||
|
if self.parse_level != 0 {
|
||||||
|
self.parse_level -= 1;
|
||||||
|
}
|
||||||
|
match result {
|
||||||
|
Err(ParseError { token: None, msg }) =>
|
||||||
|
Err(ParseError { token: Some(next_token), msg }),
|
||||||
|
_ => result
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let mut new_stmts = vec![new_item];
|
|
||||||
new_stmts.append(&mut stmts);
|
|
||||||
let new_block = syn::Block { brace_token: block.brace_token, stmts: new_stmts };
|
|
||||||
i.block = Box::new(new_block);
|
i.block = Box::new(new_block);
|
||||||
i
|
i
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user