Commit 81cf1169 authored by Geoffry Song's avatar Geoffry Song

Update to newer syn, proc_macro2, quote

parent 8af228b0
...@@ -20,6 +20,6 @@ crate-type = ["proc-macro"] ...@@ -20,6 +20,6 @@ crate-type = ["proc-macro"]
lalr = "0.0.2" lalr = "0.0.2"
redfa = "0.0.2" redfa = "0.0.2"
syn = { version = "0.12", features = ["extra-traits", "full"] } syn = { version = "0.13.1", features = ["extra-traits", "full"] }
proc-macro2 = { version = "0.2.1", features = ["nightly"] } proc-macro2 = { version = "0.3.6", features = ["nightly"] }
quote = "0.4" quote = "0.5.1"
...@@ -163,7 +163,7 @@ pub fn lexer(input: TokenStream) -> TokenStream { ...@@ -163,7 +163,7 @@ pub fn lexer(input: TokenStream) -> TokenStream {
Ok(r) => r, Ok(r) => r,
Err(e) => { Err(e) => {
pattern pattern
.span .span()
.unstable() .unstable()
.error(format!("invalid regular expression: {}", e)) .error(format!("invalid regular expression: {}", e))
.emit(); .emit();
...@@ -172,7 +172,7 @@ pub fn lexer(input: TokenStream) -> TokenStream { ...@@ -172,7 +172,7 @@ pub fn lexer(input: TokenStream) -> TokenStream {
}; };
if re.nullable() { if re.nullable() {
pattern pattern
.span .span()
.unstable() .unstable()
.error("token must not match the empty string") .error("token must not match the empty string")
.emit(); .emit();
......
...@@ -154,16 +154,15 @@ where ...@@ -154,16 +154,15 @@ where
let lhs_ty = &types[lhs]; let lhs_ty = &types[lhs];
for rhs in rhss.iter() { for rhs in rhss.iter() {
let (result, arg_pats, rhs_span) = to_expr(lhs, &rhs.act, &rhs.syms); let (result, arg_pats, rhs_span) = to_expr(lhs, &rhs.act, &rhs.syms);
let span = rhs_span.resolved_at(Span::def_site());
let len = rhs.syms.len(); let len = rhs.syms.len();
let current_span_stmt = if rhs.syms.len() > 0 { let current_span_stmt = if rhs.syms.len() > 0 {
let current_span_ident = quote_spanned!(span => current_span); let current_span_ident = quote_spanned!(rhs_span => current_span);
// Make the current_span available to the user by exposing it through a macro whose name is unhygienic. // Make the current_span available to the user by exposing it through a macro whose name is unhygienic.
let span_macro = quote_spanned!(rhs_span.resolved_at(Span::call_site()) => let span_macro = quote_spanned!(Span::call_site() =>
#[allow(unused_macros)] macro_rules! span { #[allow(unused_macros)] macro_rules! span {
() => { #current_span_ident.unwrap() } () => { #current_span_ident.unwrap() }
}); });
quote_spanned!(span => quote_spanned!(rhs_span =>
let current_span: Option<#span_ty> = { let current_span: Option<#span_ty> = {
let sp = range_array(&span_stack[(span_stack.len() - #len)..]); let sp = range_array(&span_stack[(span_stack.len() - #len)..]);
let newlen = span_stack.len() - #len; let newlen = span_stack.len() - #len;
...@@ -173,7 +172,7 @@ where ...@@ -173,7 +172,7 @@ where
#span_macro #span_macro
) )
} else { } else {
quote_spanned!(span => quote_spanned!(rhs_span =>
let current_span: Option<#span_ty> = None; let current_span: Option<#span_ty> = None;
) )
}; };
...@@ -186,24 +185,24 @@ where ...@@ -186,24 +185,24 @@ where
Terminal(_) => token_ty.clone(), Terminal(_) => token_ty.clone(),
Nonterminal(ref n) => types[n].clone(), Nonterminal(ref n) => types[n].clone(),
}; };
quote_spanned!(span => quote_spanned!(rhs_span =>
let #pat: #ty = *stack.pop().unwrap().downcast().unwrap(); let #pat: #ty = *stack.pop().unwrap().downcast().unwrap();
) )
} }
None => quote_spanned!(span => stack.pop();), None => quote_spanned!(rhs_span => stack.pop();),
}, },
)); ));
if rhs.syms.len() > 1 { if rhs.syms.len() > 1 {
let len_minus_one = rhs.syms.len() - 1; let len_minus_one = rhs.syms.len() - 1;
// XXX: Annoying syntax :( // XXX: Annoying syntax :(
reduce_stmts.push( reduce_stmts.push(
quote_spanned!(span => match state_stack.len() - #len_minus_one { x => state_stack.truncate(x) };), quote_spanned!(rhs_span => match state_stack.len() - #len_minus_one { x => state_stack.truncate(x) };),
); );
} else if rhs.syms.len() == 0 { } else if rhs.syms.len() == 0 {
reduce_stmts.push(quote_spanned!(span => state_stack.push(*state);)); reduce_stmts.push(quote_spanned!(rhs_span => state_stack.push(*state);));
} }
reduce_stmts.push(quote_spanned!( reduce_stmts.push(quote_spanned!(
span => rhs_span =>
*state = #goto_fn(*state_stack.last().unwrap()); *state = #goto_fn(*state_stack.last().unwrap());
let result: #lhs_ty = ( || -> #lhs_ty { #result } )(); let result: #lhs_ty = ( || -> #lhs_ty { #result } )();
stack.push(Box::new(result) as Box<#any_ty>); stack.push(Box::new(result) as Box<#any_ty>);
...@@ -212,7 +211,7 @@ where ...@@ -212,7 +211,7 @@ where
let fn_id = rule_fn_ids.get(&(rhs as *const _)).unwrap().clone(); let fn_id = rule_fn_ids.get(&(rhs as *const _)).unwrap().clone();
stmts.push(quote_spanned!( stmts.push(quote_spanned!(
span => rhs_span =>
fn #fn_id( fn #fn_id(
stack: &mut Vec<Box<#any_ty>>, stack: &mut Vec<Box<#any_ty>>,
span_stack: &mut Vec<Option<#span_ty>>, span_stack: &mut Vec<Option<#span_ty>>,
...@@ -372,7 +371,7 @@ fn parse_rules(mut input: Cursor) -> PResult<Vec<Rule>> { ...@@ -372,7 +371,7 @@ fn parse_rules(mut input: Cursor) -> PResult<Vec<Rule>> {
_ => { _ => {
// FIXME non-ideal span // FIXME non-ideal span
meta.name() meta.name()
.span .span()
.unstable() .unstable()
.error("unknown attribute") .error("unknown attribute")
.emit(); .emit();
...@@ -406,7 +405,7 @@ fn parse_rules(mut input: Cursor) -> PResult<Vec<Rule>> { ...@@ -406,7 +405,7 @@ fn parse_rules(mut input: Cursor) -> PResult<Vec<Rule>> {
} }
RuleRhsItem::Destructure(ident, span, pats) RuleRhsItem::Destructure(ident, span, pats)
} else { } else {
sp_hi = ident.span; sp_hi = ident.span();
RuleRhsItem::Symbol(ident) RuleRhsItem::Symbol(ident)
}, },
); );
...@@ -543,10 +542,10 @@ pub fn parser(input: TokenStream) -> TokenStream { ...@@ -543,10 +542,10 @@ pub fn parser(input: TokenStream) -> TokenStream {
} }
match rules.entry(lhs) { match rules.entry(lhs) {
Entry::Occupied(ent) => { Entry::Occupied(ent) => {
lhs.span lhs.span()
.unstable() .unstable()
.error("duplicate nonterminal") .error("duplicate nonterminal")
.span_note(ent.key().span.unstable(), "first definition here") .span_note(ent.key().span().unstable(), "first definition here")
.emit(); .emit();
} }
Entry::Vacant(ent) => { Entry::Vacant(ent) => {
...@@ -594,7 +593,7 @@ pub fn parser(input: TokenStream) -> TokenStream { ...@@ -594,7 +593,7 @@ pub fn parser(input: TokenStream) -> TokenStream {
let fake_start = Ident::from("__FIXME__start"); let fake_start = Ident::from("__FIXME__start");
fake_rule = Rule { fake_rule = Rule {
rhs: vec![], rhs: vec![],
rhs_span: Span::def_site().unstable(), rhs_span: proc_macro::Span::def_site(),
action: quote!(), action: quote!(),
exclusions: BTreeSet::new(), exclusions: BTreeSet::new(),
exclude_eof: false, exclude_eof: false,
...@@ -681,8 +680,7 @@ pub fn parser(input: TokenStream) -> TokenStream { ...@@ -681,8 +680,7 @@ pub fn parser(input: TokenStream) -> TokenStream {
r2, r2,
} => { } => {
// FIXME: wtf this span // FIXME: wtf this span
Span::call_site() proc_macro::Span::call_site()
.unstable()
.error(format!( .error(format!(
"reduce-reduce conflict: "reduce-reduce conflict:
state: {} state: {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment