Okay the proc_macro is actually doing something
At the cost of breaking code
This commit is contained in:
parent
3d00667caf
commit
4ecf63c54d
@ -8,5 +8,5 @@ edition = "2018"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syn = { version = "0.15.6", features = ["full", "extra-traits"] }
|
syn = { version = "0.15.12", features = ["full", "extra-traits", "fold"] }
|
||||||
quote = "0.6.8"
|
quote = "0.6.8"
|
||||||
|
@ -1,11 +1,36 @@
|
|||||||
|
#![feature(box_patterns)]
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
|
#[macro_use]
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|
||||||
use self::proc_macro::TokenStream;
|
use self::proc_macro::TokenStream;
|
||||||
|
use self::syn::fold::Fold;
|
||||||
|
|
||||||
|
struct RecursiveDescentFn {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Fold for RecursiveDescentFn {
|
||||||
|
fn fold_item_fn(&mut self, mut i: syn::ItemFn) -> syn::ItemFn {
|
||||||
|
let box block = i.block;
|
||||||
|
let mut stmts = block.stmts;
|
||||||
|
let new_item: syn::Stmt = parse_quote! {
|
||||||
|
println!("FROM PROC MACRO");
|
||||||
|
};
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn parser_function(attr: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn recursive_descent_method(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
item
|
|
||||||
|
let input: syn::ItemFn = parse_macro_input!(item as syn::ItemFn);
|
||||||
|
let mut folder = RecursiveDescentFn {};
|
||||||
|
let output = folder.fold_item_fn(input);
|
||||||
|
TokenStream::from(quote!(#output))
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,6 @@ take_mut = "0.1.3"
|
|||||||
maplit = "*"
|
maplit = "*"
|
||||||
lazy_static = "0.2.8"
|
lazy_static = "0.2.8"
|
||||||
|
|
||||||
|
codegen = { path = "../codegen" }
|
||||||
schala-repl = { path = "../../schala-repl" }
|
schala-repl = { path = "../../schala-repl" }
|
||||||
schala-repl-codegen = { path = "../../schala-repl-codegen" }
|
schala-repl-codegen = { path = "../../schala-repl-codegen" }
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![feature(trace_macros)]
|
#![feature(trace_macros)]
|
||||||
|
#![feature(custom_attribute)]
|
||||||
#![feature(unrestricted_attribute_tokens)]
|
#![feature(unrestricted_attribute_tokens)]
|
||||||
#![feature(slice_patterns, box_patterns, box_syntax)]
|
#![feature(slice_patterns, box_patterns, box_syntax)]
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
@ -10,6 +11,8 @@ extern crate maplit;
|
|||||||
extern crate schala_repl;
|
extern crate schala_repl;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate schala_repl_codegen;
|
extern crate schala_repl_codegen;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate codegen;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -789,7 +789,8 @@ impl Parser {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
parse_method!(signed_number_literal(&mut self) -> ParseResult<Pattern> {
|
#[recursive_descent_method]
|
||||||
|
fn signed_number_literal(&mut self) -> ParseResult<Pattern> {
|
||||||
let neg = match self.peek() {
|
let neg = match self.peek() {
|
||||||
Operator(ref op) if **op == "-" => {
|
Operator(ref op) if **op == "-" => {
|
||||||
self.next();
|
self.next();
|
||||||
@ -799,7 +800,7 @@ impl Parser {
|
|||||||
};
|
};
|
||||||
let Expression(expr_type, _) = self.number_literal()?;
|
let Expression(expr_type, _) = self.number_literal()?;
|
||||||
Ok(Pattern::Literal(PatternLiteral::NumPattern { neg, num: expr_type }))
|
Ok(Pattern::Literal(PatternLiteral::NumPattern { neg, num: expr_type }))
|
||||||
});
|
}
|
||||||
|
|
||||||
parse_method!(record_pattern_entry(&mut self) -> ParseResult<(Rc<String>, Pattern)> {
|
parse_method!(record_pattern_entry(&mut self) -> ParseResult<(Rc<String>, Pattern)> {
|
||||||
let name = self.identifier()?;
|
let name = self.identifier()?;
|
||||||
@ -913,12 +914,13 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
parse_method!(number_literal(&mut self) -> ParseResult<Expression> {
|
#[recursive_descent_method]
|
||||||
|
fn number_literal(&mut self) -> ParseResult<Expression> {
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
HexLiteral(_) | BinNumberSigil => self.int_literal(),
|
HexLiteral(_) | BinNumberSigil => self.int_literal(),
|
||||||
_ => self.float_literal(),
|
_ => self.float_literal(),
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
parse_method!(int_literal(&mut self) -> ParseResult<Expression> {
|
parse_method!(int_literal(&mut self) -> ParseResult<Expression> {
|
||||||
use self::ExpressionType::*;
|
use self::ExpressionType::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user