From f758e0ff00e3c0bd17ee04e2a3c0b399d6693548 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 18 Jul 2015 05:56:42 -0400 Subject: [PATCH] thread through most of the work to support lookahead/lookbehind, but not the actual expansion (untested, clearly) --- lalrpop-test/src/expr.rs | 2074 ++++---- lalrpop-test/src/expr_arena.rs | 5186 +++++++++++---------- lalrpop-test/src/sub.rs | 508 +- lalrpop/src/grammar/parse_tree.rs | 29 +- lalrpop/src/grammar/repr.rs | 6 +- lalrpop/src/lr1/ascent.rs | 84 +- lalrpop/src/normalize/lower/mod.rs | 37 +- lalrpop/src/normalize/macro_expand/mod.rs | 38 +- lalrpop/src/normalize/norm_util.rs | 4 +- lalrpop/src/normalize/tyinfer/mod.rs | 3 +- lalrpop/src/normalize/validate/mod.rs | 31 + lalrpop/src/normalize/validate/test.rs | 16 +- lalrpop/src/parser/mod.rs | 27 +- lalrpop/src/parser/test.rs | 6 + 14 files changed, 4245 insertions(+), 3804 deletions(-) diff --git a/lalrpop-test/src/expr.rs b/lalrpop-test/src/expr.rs index 1311c79..b0984a7 100644 --- a/lalrpop-test/src/expr.rs +++ b/lalrpop-test/src/expr.rs @@ -11,8 +11,8 @@ pub fn parse_Expr< { let mut __tokens = __tokens.into_iter(); let __lookahead = __tokens.next(); - match try!(__parse__Expr::__state0(scale, __lookahead, &mut __tokens)) { - (__lookahead, __parse__Expr::__Nonterminal::____Expr(__nt)) => Ok((__lookahead, __nt)), + match try!(__parse__Expr::__state0(scale, None, __lookahead, &mut __tokens)) { + (_, __lookahead, __parse__Expr::__Nonterminal::____Expr(__nt)) => Ok((__lookahead, __nt)), _ => unreachable!(), } } @@ -23,10 +23,10 @@ mod __parse__Expr { use util::tok::Tok; pub enum __Nonterminal<> { - ____Expr(i32), - Term(i32), - Expr(i32), Factor(i32), + ____Expr(i32), + Expr(i32), + Term(i32), } // State 0 @@ -66,59 +66,111 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // __Expr = (*) Expr [EOF] // - // "Num" -> Shift(S2) - // "(" -> Shift(S1) + // "Num" -> Shift(S3) + // "(" -> Shift(S2) // - // Factor -> S5 + // Expr -> S1 // Term -> S4 - // Expr -> S3 + // Factor -> S5 pub fn __state0< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym0 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state2(scale, __lookahead, __tokens, __sym0)); + __result = try!(__state3(scale, __lookbehind, __lookahead, __tokens, __sym0)); } Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym0 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state1(scale, __lookahead, __tokens, __sym0)); + __result = try!(__state2(scale, __lookbehind, __lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); } } loop { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { - __Nonterminal::Factor(__nt) => { + __Nonterminal::Expr(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state5(scale, __lookahead, __tokens, __sym0)); + __result = try!(__state1(scale, __lookbehind, __lookahead, __tokens, __sym0)); } __Nonterminal::Term(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state4(scale, __lookahead, __tokens, __sym0)); + __result = try!(__state4(scale, __lookbehind, __lookahead, __tokens, __sym0)); } - __Nonterminal::Expr(__nt) => { + __Nonterminal::Factor(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state3(scale, __lookahead, __tokens, __sym0)); + __result = try!(__state5(scale, __lookbehind, __lookahead, __tokens, __sym0)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } } // State 1 + // Expr = Expr (*) "+" Factor [EOF] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [EOF] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // __Expr = Expr (*) [EOF] + // + // "+" -> Shift(S6) + // EOF -> Reduce(__Expr = Expr => Call(ActionFn(0));) + // "-" -> Shift(S7) + // + pub fn __state1< + __TOKENS: Iterator, + >( + scale: i32, + __lookbehind: Option<()>, + __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> + { + let mut __result: (Option<()>, Option, __Nonterminal<>); + match __lookahead { + Some(__tok @ Tok::Plus(..)) => { + let mut __lookbehind = None; + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state6(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __lookbehind = None; + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state7(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action0(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::____Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 2 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -159,159 +211,117 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S8) - // "(" -> Shift(S9) + // "(" -> Shift(S8) + // "Num" -> Shift(S12) // + // Term -> S9 + // Factor -> S11 // Expr -> S10 - // Term -> S7 - // Factor -> S6 - pub fn __state1< + pub fn __state2< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym1 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state8(scale, __lookahead, __tokens, __sym1)); - } Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state9(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state8(scale, __lookbehind, __lookahead, __tokens, __sym1)); + } + Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; + let mut __sym1 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state12(scale, __lookbehind, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { - __Nonterminal::Expr(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state10(scale, __lookahead, __tokens, __sym0, __sym1)); - } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state7(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state9(scale, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state6(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state11(scale, __lookbehind, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state10(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 2 + // State 3 // Term = "Num" (*) [EOF] // Term = "Num" (*) ["*"] // Term = "Num" (*) ["+"] // Term = "Num" (*) ["-"] // Term = "Num" (*) ["/"] // - // EOF -> Reduce(Term = "Num" => Call(ActionFn(7));) - // "/" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // "-" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // "*" -> Reduce(Term = "Num" => Call(ActionFn(7));) // "+" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // - pub fn __state2< - __TOKENS: Iterator, - >( - scale: i32, - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 3 - // Expr = Expr (*) "+" Factor [EOF] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [EOF] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // __Expr = Expr (*) [EOF] - // - // "+" -> Shift(S11) - // "-" -> Shift(S12) - // EOF -> Reduce(__Expr = Expr => Call(ActionFn(0));) + // "-" -> Reduce(Term = "Num" => Call(ActionFn(7));) + // "/" -> Reduce(Term = "Num" => Call(ActionFn(7));) + // "*" -> Reduce(Term = "Num" => Call(ActionFn(7));) + // EOF -> Reduce(Term = "Num" => Call(ActionFn(7));) // pub fn __state3< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Plus(..)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state11(scale, __lookahead, __tokens, __sym0, __sym1)); + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } - Some(__tok @ Tok::Minus(..)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state12(scale, __lookahead, __tokens, __sym0, __sym1)); + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action0(scale, __sym0); - return Ok((__lookahead, __Nonterminal::____Expr(__nt))); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } _ => { return Err(__lookahead); } } - return Ok(__result); } // State 4 @@ -322,46 +332,47 @@ mod __parse__Expr { // Factor = Term (*) ["/"] // // "*" -> Reduce(Factor = Term => Call(ActionFn(6));) - // "/" -> Reduce(Factor = Term => Call(ActionFn(6));) // "-" -> Reduce(Factor = Term => Call(ActionFn(6));) // "+" -> Reduce(Factor = Term => Call(ActionFn(6));) // EOF -> Reduce(Factor = Term => Call(ActionFn(6));) + // "/" -> Reduce(Factor = Term => Call(ActionFn(6));) // pub fn __state4< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } None => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -384,47 +395,50 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // EOF -> Reduce(Expr = Factor => Call(ActionFn(3));) // "*" -> Shift(S14) // "/" -> Shift(S13) - // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // EOF -> Reduce(Expr = Factor => Call(ActionFn(3));) // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) // pub fn __state5< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::Times(..)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state14(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state14(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } Some(__tok @ Tok::Div(..)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state13(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state13(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } None => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -434,180 +448,172 @@ mod __parse__Expr { } // State 6 - // Expr = Factor (*) [")"] - // Expr = Factor (*) ["+"] - // Expr = Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] + // Expr = Expr "+" (*) Factor [EOF] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] // - // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) - // "*" -> Shift(S16) - // "/" -> Shift(S15) - // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) - // ")" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "Num" -> Shift(S3) + // "(" -> Shift(S2) // + // Factor -> S15 + // Term -> S4 pub fn __state6< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + __sym1: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut __sym1 = &mut Some((__tok)); + Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state16(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state3(scale, __lookbehind, __lookahead, __tokens, __sym2)); } - Some(__tok @ Tok::Div(..)) => { - let mut __sym1 = &mut Some((__tok)); + Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state15(scale, __lookahead, __tokens, __sym0, __sym1)); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state2(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state15(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state4(scale, __lookbehind, __lookahead, __tokens, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } return Ok(__result); } // State 7 - // Factor = Term (*) [")"] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] + // Expr = Expr "-" (*) Factor [EOF] + // Expr = Expr "-" (*) Factor ["+"] + // Expr = Expr "-" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] // - // "+" -> Reduce(Factor = Term => Call(ActionFn(6));) - // "*" -> Reduce(Factor = Term => Call(ActionFn(6));) - // ")" -> Reduce(Factor = Term => Call(ActionFn(6));) - // "-" -> Reduce(Factor = Term => Call(ActionFn(6));) - // "/" -> Reduce(Factor = Term => Call(ActionFn(6));) + // "(" -> Shift(S2) + // "Num" -> Shift(S3) // + // Term -> S4 + // Factor -> S16 pub fn __state7< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + __sym1: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state2(scale, __lookbehind, __lookahead, __tokens, __sym2)); } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action6(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state4(scale, __lookbehind, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state16(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } + return Ok(__result); } // State 8 - // Term = "Num" (*) [")"] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] - // - // "/" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // ")" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // "+" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // "*" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // "-" -> Reduce(Term = "Num" => Call(ActionFn(7));) - // - pub fn __state8< - __TOKENS: Iterator, - >( - scale: i32, - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 9 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -648,60 +654,119 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S9) - // "Num" -> Shift(S8) + // "(" -> Shift(S8) + // "Num" -> Shift(S12) // - // Term -> S7 + // Term -> S9 + // Factor -> S11 // Expr -> S17 - // Factor -> S6 - pub fn __state9< + pub fn __state8< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state9(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state8(scale, __lookbehind, __lookahead, __tokens, __sym1)); } Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state8(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state12(scale, __lookbehind, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state7(scale, __lookahead, __tokens, __sym1)); - } - __Nonterminal::Expr(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state17(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state9(scale, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state6(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state11(scale, __lookbehind, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state17(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } + // State 9 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // ")" -> Reduce(Factor = Term => Call(ActionFn(6));) + // "-" -> Reduce(Factor = Term => Call(ActionFn(6));) + // "/" -> Reduce(Factor = Term => Call(ActionFn(6));) + // "*" -> Reduce(Factor = Term => Call(ActionFn(6));) + // "+" -> Reduce(Factor = Term => Call(ActionFn(6));) + // + pub fn __state9< + __TOKENS: Iterator, + >( + scale: i32, + __lookbehind: Option<()>, + __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> + { + let mut __result: (Option<()>, Option, __Nonterminal<>); + match __lookahead { + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + // State 10 // Expr = Expr (*) "+" Factor [")"] // Expr = Expr (*) "+" Factor ["+"] @@ -715,36 +780,40 @@ mod __parse__Expr { // Term = "(" Expr (*) ")" ["-"] // Term = "(" Expr (*) ")" ["/"] // - // "-" -> Shift(S19) - // ")" -> Shift(S20) - // "+" -> Shift(S18) + // "-" -> Shift(S20) + // ")" -> Shift(S18) + // "+" -> Shift(S19) // pub fn __state10< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::Minus(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state19(scale, __lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state20(scale, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); } Some(__tok @ Tok::RParen(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state20(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state18(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } Some(__tok @ Tok::Plus(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state18(scale, __lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state19(scale, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); } _ => { return Err(__lookahead); @@ -754,163 +823,126 @@ mod __parse__Expr { } // State 11 - // Expr = Expr "+" (*) Factor [EOF] - // Expr = Expr "+" (*) Factor ["+"] - // Expr = Expr "+" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] + // Expr = Factor (*) [")"] + // Expr = Factor (*) ["+"] + // Expr = Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "Num" -> Shift(S2) - // "(" -> Shift(S1) + // "*" -> Shift(S22) + // "/" -> Shift(S21) + // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // ")" -> Reduce(Expr = Factor => Call(ActionFn(3));) // - // Factor -> S21 - // Term -> S4 pub fn __state11< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); + Some(__tok @ Tok::Times(..)) => { + let mut __lookbehind = None; + let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state2(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state22(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some((__tok)); + Some(__tok @ Tok::Div(..)) => { + let mut __lookbehind = None; + let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state1(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state21(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); } } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state21(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state4(scale, __lookahead, __tokens, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } return Ok(__result); } // State 12 - // Expr = Expr "-" (*) Factor [EOF] - // Expr = Expr "-" (*) Factor ["+"] - // Expr = Expr "-" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] // - // "(" -> Shift(S1) - // "Num" -> Shift(S2) + // ")" -> Reduce(Term = "Num" => Call(ActionFn(7));) + // "/" -> Reduce(Term = "Num" => Call(ActionFn(7));) + // "-" -> Reduce(Term = "Num" => Call(ActionFn(7));) + // "*" -> Reduce(Term = "Num" => Call(ActionFn(7));) + // "+" -> Reduce(Term = "Num" => Call(ActionFn(7));) // - // Factor -> S22 - // Term -> S4 pub fn __state12< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state1(scale, __lookahead, __tokens, __sym2)); + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state2(scale, __lookahead, __tokens, __sym2)); + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } _ => { return Err(__lookahead); } } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state22(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state4(scale, __lookahead, __tokens, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); } // State 13 @@ -930,45 +962,48 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S2) - // "(" -> Shift(S1) + // "Num" -> Shift(S3) + // "(" -> Shift(S2) // // Term -> S23 pub fn __state13< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state2(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state3(scale, __lookbehind, __lookahead, __tokens, __sym2)); } Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state1(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state2(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state23(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state23(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } @@ -992,45 +1027,48 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S2) - // "(" -> Shift(S1) + // "Num" -> Shift(S3) + // "(" -> Shift(S2) // // Term -> S24 pub fn __state14< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state2(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state3(scale, __lookbehind, __lookahead, __tokens, __sym2)); } Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state1(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state2(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state24(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state24(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } @@ -1038,126 +1076,152 @@ mod __parse__Expr { } // State 15 - // Factor = Factor "/" (*) Term [")"] - // Factor = Factor "/" (*) Term ["*"] - // Factor = Factor "/" (*) Term ["+"] - // Factor = Factor "/" (*) Term ["-"] - // Factor = Factor "/" (*) Term ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] + // Expr = Expr "+" Factor (*) [EOF] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "(" -> Shift(S9) - // "Num" -> Shift(S8) + // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // EOF -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "*" -> Shift(S14) + // "/" -> Shift(S13) // - // Term -> S25 pub fn __state15< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + __sym2: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some((__tok)); + Some(__tok @ Tok::Times(..)) => { + let mut __lookbehind = None; + let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state9(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state14(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); + Some(__tok @ Tok::Div(..)) => { + let mut __lookbehind = None; + let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state8(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state13(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); } } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state25(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } return Ok(__result); } // State 16 - // Factor = Factor "*" (*) Term [")"] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] + // Expr = Expr "-" Factor (*) [EOF] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "(" -> Shift(S9) - // "Num" -> Shift(S8) + // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "/" -> Shift(S13) + // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // EOF -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "*" -> Shift(S14) // - // Term -> S26 pub fn __state16< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + __sym2: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some((__tok)); + Some(__tok @ Tok::Div(..)) => { + let mut __lookbehind = None; + let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state9(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state13(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); + Some(__tok @ Tok::Times(..)) => { + let mut __lookbehind = None; + let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state8(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state14(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); } } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state26(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } return Ok(__result); } @@ -1174,36 +1238,40 @@ mod __parse__Expr { // Term = "(" Expr (*) ")" ["-"] // Term = "(" Expr (*) ")" ["/"] // - // ")" -> Shift(S27) - // "-" -> Shift(S19) - // "+" -> Shift(S18) + // "+" -> Shift(S19) + // ")" -> Shift(S25) + // "-" -> Shift(S20) // pub fn __state17< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::RParen(..)) => { + Some(__tok @ Tok::Plus(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state27(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state19(scale, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state25(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } Some(__tok @ Tok::Minus(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state19(scale, __lookahead, __tokens, __sym1, __sym2)); - } - Some(__tok @ Tok::Plus(..)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state18(scale, __lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state20(scale, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); } _ => { return Err(__lookahead); @@ -1213,6 +1281,74 @@ mod __parse__Expr { } // State 18 + // Term = "(" Expr ")" (*) [EOF] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // EOF -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // + pub fn __state18< + __TOKENS: Iterator, + >( + scale: i32, + __lookbehind: Option<()>, + __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> + { + let mut __result: (Option<()>, Option, __Nonterminal<>); + match __lookahead { + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 19 // Expr = Expr "+" (*) Factor [")"] // Expr = Expr "+" (*) Factor ["+"] // Expr = Expr "+" (*) Factor ["-"] @@ -1242,57 +1378,60 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S9) - // "Num" -> Shift(S8) + // "Num" -> Shift(S12) + // "(" -> Shift(S8) // - // Factor -> S28 - // Term -> S7 - pub fn __state18< + // Factor -> S26 + // Term -> S9 + pub fn __state19< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state9(scale, __lookahead, __tokens, __sym2)); - } Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state8(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state12(scale, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state8(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state28(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state26(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state7(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state9(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 19 + // State 20 // Expr = Expr "-" (*) Factor [")"] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -1322,264 +1461,186 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S9) - // "Num" -> Shift(S8) + // "Num" -> Shift(S12) + // "(" -> Shift(S8) // - // Term -> S7 - // Factor -> S29 - pub fn __state19< + // Term -> S9 + // Factor -> S27 + pub fn __state20< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state9(scale, __lookahead, __tokens, __sym2)); - } Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state8(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state12(scale, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state8(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state7(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state9(scale, __lookbehind, __lookahead, __tokens, __sym2)); } __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state29(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state27(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 20 - // Term = "(" Expr ")" (*) [EOF] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] + // State 21 + // Factor = Factor "/" (*) Term [")"] + // Factor = Factor "/" (*) Term ["*"] + // Factor = Factor "/" (*) Term ["+"] + // Factor = Factor "/" (*) Term ["-"] + // Factor = Factor "/" (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] // - // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // EOF -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "(" -> Shift(S8) + // "Num" -> Shift(S12) // - pub fn __state20< + // Term -> S28 + pub fn __state21< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state8(scale, __lookbehind, __lookahead, __tokens, __sym2)); } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state12(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } - } - - // State 21 - // Expr = Expr "+" Factor (*) [EOF] - // Expr = Expr "+" Factor (*) ["+"] - // Expr = Expr "+" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // "*" -> Shift(S14) - // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "/" -> Shift(S13) - // EOF -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // - pub fn __state21< - __TOKENS: Iterator, - >( - scale: i32, - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state14(scale, __lookahead, __tokens, __sym2, __sym3)); - } - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state13(scale, __lookahead, __tokens, __sym2, __sym3)); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state28(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } } } return Ok(__result); } // State 22 - // Expr = Expr "-" Factor (*) [EOF] - // Expr = Expr "-" Factor (*) ["+"] - // Expr = Expr "-" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] + // Factor = Factor "*" (*) Term [")"] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] // - // EOF -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "/" -> Shift(S13) - // "*" -> Shift(S14) - // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "Num" -> Shift(S12) + // "(" -> Shift(S8) // + // Term -> S29 pub fn __state22< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some((__tok)); + Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state13(scale, __lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state12(scale, __lookbehind, __lookahead, __tokens, __sym2)); } - Some(__tok @ Tok::Times(..)) => { - let mut __sym3 = &mut Some((__tok)); + Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state14(scale, __lookahead, __tokens, __sym2, __sym3)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state8(scale, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state29(scale, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } return Ok(__result); } @@ -1590,59 +1651,60 @@ mod __parse__Expr { // Factor = Factor "/" Term (*) ["-"] // Factor = Factor "/" Term (*) ["/"] // - // EOF -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // EOF -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // pub fn __state23< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -1657,59 +1719,60 @@ mod __parse__Expr { // Factor = Factor "*" Term (*) ["-"] // Factor = Factor "*" Term (*) ["/"] // - // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // EOF -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // EOF -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) // pub fn __state24< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -1718,65 +1781,66 @@ mod __parse__Expr { } // State 25 - // Factor = Factor "/" Term (*) [")"] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] // - // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // ")" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // ")" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) + // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) // pub fn __state25< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } _ => { return Err(__lookahead); @@ -1785,140 +1849,6 @@ mod __parse__Expr { } // State 26 - // Factor = Factor "*" Term (*) [")"] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] - // - // ")" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // - pub fn __state26< - __TOKENS: Iterator, - >( - scale: i32, - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 27 - // Term = "(" Expr ")" (*) [")"] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] - // - // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // ")" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(8));) - // - pub fn __state27< - __TOKENS: Iterator, - >( - scale: i32, - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 28 // Expr = Expr "+" Factor (*) [")"] // Expr = Expr "+" Factor (*) ["+"] // Expr = Expr "+" Factor (*) ["-"] @@ -1934,54 +1864,57 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["/"] // // ")" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "/" -> Shift(S15) - // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "*" -> Shift(S16) // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "/" -> Shift(S21) + // "*" -> Shift(S22) + // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) // - pub fn __state28< + pub fn __state26< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::Div(..)) => { + let mut __lookbehind = None; let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state15(scale, __lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state21(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } Some(__tok @ Tok::Times(..)) => { + let mut __lookbehind = None; let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state16(scale, __lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state22(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -1990,7 +1923,7 @@ mod __parse__Expr { return Ok(__result); } - // State 29 + // State 27 // Expr = Expr "-" Factor (*) [")"] // Expr = Expr "-" Factor (*) ["+"] // Expr = Expr "-" Factor (*) ["-"] @@ -2005,55 +1938,58 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // ")" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "/" -> Shift(S15) - // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "/" -> Shift(S21) // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "*" -> Shift(S16) + // ")" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "*" -> Shift(S22) // - pub fn __state29< + pub fn __state27< __TOKENS: Iterator, >( scale: i32, - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::Div(..)) => { + let mut __lookbehind = None; let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state15(scale, __lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state21(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } Some(__tok @ Tok::Times(..)) => { + let mut __lookbehind = None; let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state16(scale, __lookahead, __tokens, __sym2, __sym3)); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state22(scale, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -2061,6 +1997,142 @@ mod __parse__Expr { } return Ok(__result); } + + // State 28 + // Factor = Factor "/" Term (*) [")"] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // ")" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // + pub fn __state28< + __TOKENS: Iterator, + >( + scale: i32, + __lookbehind: Option<()>, + __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> + { + let mut __result: (Option<()>, Option, __Nonterminal<>); + match __lookahead { + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 29 + // Factor = Factor "*" Term (*) [")"] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // ")" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // + pub fn __state29< + __TOKENS: Iterator, + >( + scale: i32, + __lookbehind: Option<()>, + __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> + { + let mut __result: (Option<()>, Option, __Nonterminal<>); + match __lookahead { + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } } mod __actions { diff --git a/lalrpop-test/src/expr_arena.rs b/lalrpop-test/src/expr_arena.rs index 826888d..d271374 100644 --- a/lalrpop-test/src/expr_arena.rs +++ b/lalrpop-test/src/expr_arena.rs @@ -13,8 +13,8 @@ pub fn parse_Expr< { let mut __tokens = __tokens.into_iter(); let __lookahead = __tokens.next(); - match try!(__parse__Expr::__state0(arena, __lookahead, &mut __tokens)) { - (__lookahead, __parse__Expr::__Nonterminal::____Expr(__nt)) => Ok((__lookahead, __nt)), + match try!(__parse__Expr::__state0(arena, None, __lookahead, &mut __tokens)) { + (_, __lookahead, __parse__Expr::__Nonterminal::____Expr(__nt)) => Ok((__lookahead, __nt)), _ => unreachable!(), } } @@ -26,14 +26,14 @@ mod __parse__Expr { use util::tok::Tok; pub enum __Nonterminal<'ast, > { + Expr(&'ast Node<'ast>), + Comma_3cExpr_3e(Vec<&'ast Node<'ast>>), + ____Expr(&'ast Node<'ast>), + _28_3cExpr_3e_20_22_2c_22_29_2a(::std::vec::Vec<&'ast Node<'ast>>), _28_3cExpr_3e_20_22_2c_22_29(&'ast Node<'ast>), Factor(&'ast Node<'ast>), Expr_3f(::std::option::Option<&'ast Node<'ast>>), - Comma_3cExpr_3e(Vec<&'ast Node<'ast>>), - _28_3cExpr_3e_20_22_2c_22_29_2a(::std::vec::Vec<&'ast Node<'ast>>), - ____Expr(&'ast Node<'ast>), Term(&'ast Node<'ast>), - Expr(&'ast Node<'ast>), } // State 0 @@ -78,225 +78,70 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // __Expr = (*) Expr [EOF] // - // "*" -> Shift(S6) - // "(" -> Shift(S5) - // "Num" -> Shift(S1) + // "*" -> Shift(S3) + // "Num" -> Shift(S5) + // "(" -> Shift(S2) // - // Expr -> S2 - // Term -> S3 - // Factor -> S4 + // Term -> S4 + // Expr -> S6 + // Factor -> S1 pub fn __state0< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym0 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state6(arena, __lookahead, __tokens, __sym0)); + __result = try!(__state3(arena, __lookbehind, __lookahead, __tokens, __sym0)); } - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym0 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state5(arena, __lookahead, __tokens, __sym0)); - } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym0 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state1(arena, __lookahead, __tokens, __sym0)); + __result = try!(__state5(arena, __lookbehind, __lookahead, __tokens, __sym0)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym0 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state2(arena, __lookbehind, __lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); } } loop { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { - __Nonterminal::Expr(__nt) => { - let __sym0 = &mut Some(__nt); - __result = try!(__state2(arena, __lookahead, __tokens, __sym0)); - } __Nonterminal::Term(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state3(arena, __lookahead, __tokens, __sym0)); + __result = try!(__state4(arena, __lookbehind, __lookahead, __tokens, __sym0)); + } + __Nonterminal::Expr(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state6(arena, __lookbehind, __lookahead, __tokens, __sym0)); } __Nonterminal::Factor(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state4(arena, __lookahead, __tokens, __sym0)); + __result = try!(__state1(arena, __lookbehind, __lookahead, __tokens, __sym0)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } } // State 1 - // Term = "Num" (*) [EOF] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] - // - // "*" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "-" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "/" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "+" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // EOF -> Reduce(Term = "Num" => Call(ActionFn(8));) - // - pub fn __state1< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 2 - // Expr = Expr (*) "+" Factor [EOF] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [EOF] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // __Expr = Expr (*) [EOF] - // - // "-" -> Shift(S7) - // EOF -> Reduce(__Expr = Expr => Call(ActionFn(0));) - // "+" -> Shift(S8) - // - pub fn __state2< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Minus(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state7(arena, __lookahead, __tokens, __sym0, __sym1)); - } - Some((_, __tok @ Tok::Plus(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state8(arena, __lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action0(arena, __sym0); - return Ok((__lookahead, __Nonterminal::____Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 3 - // Factor = Term (*) [EOF] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] - // - // "+" -> Reduce(Factor = Term => Call(ActionFn(7));) - // EOF -> Reduce(Factor = Term => Call(ActionFn(7));) - // "*" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "-" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "/" -> Reduce(Factor = Term => Call(ActionFn(7));) - // - pub fn __state3< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 4 // Expr = Factor (*) [EOF] // Expr = Factor (*) ["+"] // Expr = Factor (*) ["-"] @@ -311,48 +156,51 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "/" -> Shift(S10) - // "*" -> Shift(S9) - // EOF -> Reduce(Expr = Factor => Call(ActionFn(3));) - // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "/" -> Shift(S7) // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // EOF -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "*" -> Shift(S8) // - pub fn __state4< + pub fn __state1< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Div(..), _)) => { + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state10(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state7(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } - Some((_, __tok @ Tok::Times(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state9(arena, __lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state8(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -361,7 +209,7 @@ mod __parse__Expr { return Ok(__result); } - // State 5 + // State 2 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -407,92 +255,262 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S11) - // "Num" -> Shift(S16) + // "(" -> Shift(S13) + // "Num" -> Shift(S12) // "*" -> Shift(S14) // - // Factor -> S13 - // Term -> S15 - // Expr -> S12 - pub fn __state5< + // Expr -> S9 + // Factor -> S10 + // Term -> S11 + pub fn __state2< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state11(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state13(arena, __lookbehind, __lookahead, __tokens, __sym1)); } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state16(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state12(arena, __lookbehind, __lookahead, __tokens, __sym1)); } - Some((_, __tok @ Tok::Times(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state14(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state14(arena, __lookbehind, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state9(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state13(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state10(arena, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state15(arena, __lookahead, __tokens, __sym1)); - } - __Nonterminal::Expr(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state12(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state11(arena, __lookbehind, __lookahead, __tokens, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 6 + // State 3 // Factor = "*" (*) "(" Comma ")" [EOF] // Factor = "*" (*) "(" Comma ")" ["*"] // Factor = "*" (*) "(" Comma ")" ["+"] // Factor = "*" (*) "(" Comma ")" ["-"] // Factor = "*" (*) "(" Comma ")" ["/"] // - // "(" -> Shift(S17) + // "(" -> Shift(S15) + // + pub fn __state3< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state15(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 4 + // Factor = Term (*) [EOF] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "-" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "+" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "/" -> Reduce(Factor = Term => Call(ActionFn(7));) + // EOF -> Reduce(Factor = Term => Call(ActionFn(7));) + // "*" -> Reduce(Factor = Term => Call(ActionFn(7));) + // + pub fn __state4< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 5 + // Term = "Num" (*) [EOF] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "-" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // EOF -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "*" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "/" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "+" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // + pub fn __state5< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 6 + // Expr = Expr (*) "+" Factor [EOF] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [EOF] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // __Expr = Expr (*) [EOF] + // + // EOF -> Reduce(__Expr = Expr => Call(ActionFn(0));) + // "+" -> Shift(S16) + // "-" -> Shift(S17) // pub fn __state6< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::Plus(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state17(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state16(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + Some((_, __tok @ Tok::Minus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state17(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action0(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::____Expr(__nt))); } _ => { return Err(__lookahead); @@ -502,253 +520,6 @@ mod __parse__Expr { } // State 7 - // Expr = Expr "-" (*) Factor [EOF] - // Expr = Expr "-" (*) Factor ["+"] - // Expr = Expr "-" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Factor = (*) "*" "(" Comma ")" [EOF] - // Factor = (*) "*" "(" Comma ")" ["*"] - // Factor = (*) "*" "(" Comma ")" ["+"] - // Factor = (*) "*" "(" Comma ")" ["-"] - // Factor = (*) "*" "(" Comma ")" ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "*" -> Shift(S6) - // "(" -> Shift(S5) - // "Num" -> Shift(S1) - // - // Term -> S3 - // Factor -> S18 - pub fn __state7< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state6(arena, __lookahead, __tokens, __sym2)); - } - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state5(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state18(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 8 - // Expr = Expr "+" (*) Factor [EOF] - // Expr = Expr "+" (*) Factor ["+"] - // Expr = Expr "+" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Factor = (*) "*" "(" Comma ")" [EOF] - // Factor = (*) "*" "(" Comma ")" ["*"] - // Factor = (*) "*" "(" Comma ")" ["+"] - // Factor = (*) "*" "(" Comma ")" ["-"] - // Factor = (*) "*" "(" Comma ")" ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "*" -> Shift(S6) - // "Num" -> Shift(S1) - // "(" -> Shift(S5) - // - // Term -> S3 - // Factor -> S19 - pub fn __state8< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state6(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); - } - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state5(arena, __lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state19(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 9 - // Factor = Factor "*" (*) Term [EOF] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "(" -> Shift(S5) - // "Num" -> Shift(S1) - // - // Term -> S20 - pub fn __state9< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state5(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state20(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 10 // Factor = Factor "/" (*) Term [EOF] // Factor = Factor "/" (*) Term ["*"] // Factor = Factor "/" (*) Term ["+"] @@ -765,53 +536,360 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S5) - // "Num" -> Shift(S1) + // "Num" -> Shift(S5) + // "(" -> Shift(S2) // - // Term -> S21 - pub fn __state10< + // Term -> S18 + pub fn __state7< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state5(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state5(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state2(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state21(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state18(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } + // State 8 + // Factor = Factor "*" (*) Term [EOF] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S5) + // "(" -> Shift(S2) + // + // Term -> S19 + pub fn __state8< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state2(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state19(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 9 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [EOF] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // ")" -> Shift(S21) + // "+" -> Shift(S22) + // "-" -> Shift(S20) + // + pub fn __state9< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::RParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state21(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some((_, __tok @ Tok::Plus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state22(arena, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); + } + Some((_, __tok @ Tok::Minus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state20(arena, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 10 + // Expr = Factor (*) [")"] + // Expr = Factor (*) ["+"] + // Expr = Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "*" -> Shift(S24) + // "/" -> Shift(S23) + // ")" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // + pub fn __state10< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state24(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state23(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + // State 11 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "/" -> Reduce(Factor = Term => Call(ActionFn(7));) + // ")" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "-" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "*" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "+" -> Reduce(Factor = Term => Call(ActionFn(7));) + // + pub fn __state11< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 12 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // ")" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "+" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "-" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "*" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "/" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // + pub fn __state12< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 13 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -857,184 +935,71 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // + // "(" -> Shift(S13) // "*" -> Shift(S14) - // "(" -> Shift(S11) - // "Num" -> Shift(S16) + // "Num" -> Shift(S12) // - // Factor -> S13 - // Term -> S15 - // Expr -> S22 - pub fn __state11< + // Factor -> S10 + // Term -> S11 + // Expr -> S25 + pub fn __state13< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state14(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state13(arena, __lookbehind, __lookahead, __tokens, __sym1)); } - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state11(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state14(arena, __lookbehind, __lookahead, __tokens, __sym1)); } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state16(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state12(arena, __lookbehind, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state13(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state10(arena, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state15(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state11(arena, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Expr(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state22(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state25(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 12 - // Expr = Expr (*) "+" Factor [")"] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [")"] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // Term = "(" Expr (*) ")" [EOF] - // Term = "(" Expr (*) ")" ["*"] - // Term = "(" Expr (*) ")" ["+"] - // Term = "(" Expr (*) ")" ["-"] - // Term = "(" Expr (*) ")" ["/"] - // - // "+" -> Shift(S23) - // ")" -> Shift(S24) - // "-" -> Shift(S25) - // - pub fn __state12< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Plus(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state23(arena, __lookahead, __tokens, __sym1, __sym2)); - } - Some((_, __tok @ Tok::RParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state24(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - Some((_, __tok @ Tok::Minus(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state25(arena, __lookahead, __tokens, __sym1, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 13 - // Expr = Factor (*) [")"] - // Expr = Factor (*) ["+"] - // Expr = Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) - // "*" -> Shift(S26) - // ")" -> Reduce(Expr = Factor => Call(ActionFn(3));) - // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) - // "/" -> Shift(S27) - // - pub fn __state13< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state26(arena, __lookahead, __tokens, __sym0, __sym1)); - } - Some((_, __tok @ Tok::Div(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state27(arena, __lookahead, __tokens, __sym0, __sym1)); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - // State 14 // Factor = "*" (*) "(" Comma ")" [")"] // Factor = "*" (*) "(" Comma ")" ["*"] @@ -1042,24 +1007,26 @@ mod __parse__Expr { // Factor = "*" (*) "(" Comma ")" ["-"] // Factor = "*" (*) "(" Comma ")" ["/"] // - // "(" -> Shift(S28) + // "(" -> Shift(S26) // pub fn __state14< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state28(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state26(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } _ => { return Err(__lookahead); @@ -1069,118 +1036,6 @@ mod __parse__Expr { } // State 15 - // Factor = Term (*) [")"] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] - // - // "/" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "*" -> Reduce(Factor = Term => Call(ActionFn(7));) - // ")" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "-" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "+" -> Reduce(Factor = Term => Call(ActionFn(7));) - // - pub fn __state15< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 16 - // Term = "Num" (*) [")"] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] - // - // "/" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // ")" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "*" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "-" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "+" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // - pub fn __state16< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 17 // ( ",")* = (*) ["("] // ( ",")* = (*) [")"] // ( ",")* = (*) ["*"] @@ -1196,59 +1051,252 @@ mod __parse__Expr { // Factor = "*" "(" (*) Comma ")" ["-"] // Factor = "*" "(" (*) Comma ")" ["/"] // + // "(" -> Reduce(( ",")* = => Call(ActionFn(13));) // ")" -> Reduce(( ",")* = => Call(ActionFn(13));) // "*" -> Reduce(( ",")* = => Call(ActionFn(13));) - // "(" -> Reduce(( ",")* = => Call(ActionFn(13));) // "Num" -> Reduce(( ",")* = => Call(ActionFn(13));) // - // ( ",")* -> S30 - // Comma -> S29 - pub fn __state17< + // Comma -> S28 + // ( ",")* -> S27 + pub fn __state15< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { + Some((_, Tok::LParen(..), _)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + } Some((_, Tok::RParen(..), _)) => { let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); } Some((_, Tok::Times(..), _)) => { let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); - } - Some((_, Tok::LParen(..), _)) => { - let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); } Some((_, Tok::Num(_), _)) => { let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { - __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state30(arena, __lookahead, __tokens, __sym2)); - } __Nonterminal::Comma_3cExpr_3e(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state29(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state28(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state27(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 16 + // Expr = Expr "+" (*) Factor [EOF] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [EOF] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S5) + // "(" -> Shift(S2) + // "*" -> Shift(S3) + // + // Factor -> S29 + // Term -> S4 + pub fn __state16< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state2(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state3(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state29(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state4(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 17 + // Expr = Expr "-" (*) Factor [EOF] + // Expr = Expr "-" (*) Factor ["+"] + // Expr = Expr "-" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [EOF] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S5) + // "*" -> Shift(S3) + // "(" -> Shift(S2) + // + // Term -> S4 + // Factor -> S30 + pub fn __state17< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state3(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state2(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state4(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state30(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); } } } @@ -1256,280 +1304,67 @@ mod __parse__Expr { } // State 18 - // Expr = Expr "-" Factor (*) [EOF] - // Expr = Expr "-" Factor (*) ["+"] - // Expr = Expr "-" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // EOF -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "*" -> Shift(S9) - // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "/" -> Shift(S10) - // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // - pub fn __state18< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state9(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, __tok @ Tok::Div(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state10(arena, __lookahead, __tokens, __sym2, __sym3)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 19 - // Expr = Expr "+" Factor (*) [EOF] - // Expr = Expr "+" Factor (*) ["+"] - // Expr = Expr "+" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "*" -> Shift(S9) - // EOF -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "/" -> Shift(S10) - // - pub fn __state19< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state9(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, __tok @ Tok::Div(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state10(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 20 - // Factor = Factor "*" Term (*) [EOF] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] - // - // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // EOF -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // - pub fn __state20< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 21 // Factor = Factor "/" Term (*) [EOF] // Factor = Factor "/" Term (*) ["*"] // Factor = Factor "/" Term (*) ["+"] // Factor = Factor "/" Term (*) ["-"] // Factor = Factor "/" Term (*) ["/"] // - // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // EOF -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // - pub fn __state21< + pub fn __state18< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -1537,211 +1372,68 @@ mod __parse__Expr { } } - // State 22 - // Expr = Expr (*) "+" Factor [")"] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [")"] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // Term = "(" Expr (*) ")" [")"] - // Term = "(" Expr (*) ")" ["*"] - // Term = "(" Expr (*) ")" ["+"] - // Term = "(" Expr (*) ")" ["-"] - // Term = "(" Expr (*) ")" ["/"] + // State 19 + // Factor = Factor "*" Term (*) [EOF] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] // - // "-" -> Shift(S25) - // "+" -> Shift(S23) - // ")" -> Shift(S31) + // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // EOF -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) // - pub fn __state22< + pub fn __state19< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Minus(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state25(arena, __lookahead, __tokens, __sym1, __sym2)); - } - Some((_, __tok @ Tok::Plus(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state23(arena, __lookahead, __tokens, __sym1, __sym2)); - } - Some((_, __tok @ Tok::RParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state31(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 23 - // Expr = Expr "+" (*) Factor [")"] - // Expr = Expr "+" (*) Factor ["+"] - // Expr = Expr "+" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [")"] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [")"] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [")"] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Factor = (*) "*" "(" Comma ")" [")"] - // Factor = (*) "*" "(" Comma ")" ["*"] - // Factor = (*) "*" "(" Comma ")" ["+"] - // Factor = (*) "*" "(" Comma ")" ["-"] - // Factor = (*) "*" "(" Comma ")" ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "*" -> Shift(S14) - // "Num" -> Shift(S16) - // "(" -> Shift(S11) - // - // Factor -> S32 - // Term -> S15 - pub fn __state23< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state14(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state16(arena, __lookahead, __tokens, __sym2)); - } - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state11(arena, __lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state32(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state15(arena, __lookahead, __tokens, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 24 - // Term = "(" Expr ")" (*) [EOF] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] - // - // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // EOF -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // - pub fn __state24< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option<&'ast Node<'ast>>, - __sym2: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -1749,7 +1441,7 @@ mod __parse__Expr { } } - // State 25 + // State 20 // Expr = Expr "-" (*) Factor [")"] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -1784,69 +1476,160 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S11) + // "Num" -> Shift(S12) + // "(" -> Shift(S13) // "*" -> Shift(S14) - // "Num" -> Shift(S16) // - // Term -> S15 - // Factor -> S33 - pub fn __state25< + // Term -> S11 + // Factor -> S31 + pub fn __state20< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state11(arena, __lookahead, __tokens, __sym2)); - } - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state14(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state16(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state12(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state13(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state14(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state15(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state11(arena, __lookbehind, __lookahead, __tokens, __sym2)); } __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state33(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state31(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 26 - // Factor = Factor "*" (*) Term [")"] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] + // State 21 + // Term = "(" Expr ")" (*) [EOF] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // EOF -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // + pub fn __state21< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + __sym2: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 22 + // Expr = Expr "+" (*) Factor [")"] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [")"] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [")"] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] // Term = (*) "(" Expr ")" [")"] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -1858,53 +1641,68 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S11) - // "Num" -> Shift(S16) + // "(" -> Shift(S13) + // "*" -> Shift(S14) + // "Num" -> Shift(S12) // - // Term -> S34 - pub fn __state26< + // Factor -> S32 + // Term -> S11 + pub fn __state22< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state11(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state13(arena, __lookbehind, __lookahead, __tokens, __sym2)); } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state14(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state16(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state12(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state32(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state34(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state11(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 27 + // State 23 // Factor = Factor "/" (*) Term [")"] // Factor = Factor "/" (*) Term ["*"] // Factor = Factor "/" (*) Term ["+"] @@ -1921,53 +1719,178 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S11) - // "Num" -> Shift(S16) + // "(" -> Shift(S13) + // "Num" -> Shift(S12) // - // Term -> S35 - pub fn __state27< + // Term -> S33 + pub fn __state23< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state11(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state13(arena, __lookbehind, __lookahead, __tokens, __sym2)); } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state16(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state12(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state35(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state33(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 28 + // State 24 + // Factor = Factor "*" (*) Term [")"] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S12) + // "(" -> Shift(S13) + // + // Term -> S34 + pub fn __state24< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state12(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state13(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state34(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 25 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [")"] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // "+" -> Shift(S22) + // ")" -> Shift(S35) + // "-" -> Shift(S20) + // + pub fn __state25< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::Plus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state22(arena, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); + } + Some((_, __tok @ Tok::RParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state35(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some((_, __tok @ Tok::Minus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state20(arena, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 26 // ( ",")* = (*) ["("] // ( ",")* = (*) [")"] // ( ",")* = (*) ["*"] @@ -1983,101 +1906,67 @@ mod __parse__Expr { // Factor = "*" "(" (*) Comma ")" ["-"] // Factor = "*" "(" (*) Comma ")" ["/"] // - // "*" -> Reduce(( ",")* = => Call(ActionFn(13));) // "(" -> Reduce(( ",")* = => Call(ActionFn(13));) // ")" -> Reduce(( ",")* = => Call(ActionFn(13));) // "Num" -> Reduce(( ",")* = => Call(ActionFn(13));) + // "*" -> Reduce(( ",")* = => Call(ActionFn(13));) // - // ( ",")* -> S30 + // ( ",")* -> S27 // Comma -> S36 - pub fn __state28< + pub fn __state26< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Times(..), _)) => { - let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); - } Some((_, Tok::LParen(..), _)) => { let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); } Some((_, Tok::RParen(..), _)) => { let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); } Some((_, Tok::Num(_), _)) => { let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + } + Some((_, Tok::Times(..), _)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state30(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state27(arena, __lookbehind, __lookahead, __tokens, __sym2)); } __Nonterminal::Comma_3cExpr_3e(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state36(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state36(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 29 - // Factor = "*" "(" Comma (*) ")" [EOF] - // Factor = "*" "(" Comma (*) ")" ["*"] - // Factor = "*" "(" Comma (*) ")" ["+"] - // Factor = "*" "(" Comma (*) ")" ["-"] - // Factor = "*" "(" Comma (*) ")" ["/"] - // - // ")" -> Shift(S37) - // - pub fn __state29< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::RParen(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state37(arena, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 30 + // State 27 // ( ",") = (*) Expr "," ["("] // ( ",") = (*) Expr "," [")"] // ( ",") = (*) Expr "," ["*"] @@ -2138,148 +2027,349 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S39) - // "*" -> Shift(S41) - // "Num" -> Shift(S45) + // "*" -> Shift(S42) + // "Num" -> Shift(S43) // ")" -> Reduce(Expr? = => Call(ActionFn(12));) + // "(" -> Shift(S39) // - // Term -> S38 - // Expr? -> S44 - // ( ",") -> S40 - // Factor -> S43 - // Expr -> S42 - pub fn __state30< + // ( ",") -> S44 + // Term -> S41 + // Expr? -> S38 + // Factor -> S40 + // Expr -> S37 + pub fn __state27< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<::std::vec::Vec<&'ast Node<'ast>>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state39(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state42(arena, __lookbehind, __lookahead, __tokens, __sym1)); } - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state41(arena, __lookahead, __tokens, __sym1)); - } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state45(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state43(arena, __lookbehind, __lookahead, __tokens, __sym1)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookbehind, __lookahead, __tokens, __sym1)); } Some((_, Tok::RParen(..), _)) => { let __nt = super::__actions::__action12(arena, ); - __result = (__lookahead, __Nonterminal::Expr_3f(__nt)); + __result = (__lookbehind, __lookahead, __Nonterminal::Expr_3f(__nt)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { + __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state44(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state38(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state41(arena, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Expr_3f(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state44(arena, __lookahead, __tokens, __sym0, __sym1)); - } - __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state40(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state38(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state43(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state40(arena, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Expr(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state42(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state37(arena, __lookbehind, __lookahead, __tokens, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 31 - // Term = "(" Expr ")" (*) [")"] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] + // State 28 + // Factor = "*" "(" Comma (*) ")" [EOF] + // Factor = "*" "(" Comma (*) ")" ["*"] + // Factor = "*" "(" Comma (*) ")" ["+"] + // Factor = "*" "(" Comma (*) ")" ["-"] + // Factor = "*" "(" Comma (*) ")" ["/"] // - // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // ")" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // ")" -> Shift(S45) + // + pub fn __state28< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::RParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state45(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 29 + // Expr = Expr "+" Factor (*) [EOF] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "*" -> Shift(S8) + // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "/" -> Shift(S7) + // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // EOF -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // + pub fn __state29< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state8(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state7(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 30 + // Expr = Expr "-" Factor (*) [EOF] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "*" -> Shift(S8) + // EOF -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "/" -> Shift(S7) + // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // + pub fn __state30< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state8(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state7(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 31 + // Expr = Expr "-" Factor (*) [")"] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // ")" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "*" -> Shift(S24) + // "/" -> Shift(S23) // pub fn __state31< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option<&'ast Node<'ast>>, - __sym2: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state24(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state23(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); } } + return Ok(__result); } // State 32 @@ -2297,56 +2387,59 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "/" -> Shift(S27) // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // ")" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "*" -> Shift(S26) // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // ")" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "/" -> Shift(S23) + // "*" -> Shift(S24) // pub fn __state32< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Div(..), _)) => { + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state27(arena, __lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state23(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } - Some((_, __tok @ Tok::Times(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state26(arena, __lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state24(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -2356,76 +2449,72 @@ mod __parse__Expr { } // State 33 - // Expr = Expr "-" Factor (*) [")"] - // Expr = Expr "-" Factor (*) ["+"] - // Expr = Expr "-" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] + // Factor = Factor "/" Term (*) [")"] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] // - // "*" -> Shift(S26) - // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "/" -> Shift(S27) - // ")" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // ")" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // pub fn __state33< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state26(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, __tok @ Tok::Div(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state27(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, Tok::Minus(..), _)) => { + Some((_, Tok::Div(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); } } - return Ok(__result); } // State 34 @@ -2435,60 +2524,61 @@ mod __parse__Expr { // Factor = Factor "*" Term (*) ["-"] // Factor = Factor "*" Term (*) ["/"] // - // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) // ")" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) // pub fn __state34< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Times(..), _)) => { + Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } - Some((_, Tok::Div(..), _)) => { + Some((_, Tok::Times(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -2497,66 +2587,67 @@ mod __parse__Expr { } // State 35 - // Factor = Factor "/" Term (*) [")"] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] // - // ")" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // ")" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) // pub fn __state35< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + __sym2: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } Some((_, Tok::Times(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } _ => { return Err(__lookahead); @@ -2578,19 +2669,21 @@ mod __parse__Expr { __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::RParen(..), _)) => { + Some((_, __tok @ Tok::RParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym3 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state46(arena, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); + __result = try!(__state46(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); } _ => { return Err(__lookahead); @@ -2600,135 +2693,92 @@ mod __parse__Expr { } // State 37 - // Factor = "*" "(" Comma ")" (*) [EOF] - // Factor = "*" "(" Comma ")" (*) ["*"] - // Factor = "*" "(" Comma ")" (*) ["+"] - // Factor = "*" "(" Comma ")" (*) ["-"] - // Factor = "*" "(" Comma ")" (*) ["/"] + // ( ",") = Expr (*) "," ["("] + // ( ",") = Expr (*) "," [")"] + // ( ",") = Expr (*) "," ["*"] + // ( ",") = Expr (*) "," ["Num"] + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor [","] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor [","] + // Expr = Expr (*) "-" Factor ["-"] + // Expr? = Expr (*) [")"] // - // "+" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // "-" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // EOF -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // "/" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // "*" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "+" -> Shift(S47) + // ")" -> Reduce(Expr? = Expr => Call(ActionFn(11));) + // "," -> Shift(S48) + // "-" -> Shift(S49) // pub fn __state37< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option>>, - __sym3: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some((_, __tok @ Tok::Plus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state47(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some((_, __tok @ Tok::Comma(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state48(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some((_, __tok @ Tok::Minus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state49(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } - Some((_, Tok::Div(..), _)) => { + Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action11(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr_3f(__nt))); } _ => { return Err(__lookahead); } } + return Ok(__result); } // State 38 - // Factor = Term (*) [")"] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) [","] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] + // Comma = ( ",")* Expr? (*) [")"] // - // "/" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "+" -> Reduce(Factor = Term => Call(ActionFn(7));) - // ")" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "*" -> Reduce(Factor = Term => Call(ActionFn(7));) - // "," -> Reduce(Factor = Term => Call(ActionFn(7));) - // "-" -> Reduce(Factor = Term => Call(ActionFn(7));) + // ")" -> Reduce(Comma = ( ",")*, Expr? => Call(ActionFn(10));) // pub fn __state38< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option<::std::vec::Vec<&'ast Node<'ast>>>, + __sym1: &mut Option<::std::option::Option<&'ast Node<'ast>>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Comma(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action10(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::Comma_3cExpr_3e(__nt))); } _ => { return Err(__lookahead); @@ -2783,61 +2833,65 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // + // "(" -> Shift(S13) // "*" -> Shift(S14) - // "(" -> Shift(S11) - // "Num" -> Shift(S16) + // "Num" -> Shift(S12) // - // Term -> S15 - // Factor -> S13 - // Expr -> S47 + // Term -> S11 + // Factor -> S10 + // Expr -> S50 pub fn __state39< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state14(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state13(arena, __lookbehind, __lookahead, __tokens, __sym1)); } - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state11(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state14(arena, __lookbehind, __lookahead, __tokens, __sym1)); } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state16(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state12(arena, __lookbehind, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state15(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state11(arena, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state13(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state10(arena, __lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::Expr(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state47(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state50(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } @@ -2845,153 +2899,6 @@ mod __parse__Expr { } // State 40 - // ( ",")* = ( ",")* ( ",") (*) ["("] - // ( ",")* = ( ",")* ( ",") (*) [")"] - // ( ",")* = ( ",")* ( ",") (*) ["*"] - // ( ",")* = ( ",")* ( ",") (*) ["Num"] - // - // "(" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) - // "*" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) - // ")" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) - // "Num" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) - // - pub fn __state40< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<::std::vec::Vec<&'ast Node<'ast>>>, - __sym1: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::LParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action14(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action14(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action14(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); - } - Some((_, Tok::Num(_), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action14(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 41 - // Factor = "*" (*) "(" Comma ")" [")"] - // Factor = "*" (*) "(" Comma ")" ["*"] - // Factor = "*" (*) "(" Comma ")" ["+"] - // Factor = "*" (*) "(" Comma ")" [","] - // Factor = "*" (*) "(" Comma ")" ["-"] - // Factor = "*" (*) "(" Comma ")" ["/"] - // - // "(" -> Shift(S48) - // - pub fn __state41< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state48(arena, __lookahead, __tokens, __sym0, __sym1)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 42 - // ( ",") = Expr (*) "," ["("] - // ( ",") = Expr (*) "," [")"] - // ( ",") = Expr (*) "," ["*"] - // ( ",") = Expr (*) "," ["Num"] - // Expr = Expr (*) "+" Factor [")"] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor [","] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [")"] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor [","] - // Expr = Expr (*) "-" Factor ["-"] - // Expr? = Expr (*) [")"] - // - // "-" -> Shift(S50) - // "," -> Shift(S49) - // ")" -> Reduce(Expr? = Expr => Call(ActionFn(11));) - // "+" -> Shift(S51) - // - pub fn __state42< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Minus(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state50(arena, __lookahead, __tokens, __sym0, __sym1)); - } - Some((_, __tok @ Tok::Comma(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state49(arena, __lookahead, __tokens, __sym0, __sym1)); - } - Some((_, __tok @ Tok::Plus(..), _)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state51(arena, __lookahead, __tokens, __sym0, __sym1)); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action11(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr_3f(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 43 // Expr = Factor (*) [")"] // Expr = Factor (*) ["+"] // Expr = Factor (*) [","] @@ -3009,54 +2916,57 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // ")" -> Reduce(Expr = Factor => Call(ActionFn(3));) // "," -> Reduce(Expr = Factor => Call(ActionFn(3));) - // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) - // "*" -> Shift(S53) - // "/" -> Shift(S52) + // "*" -> Shift(S52) // "+" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // ")" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "-" -> Reduce(Expr = Factor => Call(ActionFn(3));) + // "/" -> Shift(S51) // - pub fn __state43< + pub fn __state40< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state53(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state52(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } - Some((_, __tok @ Tok::Div(..), _)) => { + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state52(arena, __lookahead, __tokens, __sym0, __sym1)); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state51(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); } Some((_, Tok::Comma(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -3065,29 +2975,218 @@ mod __parse__Expr { return Ok(__result); } - // State 44 - // Comma = ( ",")* Expr? (*) [")"] + // State 41 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) [","] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] // - // ")" -> Reduce(Comma = ( ",")*, Expr? => Call(ActionFn(10));) + // "+" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "/" -> Reduce(Factor = Term => Call(ActionFn(7));) + // ")" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "," -> Reduce(Factor = Term => Call(ActionFn(7));) + // "-" -> Reduce(Factor = Term => Call(ActionFn(7));) + // "*" -> Reduce(Factor = Term => Call(ActionFn(7));) + // + pub fn __state41< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Comma(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 42 + // Factor = "*" (*) "(" Comma ")" [")"] + // Factor = "*" (*) "(" Comma ")" ["*"] + // Factor = "*" (*) "(" Comma ")" ["+"] + // Factor = "*" (*) "(" Comma ")" [","] + // Factor = "*" (*) "(" Comma ")" ["-"] + // Factor = "*" (*) "(" Comma ")" ["/"] + // + // "(" -> Shift(S53) + // + pub fn __state42< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state53(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 43 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) [","] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "-" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // ")" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "," -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "*" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "+" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "/" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // + pub fn __state43< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Comma(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 44 + // ( ",")* = ( ",")* ( ",") (*) ["("] + // ( ",")* = ( ",")* ( ",") (*) [")"] + // ( ",")* = ( ",")* ( ",") (*) ["*"] + // ( ",")* = ( ",")* ( ",") (*) ["Num"] + // + // ")" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) + // "*" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) + // "(" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) + // "Num" -> Reduce(( ",")* = ( ",")*, ( ",") => Call(ActionFn(14));) // pub fn __state44< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<::std::vec::Vec<&'ast Node<'ast>>>, - __sym1: &mut Option<::std::option::Option<&'ast Node<'ast>>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym1: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action10(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::Comma_3cExpr_3e(__nt))); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); + } + Some((_, Tok::LParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); + } + Some((_, Tok::Num(_), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt))); } _ => { return Err(__lookahead); @@ -3096,61 +3195,73 @@ mod __parse__Expr { } // State 45 - // Term = "Num" (*) [")"] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) [","] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] + // Factor = "*" "(" Comma ")" (*) [EOF] + // Factor = "*" "(" Comma ")" (*) ["*"] + // Factor = "*" "(" Comma ")" (*) ["+"] + // Factor = "*" "(" Comma ")" (*) ["-"] + // Factor = "*" "(" Comma ")" (*) ["/"] // - // "*" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "+" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // ")" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "," -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "-" -> Reduce(Term = "Num" => Call(ActionFn(8));) - // "/" -> Reduce(Term = "Num" => Call(ActionFn(8));) + // "*" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // EOF -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "/" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "+" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "-" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) // pub fn __state45< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option>>, + __sym3: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { Some((_, Tok::Times(..), _)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } - Some((_, Tok::Plus(..), _)) => { + None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Comma(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Div(..), _)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action8(arena, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -3165,58 +3276,43 @@ mod __parse__Expr { // Factor = "*" "(" Comma ")" (*) ["-"] // Factor = "*" "(" Comma ")" (*) ["/"] // - // "*" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // "-" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) // "/" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // ")" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "*" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) // "+" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "-" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // ")" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) // pub fn __state46< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option>>, __sym3: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some((_, Tok::Div(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __sym3 = __sym3.take().unwrap(); let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } - Some((_, Tok::RParen(..), _)) => { + Some((_, Tok::Times(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __sym3 = __sym3.take().unwrap(); let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); @@ -3224,7 +3320,23 @@ mod __parse__Expr { let __sym2 = __sym2.take().unwrap(); let __sym3 = __sym3.take().unwrap(); let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -3233,288 +3345,6 @@ mod __parse__Expr { } // State 47 - // Expr = Expr (*) "+" Factor [")"] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [")"] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // Term = "(" Expr (*) ")" [")"] - // Term = "(" Expr (*) ")" ["*"] - // Term = "(" Expr (*) ")" ["+"] - // Term = "(" Expr (*) ")" [","] - // Term = "(" Expr (*) ")" ["-"] - // Term = "(" Expr (*) ")" ["/"] - // - // "-" -> Shift(S25) - // "+" -> Shift(S23) - // ")" -> Shift(S54) - // - pub fn __state47< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Minus(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state25(arena, __lookahead, __tokens, __sym1, __sym2)); - } - Some((_, __tok @ Tok::Plus(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state23(arena, __lookahead, __tokens, __sym1, __sym2)); - } - Some((_, __tok @ Tok::RParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state54(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 48 - // ( ",")* = (*) ["("] - // ( ",")* = (*) [")"] - // ( ",")* = (*) ["*"] - // ( ",")* = (*) ["Num"] - // ( ",")* = (*) ( ",")* ( ",") ["("] - // ( ",")* = (*) ( ",")* ( ",") [")"] - // ( ",")* = (*) ( ",")* ( ",") ["*"] - // ( ",")* = (*) ( ",")* ( ",") ["Num"] - // Comma = (*) ( ",")* Expr? [")"] - // Factor = "*" "(" (*) Comma ")" [")"] - // Factor = "*" "(" (*) Comma ")" ["*"] - // Factor = "*" "(" (*) Comma ")" ["+"] - // Factor = "*" "(" (*) Comma ")" [","] - // Factor = "*" "(" (*) Comma ")" ["-"] - // Factor = "*" "(" (*) Comma ")" ["/"] - // - // ")" -> Reduce(( ",")* = => Call(ActionFn(13));) - // "*" -> Reduce(( ",")* = => Call(ActionFn(13));) - // "Num" -> Reduce(( ",")* = => Call(ActionFn(13));) - // "(" -> Reduce(( ",")* = => Call(ActionFn(13));) - // - // Comma -> S55 - // ( ",")* -> S30 - pub fn __state48< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::RParen(..), _)) => { - let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); - } - Some((_, Tok::Times(..), _)) => { - let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); - } - Some((_, Tok::Num(_), _)) => { - let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); - } - Some((_, Tok::LParen(..), _)) => { - let __nt = super::__actions::__action13(arena, ); - __result = (__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Comma_3cExpr_3e(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state55(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state30(arena, __lookahead, __tokens, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 49 - // ( ",") = Expr "," (*) ["("] - // ( ",") = Expr "," (*) [")"] - // ( ",") = Expr "," (*) ["*"] - // ( ",") = Expr "," (*) ["Num"] - // - // ")" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) - // "(" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) - // "*" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) - // "Num" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) - // - pub fn __state49< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action15(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); - } - Some((_, Tok::LParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action15(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action15(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); - } - Some((_, Tok::Num(_), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __nt = super::__actions::__action15(arena, __sym0, __sym1); - return Ok((__lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 50 - // Expr = Expr "-" (*) Factor [")"] - // Expr = Expr "-" (*) Factor ["+"] - // Expr = Expr "-" (*) Factor [","] - // Expr = Expr "-" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [")"] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term [","] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [")"] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term [","] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [")"] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term [","] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Factor = (*) "*" "(" Comma ")" [")"] - // Factor = (*) "*" "(" Comma ")" ["*"] - // Factor = (*) "*" "(" Comma ")" ["+"] - // Factor = (*) "*" "(" Comma ")" [","] - // Factor = (*) "*" "(" Comma ")" ["-"] - // Factor = (*) "*" "(" Comma ")" ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" [","] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" [","] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "Num" -> Shift(S45) - // "(" -> Shift(S39) - // "*" -> Shift(S41) - // - // Term -> S38 - // Factor -> S56 - pub fn __state50< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, Tok::Num(__tok0), _)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state45(arena, __lookahead, __tokens, __sym2)); - } - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state39(arena, __lookahead, __tokens, __sym2)); - } - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state41(arena, __lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state38(arena, __lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state56(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 51 // Expr = Expr "+" (*) Factor [")"] // Expr = Expr "+" (*) Factor ["+"] // Expr = Expr "+" (*) Factor [","] @@ -3556,64 +3386,283 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // + // "*" -> Shift(S42) + // "Num" -> Shift(S43) // "(" -> Shift(S39) - // "*" -> Shift(S41) - // "Num" -> Shift(S45) // - // Term -> S38 - // Factor -> S57 - pub fn __state51< + // Term -> S41 + // Factor -> S54 + pub fn __state47< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state39(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state42(arena, __lookbehind, __lookahead, __tokens, __sym2)); } - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state41(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state45(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state43(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state38(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state41(arena, __lookbehind, __lookahead, __tokens, __sym2)); } __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state57(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state54(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 52 + // State 48 + // ( ",") = Expr "," (*) ["("] + // ( ",") = Expr "," (*) [")"] + // ( ",") = Expr "," (*) ["*"] + // ( ",") = Expr "," (*) ["Num"] + // + // "Num" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) + // "(" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) + // ")" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) + // "*" -> Reduce(( ",") = Expr, "," => Call(ActionFn(15));) + // + pub fn __state48< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Num(_), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); + } + Some((_, Tok::LParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 49 + // Expr = Expr "-" (*) Factor [")"] + // Expr = Expr "-" (*) Factor ["+"] + // Expr = Expr "-" (*) Factor [","] + // Expr = Expr "-" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [")"] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term [","] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [")"] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term [","] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term [","] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" [","] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" [","] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" [","] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S43) + // "(" -> Shift(S39) + // "*" -> Shift(S42) + // + // Term -> S41 + // Factor -> S55 + pub fn __state49< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state43(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state42(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state41(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state55(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 50 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [")"] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" [","] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // "-" -> Shift(S20) + // "+" -> Shift(S22) + // ")" -> Shift(S56) + // + pub fn __state50< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::Minus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state20(arena, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); + } + Some((_, __tok @ Tok::Plus(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state22(arena, __lookbehind, __lookahead, __tokens, __sym1, __sym2)); + } + Some((_, __tok @ Tok::RParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state56(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 51 // Factor = Factor "/" (*) Term [")"] // Factor = Factor "/" (*) Term ["*"] // Factor = Factor "/" (*) Term ["+"] @@ -3633,53 +3682,56 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // + // "Num" -> Shift(S43) // "(" -> Shift(S39) - // "Num" -> Shift(S45) // - // Term -> S58 - pub fn __state52< + // Term -> S57 + pub fn __state51< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state39(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state45(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state43(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state58(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state57(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 53 + // State 52 // Factor = Factor "*" (*) Term [")"] // Factor = Factor "*" (*) Term ["*"] // Factor = Factor "*" (*) Term ["+"] @@ -3699,46 +3751,126 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // + // "Num" -> Shift(S43) // "(" -> Shift(S39) - // "Num" -> Shift(S45) // - // Term -> S59 - pub fn __state53< + // Term -> S58 + pub fn __state52< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::LParen(..), _)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state39(arena, __lookahead, __tokens, __sym2)); - } - Some((_, Tok::Num(__tok0), _)) => { + Some((_, Tok::Num(__tok0), __loc)) => { + let mut __lookbehind = Some(__loc); let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state45(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state43(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + Some((_, __tok @ Tok::LParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state59(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state58(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 53 + // ( ",")* = (*) ["("] + // ( ",")* = (*) [")"] + // ( ",")* = (*) ["*"] + // ( ",")* = (*) ["Num"] + // ( ",")* = (*) ( ",")* ( ",") ["("] + // ( ",")* = (*) ( ",")* ( ",") [")"] + // ( ",")* = (*) ( ",")* ( ",") ["*"] + // ( ",")* = (*) ( ",")* ( ",") ["Num"] + // Comma = (*) ( ",")* Expr? [")"] + // Factor = "*" "(" (*) Comma ")" [")"] + // Factor = "*" "(" (*) Comma ")" ["*"] + // Factor = "*" "(" (*) Comma ")" ["+"] + // Factor = "*" "(" (*) Comma ")" [","] + // Factor = "*" "(" (*) Comma ")" ["-"] + // Factor = "*" "(" (*) Comma ")" ["/"] + // + // "*" -> Reduce(( ",")* = => Call(ActionFn(13));) + // "(" -> Reduce(( ",")* = => Call(ActionFn(13));) + // ")" -> Reduce(( ",")* = => Call(ActionFn(13));) + // "Num" -> Reduce(( ",")* = => Call(ActionFn(13));) + // + // ( ",")* -> S27 + // Comma -> S59 + pub fn __state53< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Times(..), _)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + } + Some((_, Tok::LParen(..), _)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + } + Some((_, Tok::RParen(..), _)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + } + Some((_, Tok::Num(_), _)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookbehind, __lookahead, __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookbehind, __lookahead, __nt) = __result; + match __nt { + __Nonterminal::_28_3cExpr_3e_20_22_2c_22_29_2a(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state27(arena, __lookbehind, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Comma_3cExpr_3e(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state59(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookbehind, __lookahead, __nt)); } } } @@ -3746,110 +3878,84 @@ mod __parse__Expr { } // State 54 - // Term = "(" Expr ")" (*) [")"] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) [","] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] + // Expr = Expr "+" Factor (*) [")"] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) [","] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term [","] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term [","] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "," -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // ")" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) - // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "," -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // ")" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "/" -> Shift(S51) + // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) + // "*" -> Shift(S52) // pub fn __state54< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option<&'ast Node<'ast>>, - __sym2: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Comma(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state51(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state52(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } - Some((_, Tok::Div(..), _)) => { + Some((_, Tok::Comma(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } - Some((_, Tok::Times(..), _)) => { + Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 55 - // Factor = "*" "(" Comma (*) ")" [")"] - // Factor = "*" "(" Comma (*) ")" ["*"] - // Factor = "*" "(" Comma (*) ")" ["+"] - // Factor = "*" "(" Comma (*) ")" [","] - // Factor = "*" "(" Comma (*) ")" ["-"] - // Factor = "*" "(" Comma (*) ")" ["/"] - // - // ")" -> Shift(S60) - // - pub fn __state55< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::RParen(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state60(arena, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -3858,7 +3964,7 @@ mod __parse__Expr { return Ok(__result); } - // State 56 + // State 55 // Expr = Expr "-" Factor (*) [")"] // Expr = Expr "-" Factor (*) ["+"] // Expr = Expr "-" Factor (*) [","] @@ -3877,156 +3983,153 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["/"] // // "+" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "/" -> Shift(S52) // "-" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // ")" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // "*" -> Shift(S52) // "," -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) - // "*" -> Shift(S53) + // "/" -> Shift(S51) + // ")" -> Reduce(Expr = Expr, "-", Factor => Call(ActionFn(1));) + // + pub fn __state55< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, __tok @ Tok::Times(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state52(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + Some((_, __tok @ Tok::Div(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state51(arena, __lookbehind, __lookahead, __tokens, __sym2, __sym3)); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::Comma(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 56 + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) [","] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "-" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "/" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "*" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // ")" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "," -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) + // "+" -> Reduce(Term = "(", Expr, ")" => Call(ActionFn(9));) // pub fn __state56< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + __sym2: &mut Option, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, __tok @ Tok::Div(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state52(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state53(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } Some((_, Tok::Minus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } Some((_, Tok::Comma(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Term(__nt))); } _ => { return Err(__lookahead); } } - return Ok(__result); } // State 57 - // Expr = Expr "+" Factor (*) [")"] - // Expr = Expr "+" Factor (*) ["+"] - // Expr = Expr "+" Factor (*) [","] - // Expr = Expr "+" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term [","] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term [","] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // ")" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "+" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "-" -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "*" -> Shift(S53) - // "," -> Reduce(Expr = Expr, "+", Factor => Call(ActionFn(2));) - // "/" -> Shift(S52) - // - pub fn __state57< - 'ast, - __TOKENS: Iterator, - >( - arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, - __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, - __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> - { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); - match __lookahead { - Some((_, __tok @ Tok::Times(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state53(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, __tok @ Tok::Div(..), _)) => { - let mut __sym3 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state52(arena, __lookahead, __tokens, __sym2, __sym3)); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some((_, Tok::Comma(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 58 // Factor = Factor "/" Term (*) [")"] // Factor = Factor "/" Term (*) ["*"] // Factor = Factor "/" Term (*) ["+"] @@ -4034,68 +4137,147 @@ mod __parse__Expr { // Factor = Factor "/" Term (*) ["-"] // Factor = Factor "/" Term (*) ["/"] // - // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // "+" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // "," -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) - // ")" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // "*" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // ")" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "-" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) + // "/" -> Reduce(Factor = Factor, "/", Term => Call(ActionFn(5));) // - pub fn __state58< + pub fn __state57< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option<&'ast Node<'ast>>, __sym1: &mut Option, __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some((_, Tok::Plus(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Comma(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Times(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 58 + // Factor = Factor "*" Term (*) [")"] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) [","] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // ")" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "," -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // + pub fn __state58< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + { + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + match __lookahead { + Some((_, Tok::Times(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::RParen(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Comma(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -4104,80 +4286,41 @@ mod __parse__Expr { } // State 59 - // Factor = Factor "*" Term (*) [")"] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) [","] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] + // Factor = "*" "(" Comma (*) ")" [")"] + // Factor = "*" "(" Comma (*) ")" ["*"] + // Factor = "*" "(" Comma (*) ")" ["+"] + // Factor = "*" "(" Comma (*) ")" [","] + // Factor = "*" "(" Comma (*) ")" ["-"] + // Factor = "*" "(" Comma (*) ")" ["/"] // - // "-" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "," -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "+" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "/" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // ")" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) - // "*" -> Reduce(Factor = Factor, "*", Term => Call(ActionFn(4));) + // ")" -> Shift(S60) // pub fn __state59< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, + __sym0: &mut Option, __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + __sym2: &mut Option>>, + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Minus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Comma(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::RParen(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some((_, __tok @ Tok::RParen(..), __loc)) => { + let mut __lookbehind = Some(__loc); + let mut __sym3 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state60(arena, __lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); } _ => { return Err(__lookahead); } } + return Ok(__result); } // State 60 @@ -4188,35 +4331,36 @@ mod __parse__Expr { // Factor = "*" "(" Comma ")" (*) ["-"] // Factor = "*" "(" Comma ")" (*) ["/"] // - // "-" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // ")" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // "+" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) - // "/" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) // "*" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // ")" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) // "," -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "+" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "-" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) + // "/" -> Reduce(Factor = "*", "(", Comma, ")" => Call(ActionFn(6));) // pub fn __state60< 'ast, __TOKENS: Iterator, >( arena: &'ast Arena<'ast>, - mut __lookahead: Option<(usize,Tok,usize)>, + __lookbehind: Option, + __lookahead: Option<(usize,Tok,usize)>, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option>>, __sym3: &mut Option, - ) -> Result<(Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> + ) -> Result<(Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >), Option<(usize,Tok,usize)>> { - let mut __result: (Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); + let mut __result: (Option, Option<(usize,Tok,usize)>, __Nonterminal<'ast, >); match __lookahead { - Some((_, Tok::Minus(..), _)) => { + Some((_, Tok::Times(..), _)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __sym3 = __sym3.take().unwrap(); let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::RParen(..), _)) => { let __sym0 = __sym0.take().unwrap(); @@ -4224,31 +4368,7 @@ mod __parse__Expr { let __sym2 = __sym2.take().unwrap(); let __sym3 = __sym3.take().unwrap(); let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Plus(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Div(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some((_, Tok::Times(..), _)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __sym3 = __sym3.take().unwrap(); - let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } Some((_, Tok::Comma(..), _)) => { let __sym0 = __sym0.take().unwrap(); @@ -4256,7 +4376,31 @@ mod __parse__Expr { let __sym2 = __sym2.take().unwrap(); let __sym3 = __sym3.take().unwrap(); let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Plus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Minus(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); + } + Some((_, Tok::Div(..), _)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookbehind, __lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); diff --git a/lalrpop-test/src/sub.rs b/lalrpop-test/src/sub.rs index e24225a..820f4c7 100644 --- a/lalrpop-test/src/sub.rs +++ b/lalrpop-test/src/sub.rs @@ -10,8 +10,8 @@ pub fn parse_S< { let mut __tokens = __tokens.into_iter(); let __lookahead = __tokens.next(); - match try!(__parse__S::__state0(__lookahead, &mut __tokens)) { - (__lookahead, __parse__S::__Nonterminal::____S(__nt)) => Ok((__lookahead, __nt)), + match try!(__parse__S::__state0(None, __lookahead, &mut __tokens)) { + (_, __lookahead, __parse__S::__Nonterminal::____S(__nt)) => Ok((__lookahead, __nt)), _ => unreachable!(), } } @@ -22,10 +22,10 @@ mod __parse__S { use util::tok::Tok; pub enum __Nonterminal<> { - S(i32), - ____S(i32), - E(i32), T(i32), + S(i32), + E(i32), + ____S(i32), } // State 0 @@ -40,88 +40,95 @@ mod __parse__S { // T = (*) "Num" ["-"] // __S = (*) S [EOF] // - // "Num" -> Shift(S4) - // "(" -> Shift(S5) + // "(" -> Shift(S4) + // "Num" -> Shift(S5) // - // E -> S3 - // T -> S1 + // T -> S3 // S -> S2 + // E -> S1 pub fn __state0< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym0 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state4(__lookahead, __tokens, __sym0)); - } Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym0 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state5(__lookahead, __tokens, __sym0)); + __result = try!(__state4(__lookbehind, __lookahead, __tokens, __sym0)); + } + Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; + let mut __sym0 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(__lookbehind, __lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); } } loop { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { - __Nonterminal::E(__nt) => { - let __sym0 = &mut Some(__nt); - __result = try!(__state3(__lookahead, __tokens, __sym0)); - } __Nonterminal::T(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state1(__lookahead, __tokens, __sym0)); + __result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym0)); } __Nonterminal::S(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state2(__lookahead, __tokens, __sym0)); + __result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym0)); + } + __Nonterminal::E(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state1(__lookbehind, __lookahead, __tokens, __sym0)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } } // State 1 - // E = T (*) [EOF] - // E = T (*) ["-"] + // E = E (*) "-" T [EOF] + // E = E (*) "-" T ["-"] + // S = E (*) [EOF] // - // EOF -> Reduce(E = T => Call(ActionFn(3));) - // "-" -> Reduce(E = T => Call(ActionFn(3));) + // EOF -> Reduce(S = E => Call(ActionFn(1));) + // "-" -> Shift(S6) // pub fn __state1< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut __lookbehind = None; + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state6(__lookbehind, __lookahead, __tokens, __sym0, __sym1)); + } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); + let __nt = super::__actions::__action1(__sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::S(__nt))); } _ => { return Err(__lookahead); } } + return Ok(__result); } // State 2 @@ -132,17 +139,18 @@ mod __parse__S { pub fn __state2< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { None => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action0(__sym0); - return Ok((__lookahead, __Nonterminal::____S(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::____S(__nt))); } _ => { return Err(__lookahead); @@ -151,66 +159,32 @@ mod __parse__S { } // State 3 - // E = E (*) "-" T [EOF] - // E = E (*) "-" T ["-"] - // S = E (*) [EOF] + // E = T (*) [EOF] + // E = T (*) ["-"] // - // EOF -> Reduce(S = E => Call(ActionFn(1));) - // "-" -> Shift(S6) + // EOF -> Reduce(E = T => Call(ActionFn(3));) + // "-" -> Reduce(E = T => Call(ActionFn(3));) // pub fn __state3< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action1(__sym0); - return Ok((__lookahead, __Nonterminal::S(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 4 - // T = "Num" (*) [EOF] - // T = "Num" (*) ["-"] - // - // EOF -> Reduce(T = "Num" => Call(ActionFn(4));) - // "-" -> Reduce(T = "Num" => Call(ActionFn(4));) - // - pub fn __state4< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); + let __nt = super::__actions::__action3(__sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); + let __nt = super::__actions::__action3(__sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); } _ => { return Err(__lookahead); @@ -218,7 +192,7 @@ mod __parse__S { } } - // State 5 + // State 4 // E = (*) E "-" T [")"] // E = (*) E "-" T ["-"] // E = (*) T [")"] @@ -230,54 +204,91 @@ mod __parse__S { // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "(" -> Shift(S8) // "Num" -> Shift(S10) + // "(" -> Shift(S8) // // T -> S9 // E -> S7 - pub fn __state5< + pub fn __state4< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym1 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym1)); - } Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state10(__lookahead, __tokens, __sym1)); + __result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; + let mut __sym1 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state8(__lookbehind, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::T(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state9(__lookahead, __tokens, __sym1)); + __result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::E(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state7(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state7(__lookbehind, __lookahead, __tokens, __sym0, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } + // State 5 + // T = "Num" (*) [EOF] + // T = "Num" (*) ["-"] + // + // "-" -> Reduce(T = "Num" => Call(ActionFn(4));) + // EOF -> Reduce(T = "Num" => Call(ActionFn(4));) + // + pub fn __state5< + __TOKENS: Iterator, + >( + __lookbehind: Option<()>, + __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> + { + let mut __result: (Option<()>, Option, __Nonterminal<>); + match __lookahead { + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action4(__sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action4(__sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + // State 6 // E = E "-" (*) T [EOF] // E = E "-" (*) T ["-"] @@ -286,44 +297,47 @@ mod __parse__S { // T = (*) "Num" [EOF] // T = (*) "Num" ["-"] // - // "(" -> Shift(S5) - // "Num" -> Shift(S4) + // "(" -> Shift(S4) + // "Num" -> Shift(S5) // // T -> S11 pub fn __state6< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state5(__lookahead, __tokens, __sym2)); + __result = try!(__state4(__lookbehind, __lookahead, __tokens, __sym2)); } Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state4(__lookahead, __tokens, __sym2)); + __result = try!(__state5(__lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::T(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state11(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state11(__lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } @@ -336,29 +350,32 @@ mod __parse__S { // T = "(" E (*) ")" [EOF] // T = "(" E (*) ")" ["-"] // - // "-" -> Shift(S12) - // ")" -> Shift(S13) + // ")" -> Shift(S12) + // "-" -> Shift(S13) // pub fn __state7< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym1, __sym2)); - } Some(__tok @ Tok::RParen(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state13(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state12(__lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state13(__lookbehind, __lookahead, __tokens, __sym1, __sym2)); } _ => { return Err(__lookahead); @@ -387,40 +404,43 @@ mod __parse__S { pub fn __state8< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym1)); + __result = try!(__state8(__lookbehind, __lookahead, __tokens, __sym1)); } Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state10(__lookahead, __tokens, __sym1)); + __result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); } } while __sym0.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::T(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state9(__lookahead, __tokens, __sym1)); + __result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym1)); } __Nonterminal::E(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state14(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state14(__lookbehind, __lookahead, __tokens, __sym0, __sym1)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } @@ -437,22 +457,23 @@ mod __parse__S { pub fn __state9< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); } _ => { return Err(__lookahead); @@ -464,28 +485,29 @@ mod __parse__S { // T = "Num" (*) [")"] // T = "Num" (*) ["-"] // - // ")" -> Reduce(T = "Num" => Call(ActionFn(4));) // "-" -> Reduce(T = "Num" => Call(ActionFn(4));) + // ")" -> Reduce(T = "Num" => Call(ActionFn(4));) // pub fn __state10< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action4(__sym0); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); } _ => { return Err(__lookahead); @@ -503,28 +525,29 @@ mod __parse__S { pub fn __state11< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); } _ => { return Err(__lookahead); @@ -533,6 +556,46 @@ mod __parse__S { } // State 12 + // T = "(" E ")" (*) [EOF] + // T = "(" E ")" (*) ["-"] + // + // "-" -> Reduce(T = "(", E, ")" => Call(ActionFn(5));) + // EOF -> Reduce(T = "(", E, ")" => Call(ActionFn(5));) + // + pub fn __state12< + __TOKENS: Iterator, + >( + __lookbehind: Option<()>, + __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> + { + let mut __result: (Option<()>, Option, __Nonterminal<>); + match __lookahead { + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 13 // E = E "-" (*) T [")"] // E = E "-" (*) T ["-"] // T = (*) "(" E ")" [")"] @@ -544,114 +607,81 @@ mod __parse__S { // "(" -> Shift(S8) // // T -> S15 - pub fn __state12< + pub fn __state13< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { Some(Tok::Num(__tok0)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state10(__lookahead, __tokens, __sym2)); + __result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym2)); } Some(__tok @ Tok::LParen(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym2)); + __result = try!(__state8(__lookbehind, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); } } while __sym1.is_some() { - let (__lookahead, __nt) = __result; + let (__lookbehind, __lookahead, __nt) = __result; match __nt { __Nonterminal::T(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state15(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state15(__lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { - return Ok((__lookahead, __nt)); + return Ok((__lookbehind, __lookahead, __nt)); } } } return Ok(__result); } - // State 13 - // T = "(" E ")" (*) [EOF] - // T = "(" E ")" (*) ["-"] - // - // "-" -> Reduce(T = "(", E, ")" => Call(ActionFn(5));) - // EOF -> Reduce(T = "(", E, ")" => Call(ActionFn(5));) - // - pub fn __state13< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - // State 14 // E = E (*) "-" T [")"] // E = E (*) "-" T ["-"] // T = "(" E (*) ")" [")"] // T = "(" E (*) ")" ["-"] // - // "-" -> Shift(S12) // ")" -> Shift(S16) + // "-" -> Shift(S13) // pub fn __state14< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some((__tok)); - let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym1, __sym2)); - } Some(__tok @ Tok::RParen(..)) => { + let mut __lookbehind = None; let mut __sym2 = &mut Some((__tok)); let __lookahead = __tokens.next(); - __result = try!(__state16(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state16(__lookbehind, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __lookbehind = None; + let mut __sym2 = &mut Some((__tok)); + let __lookahead = __tokens.next(); + __result = try!(__state13(__lookbehind, __lookahead, __tokens, __sym1, __sym2)); } _ => { return Err(__lookahead); @@ -664,34 +694,35 @@ mod __parse__S { // E = E "-" T (*) [")"] // E = E "-" T (*) ["-"] // - // "-" -> Reduce(E = E, "-", T => Call(ActionFn(2));) // ")" -> Reduce(E = E, "-", T => Call(ActionFn(2));) + // "-" -> Reduce(E = E, "-", T => Call(ActionFn(2));) // pub fn __state15< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt))); } _ => { return Err(__lookahead); @@ -703,34 +734,35 @@ mod __parse__S { // T = "(" E ")" (*) [")"] // T = "(" E ")" (*) ["-"] // - // "-" -> Reduce(T = "(", E, ")" => Call(ActionFn(5));) // ")" -> Reduce(T = "(", E, ")" => Call(ActionFn(5));) + // "-" -> Reduce(T = "(", E, ")" => Call(ActionFn(5));) // pub fn __state16< __TOKENS: Iterator, >( - mut __lookahead: Option, + __lookbehind: Option<()>, + __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> + ) -> Result<(Option<()>, Option, __Nonterminal<>), Option> { - let mut __result: (Option, __Nonterminal<>); + let mut __result: (Option<()>, Option, __Nonterminal<>); match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::T(__nt))); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); + return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt))); } _ => { return Err(__lookahead); diff --git a/lalrpop/src/grammar/parse_tree.rs b/lalrpop/src/grammar/parse_tree.rs index db4cd08..8c631d7 100644 --- a/lalrpop/src/grammar/parse_tree.rs +++ b/lalrpop/src/grammar/parse_tree.rs @@ -33,6 +33,7 @@ pub enum GrammarItem { #[derive(Clone, Debug, PartialEq, Eq)] pub struct ExternToken { + pub span: Span, pub associated_types: Vec, pub enum_token: EnumToken, } @@ -127,7 +128,14 @@ pub struct Alternative { pub condition: Option, // => { code } - pub action: Option, + pub action: Option, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum ActionKind { + User(String), + Lookahead, + Lookbehind, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -181,6 +189,12 @@ pub enum SymbolKind { // x:X Name(InternedString, Box), + + // @< + Lookahead, + + // @> + Lookbehind, } #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] @@ -307,6 +321,10 @@ impl Display for SymbolKind { write!(fmt, "<{}>", s), SymbolKind::Name(n, ref s) => write!(fmt, "{}:{}", n, s), + SymbolKind::Lookahead => + write!(fmt, "$<"), + SymbolKind::Lookbehind => + write!(fmt, "$>"), } } } @@ -468,3 +486,12 @@ impl Path { } } } + +impl ActionKind { + pub fn as_user(&self) -> Option<&String> { + match *self { + ActionKind::User(ref s) => Some(s), + _ => None + } + } +} diff --git a/lalrpop/src/grammar/repr.rs b/lalrpop/src/grammar/repr.rs index 1f36fb6..ab0f7db 100644 --- a/lalrpop/src/grammar/repr.rs +++ b/lalrpop/src/grammar/repr.rs @@ -60,7 +60,7 @@ pub struct Production { // handy to have it pub nonterminal: NonterminalString, pub symbols: Vec, - pub action: ProductionAction, + pub action: ActionKind, pub span: Span, } @@ -71,9 +71,11 @@ pub enum Symbol { } #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub enum ProductionAction { +pub enum ActionKind { // execute code provided by the user Call(ActionFn), + Lookahead, + Lookbehind, } #[derive(Clone, PartialEq, Eq)] diff --git a/lalrpop/src/lr1/ascent.rs b/lalrpop/src/lr1/ascent.rs index 5bf1b43..cc0459c 100644 --- a/lalrpop/src/lr1/ascent.rs +++ b/lalrpop/src/lr1/ascent.rs @@ -2,7 +2,7 @@ //! //! [recursive ascent]: https://en.wikipedia.org/wiki/Recursive_ascent_parser -use grammar::repr::{Grammar, NonterminalString, ProductionAction, Symbol, TerminalString, Types}; +use grammar::repr::{ActionKind, Grammar, NonterminalString, Symbol, TerminalString, Types}; use lr1::{Lookahead, State, StateIndex}; use rust::RustWrite; use std::io::{self, Write}; @@ -117,10 +117,10 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { rust!(self.out, "{{"); rust!(self.out, "let mut {}tokens = {}tokens.into_iter();", self.prefix, self.prefix); rust!(self.out, "let {}lookahead = {}tokens.next();", self.prefix, self.prefix); - rust!(self.out, "match try!({}parse{}::{}state0({}{}lookahead, &mut {}tokens)) {{", + rust!(self.out, "match try!({}parse{}::{}state0({}None, {}lookahead, &mut {}tokens)) {{", self.prefix, self.start_symbol, self.prefix, self.grammar.user_parameter_refs(), self.prefix, self.prefix); - rust!(self.out, "({}lookahead, {}parse{}::{}Nonterminal::{}({}nt)) => \ + rust!(self.out, "(_, {}lookahead, {}parse{}::{}Nonterminal::{}({}nt)) => \ Ok(({}lookahead, {}nt)),", self.prefix, self.prefix, self.start_symbol, self.prefix, Escape(self.start_symbol), self.prefix, self.prefix, self.prefix); @@ -134,6 +134,10 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { fn write_state_fn(&mut self, this_index: StateIndex) -> io::Result<()> { let this_state = &self.states[this_index.0]; let this_prefix = self.state_prefixes[this_index.0]; + let loc_type = match self.types.opt_terminal_loc_type() { + Some(t) => format!("{}", t), + None => format!("()"), + }; let item_type = self.iterator_item_type(); // Leave a comment explaining what this state is. @@ -154,7 +158,8 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { let mut fallthrough = false; let base_args = - vec![format!("mut {}lookahead: Option<{}>", self.prefix, item_type), + vec![format!("{}lookbehind: Option<{}>", self.prefix, loc_type), + format!("{}lookahead: Option<{}>", self.prefix, item_type), format!("{}tokens: &mut {}TOKENS", self.prefix, self.prefix)]; let sym_args: Vec<_> = (0..this_prefix.len()) @@ -167,15 +172,17 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { format!("{}state{}", self.prefix, this_index.0), vec![format!("{}TOKENS: Iterator", self.prefix, item_type)], base_args.into_iter().chain(sym_args).collect(), - format!("Result<(Option<{}>, {}Nonterminal<{}>), Option<{}>>", + format!("Result<(Option<{}>, Option<{}>, {}Nonterminal<{}>), Option<{}>>", + loc_type, item_type, self.prefix, self.grammar.user_type_parameter_refs(), item_type), vec![])); rust!(self.out, "{{"); - rust!(self.out, "let mut {}result: (Option<{}>, {}Nonterminal<{}>);", - self.prefix, item_type, self.prefix, self.grammar.user_type_parameter_refs()); + rust!(self.out, "let mut {}result: (Option<{}>, Option<{}>, {}Nonterminal<{}>);", + self.prefix, loc_type, item_type, self.prefix, + self.grammar.user_type_parameter_refs()); rust!(self.out, "match {}lookahead {{", self.prefix); @@ -187,7 +194,8 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { match *token { Lookahead::Terminal(s) => { let sym_name = format!("{}sym{}", self.prefix, this_prefix.len()); - try!(self.consume_terminal(s, sym_name)) + let lb_name = format!("{}lookbehind", self.prefix); + try!(self.consume_terminal(s, sym_name, lb_name)); } Lookahead::EOF => unreachable!("should never have to shift EOF") @@ -199,7 +207,7 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { // transition to the new state let transition = - self.transition(this_prefix, next_index, "lookahead", "tokens"); + self.transition(this_prefix, next_index, "lookbehind", "lookahead", "tokens"); rust!(self.out, "{}result = {};", self.prefix, transition); rust!(self.out, "}}"); @@ -230,25 +238,41 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { // invoke the action code match production.action { - ProductionAction::Call(action_fn) => + ActionKind::Call(action_fn) => { rust!(self.out, "let {}nt = super::{}actions::{}action{}({}{});", self.prefix, self.prefix, self.prefix, action_fn.index(), self.grammar.user_parameter_refs(), - Sep(", ", &transfer_syms)), + Sep(", ", &transfer_syms)) + } + + ActionKind::Lookahead => { + debug_assert!(self.types.opt_terminal_loc_type().is_some()); + rust!(self.out, + "let {}nt = ::std::clone::Clone(&{}lookahead.map(|o| o.0));", + self.prefix, self.prefix); + } + + ActionKind::Lookbehind => { + debug_assert!(self.types.opt_terminal_loc_type().is_some()); + rust!(self.out, + "let {}nt = ::std::clone::Clone(&{}lookbehind);", + self.prefix, self.prefix); + } } // wrap up the result along with the (unused) lookahead if !transfer_syms.is_empty() { // if we popped anything off of the stack, then this frame is done - rust!(self.out, "return Ok(({}lookahead, {}Nonterminal::{}({}nt)));", - self.prefix, self.prefix, Escape(production.nonterminal), self.prefix); + rust!(self.out, "return Ok(({}lookbehind, {}lookahead, {}Nonterminal::{}({}nt)));", + self.prefix, self.prefix, self.prefix, + Escape(production.nonterminal), self.prefix); } else { // otherwise, pop back - rust!(self.out, "{}result = ({}lookahead, {}Nonterminal::{}({}nt));", - self.prefix, self.prefix, self.prefix, + rust!(self.out, "{}result = ({}lookbehind, {}lookahead, {}Nonterminal::{}({}nt));", + self.prefix, self.prefix, self.prefix, self.prefix, Escape(production.nonterminal), self.prefix); fallthrough = true; } @@ -271,8 +295,8 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { rust!(self.out, "loop {{"); } - rust!(self.out, "let ({}lookahead, {}nt) = {}result;", - self.prefix, self.prefix, self.prefix); + rust!(self.out, "let ({}lookbehind, {}lookahead, {}nt) = {}result;", + self.prefix, self.prefix, self.prefix, self.prefix); rust!(self.out, "match {}nt {{", self.prefix); for (&nt, &next_index) in &this_state.gotos { @@ -280,7 +304,8 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { self.prefix, Escape(nt), self.prefix); rust!(self.out, "let {}sym{} = &mut Some({}nt);", self.prefix, this_prefix.len(), self.prefix); - let transition = self.transition(this_prefix, next_index, "lookahead", "tokens"); + let transition = self.transition(this_prefix, next_index, + "lookbehind", "lookahead", "tokens"); rust!(self.out, "{}result = {};", self.prefix, transition); rust!(self.out, "}}"); } @@ -289,7 +314,8 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { // indicates parse successfully completed, so just bail out if this_state.gotos.len() != self.grammar.productions.keys().len() { rust!(self.out, "_ => {{"); - rust!(self.out, "return Ok(({}lookahead, {}nt));", self.prefix, self.prefix); + rust!(self.out, "return Ok(({}lookbehind, {}lookahead, {}nt));", + self.prefix, self.prefix, self.prefix); rust!(self.out, "}}"); } @@ -316,6 +342,7 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { fn transition(&self, prefix: &[Symbol], next_index: StateIndex, + lookbehind: &str, lookahead: &str, tokens: &str) -> String @@ -332,9 +359,10 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { let transfer_syms = self.pop_syms(n, m); // invoke next state, transferring the top `m` tokens - format!("try!({}state{}({}{}{}, {}{}, {}))", + format!("try!({}state{}({}{}{}, {}{}, {}{}, {}))", self.prefix, next_index.0, self.grammar.user_parameter_refs(), + self.prefix, lookbehind, self.prefix, lookahead, self.prefix, tokens, Sep(", ", &transfer_syms)) @@ -356,7 +384,11 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { /// Emit a pattern that matches `id` and extracts its value, storing /// that value as `let_name`. - fn consume_terminal(&mut self, id: TerminalString, let_name: String) -> io::Result<()> { + fn consume_terminal(&mut self, + id: TerminalString, + let_name: String, + lb_name: String) + -> io::Result<()> { let mut pattern_names = vec![]; let pattern = self.grammar.pattern(id).map(&mut |_| { let index = pattern_names.len(); @@ -370,10 +402,18 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { pattern = format!("{}tok @ {}", self.prefix, pattern); } if self.types.opt_terminal_loc_type().is_some() { - pattern = format!("(_, {}, _)", pattern); + pattern = format!("(_, {}, {}loc)", pattern, self.prefix); } rust!(self.out, "Some({}) => {{", pattern); + + if self.types.opt_terminal_loc_type().is_some() { + rust!(self.out, "let mut {} = Some({}loc);", + lb_name, self.prefix); + } else { + rust!(self.out, "let mut {} = None;", lb_name); + } + rust!(self.out, "let mut {} = &mut Some(({}));", let_name, pattern_names.connect(", ")); diff --git a/lalrpop/src/normalize/lower/mod.rs b/lalrpop/src/normalize/lower/mod.rs index c16638b..7c72452 100644 --- a/lalrpop/src/normalize/lower/mod.rs +++ b/lalrpop/src/normalize/lower/mod.rs @@ -64,12 +64,12 @@ impl LowerState { for alt in nt.alternatives { let nt_type = self.types.nonterminal_type(nt.name).clone(); let symbols = self.symbols(&alt.expr.symbols); - let action_fn = self.action_fn(nt_type, &alt.expr, &symbols, alt.action); + let action = self.action_kind(nt_type, &alt.expr, &symbols, alt.action); let production = r::Production { nonterminal: nt.name, span: alt.span, symbols: symbols, - action: r::ProductionAction::Call(action_fn), + action: action, }; self.productions.push(production); } @@ -129,7 +129,7 @@ impl LowerState { self.productions.push(r::Production { nonterminal: fake_name, symbols: symbols, - action: r::ProductionAction::Call(action_fn), + action: r::ActionKind::Call(action_fn), span: nt.span }); (nt.name, fake_name) @@ -137,6 +137,29 @@ impl LowerState { .collect() } + fn action_kind(&mut self, + nt_type: r::TypeRepr, + expr: &pt::ExprSymbol, + symbols: &[r::Symbol], + action: Option) + -> r::ActionKind + { + match action { + Some(pt::ActionKind::Lookahead) => + r::ActionKind::Lookahead, + Some(pt::ActionKind::Lookbehind) => + r::ActionKind::Lookbehind, + Some(pt::ActionKind::User(string)) => { + let action_fn = self.action_fn(nt_type, &expr, &symbols, Some(string)); + r::ActionKind::Call(action_fn) + } + None => { + let action_fn = self.action_fn(nt_type, &expr, &symbols, None); + r::ActionKind::Call(action_fn) + } + } + } + fn action_fn(&mut self, nt_type: r::TypeRepr, expr: &pt::ExprSymbol, @@ -209,7 +232,11 @@ impl LowerState { pt::SymbolKind::Nonterminal(id) => r::Symbol::Nonterminal(id), pt::SymbolKind::Choose(ref s) | pt::SymbolKind::Name(_, ref s) => self.symbol(s), - pt::SymbolKind::Macro(..) | pt::SymbolKind::Repeat(..) | pt::SymbolKind::Expr(..) => { + pt::SymbolKind::Macro(..) | + pt::SymbolKind::Repeat(..) | + pt::SymbolKind::Expr(..) | + pt::SymbolKind::Lookahead | + pt::SymbolKind::Lookbehind => { unreachable!("symbol `{}` should have been normalized away by now", symbol) } } @@ -259,6 +286,7 @@ fn find_prefix(grammar: &pt::Grammar) -> String { .filter_map(|i| i.as_nonterminal()) .flat_map(|nt| nt.alternatives.iter()) .filter_map(|alt| alt.action.as_ref()) + .filter_map(|action| action.as_user()) .any(|s| s.contains(&prefix)) || grammar.items @@ -271,3 +299,4 @@ fn find_prefix(grammar: &pt::Grammar) -> String { prefix } + diff --git a/lalrpop/src/normalize/macro_expand/mod.rs b/lalrpop/src/normalize/macro_expand/mod.rs index c4f1f3a..6f2da9c 100644 --- a/lalrpop/src/normalize/macro_expand/mod.rs +++ b/lalrpop/src/normalize/macro_expand/mod.rs @@ -1,6 +1,6 @@ use std::collections::{HashMap, HashSet}; use intern::{intern, read, InternedString}; -use grammar::parse_tree::{Alternative, +use grammar::parse_tree::{ActionKind, Alternative, Condition, ConditionOp, ExprSymbol, Grammar, GrammarItem, @@ -77,6 +77,10 @@ impl MacroExpander { items.push(try!(self.expand_expr_symbol(sym.span, expr))), SymbolKind::Repeat(repeat) => items.push(try!(self.expand_repeat_symbol(sym.span, *repeat))), + SymbolKind::Lookahead => + items.push(try!(self.expand_lookahead_symbol(sym.span))), + SymbolKind::Lookbehind => + items.push(try!(self.expand_lookbehind_symbol(sym.span))), _ => assert!(false, "don't know how to expand `{:?}`", sym) } @@ -128,6 +132,8 @@ impl MacroExpander { self.replace_symbol(sym); return; } + SymbolKind::Lookahead | SymbolKind::Lookbehind => { + } } // only symbols we intend to expand fallthrough to here @@ -307,6 +313,10 @@ impl MacroExpander { SymbolKind::Choose(Box::new(self.macro_expand_symbol(args, sym))), SymbolKind::Name(id, ref sym) => SymbolKind::Name(id, Box::new(self.macro_expand_symbol(args, sym))), + SymbolKind::Lookahead => + SymbolKind::Lookahead, + SymbolKind::Lookbehind => + SymbolKind::Lookbehind, }; Symbol { span: symbol.span, kind: kind } @@ -343,7 +353,7 @@ impl MacroExpander { alternatives: vec![Alternative { span: span, expr: expr, condition: None, - action: Some(format!("(<>)")) }] + action: action("(<>)") }] })) } @@ -374,7 +384,7 @@ impl MacroExpander { span: span, expr: ExprSymbol { symbols: vec![] }, condition: None, - action: Some(format!("vec![]")) + action: action("vec![]") }, // X* = @@ -396,7 +406,7 @@ impl MacroExpander { Box::new(repeat.symbol.clone())))] }, condition: None, - action: Some(format!("{{ let mut v = v; v.push(e); v }}")) + action: action("{ let mut v = v; v.push(e); v }") }], })) } @@ -419,7 +429,7 @@ impl MacroExpander { symbols: vec![repeat.symbol.clone()] }, condition: None, - action: Some(format!("vec![<>]")) + action: action("Vec![<>]"), }, // X+ = @@ -434,7 +444,7 @@ impl MacroExpander { e, Box::new(repeat.symbol.clone())))] }, condition: None, - action: Some(format!("{{ let mut v = v; v.push(e); v }}")) + action: action("{ let mut v = v; v.push(e); v }"), }], })) } @@ -456,7 +466,7 @@ impl MacroExpander { symbols: vec![repeat.symbol.clone()] }, condition: None, - action: Some(format!("Some(<>)")) }, + action: action("Some(<>)") }, // X? = { => None; } Alternative { span: span, @@ -464,11 +474,19 @@ impl MacroExpander { symbols: vec![] }, condition: None, - action: Some(format!("None")) }] + action: action("None") }] })) } } } + + fn expand_lookahead_symbol(&mut self, _span: Span) -> NormResult { + panic!("not yet implemented") + } + + fn expand_lookbehind_symbol(&mut self, _span: Span) -> NormResult { + panic!("not yet implemented") + } } fn maybe_tuple(v: Vec) -> TypeRef { @@ -478,3 +496,7 @@ fn maybe_tuple(v: Vec) -> TypeRef { TypeRef::Tuple(v) } } + +fn action(s: &str) -> Option { + Some(ActionKind::User(s.to_string())) +} diff --git a/lalrpop/src/normalize/norm_util.rs b/lalrpop/src/normalize/norm_util.rs index c166cd3..70d443d 100644 --- a/lalrpop/src/normalize/norm_util.rs +++ b/lalrpop/src/normalize/norm_util.rs @@ -1,9 +1,9 @@ use intern::InternedString; -use grammar::parse_tree::{Alternative, ExprSymbol, Symbol, SymbolKind}; +use grammar::parse_tree::{ActionKind, Alternative, ExprSymbol, Symbol, SymbolKind}; #[derive(Debug)] pub enum AlternativeAction<'a> { - User(&'a str), + User(&'a ActionKind), Default(Symbols<'a>), } diff --git a/lalrpop/src/normalize/tyinfer/mod.rs b/lalrpop/src/normalize/tyinfer/mod.rs index 0fc9f0f..6ddc0e7 100644 --- a/lalrpop/src/normalize/tyinfer/mod.rs +++ b/lalrpop/src/normalize/tyinfer/mod.rs @@ -252,7 +252,8 @@ impl<'grammar> TypeInferencer<'grammar> { SymbolKind::Choose(ref s) => self.symbol_type(&s.kind), SymbolKind::Name(_, ref s) => self.symbol_type(&s.kind), - SymbolKind::Repeat(..) | SymbolKind::Expr(..) | SymbolKind::Macro(..) => { + SymbolKind::Repeat(..) | SymbolKind::Expr(..) | SymbolKind::Macro(..) | + SymbolKind::Lookahead | SymbolKind::Lookbehind => { unreachable!("symbol `{:?}` should have been expanded away", symbol) } } diff --git a/lalrpop/src/normalize/validate/mod.rs b/lalrpop/src/normalize/validate/mod.rs index ac90f5a..65df0ca 100644 --- a/lalrpop/src/normalize/validate/mod.rs +++ b/lalrpop/src/normalize/validate/mod.rs @@ -25,6 +25,12 @@ pub fn validate(grammar: &Grammar) -> NormResult<()> { .collect() }; + let extern_token: Option<&ExternToken> = + grammar.items + .iter() + .filter_map(|item| item.as_extern_token()) + .next(); + let conversions: Set<_> = grammar.items .iter() @@ -35,6 +41,7 @@ pub fn validate(grammar: &Grammar) -> NormResult<()> { let validator = Validator { grammar: grammar, globals: globals, + extern_token: extern_token, conversions: conversions, }; @@ -43,6 +50,7 @@ pub fn validate(grammar: &Grammar) -> NormResult<()> { struct Validator<'grammar> { grammar: &'grammar Grammar, + extern_token: Option<&'grammar ExternToken>, globals: ScopeChain<'grammar>, conversions: Set, } @@ -65,6 +73,12 @@ impl<'grammar> Validator<'grammar> { match *item { GrammarItem::Use(..) => { } GrammarItem::ExternToken(ref data) => { + if data.span != self.extern_token.unwrap().span { + return_err!( + data.span, + "multiple extern token definitions are not permitted"); + } + let allowed_names = vec![intern(LOCATION)]; let mut new_names = set(); for associated_type in &data.associated_types { @@ -238,6 +252,23 @@ impl<'grammar> Validator<'grammar> { SymbolKind::Choose(ref sym) | SymbolKind::Name(_, ref sym) => { try!(self.validate_symbol(scope, sym)); } + SymbolKind::Lookahead | SymbolKind::Lookbehind => { + if self.extern_token.is_none() { + return_err!(symbol.span, + "lookahead/lookbehind not permitted without \ + an extern token declaration"); + } + + let loc = intern(LOCATION); + if self.extern_token.unwrap().associated_type(loc).is_none() { + return_err!( + symbol.span, + "lookahead/lookbehind require you to declare the type of \ + a location; add a `type {} = ..` statement to the extern token \ + block", + LOCATION); + } + } } Ok(()) diff --git a/lalrpop/src/normalize/validate/test.rs b/lalrpop/src/normalize/validate/test.rs index 6d809b5..2325da6 100644 --- a/lalrpop/src/normalize/validate/test.rs +++ b/lalrpop/src/normalize/validate/test.rs @@ -9,7 +9,7 @@ fn check_err(expected_err: &str, grammar: &str) { // indicate the span where an error is expected. let start_index = grammar.find(">>>").unwrap(); let grammar = grammar.replace(">>>", ""); // remove the `>>>` marker - let end_index = grammar.find("<<<").unwrap(); + let end_index = grammar.rfind("<<<").unwrap(); let grammar = grammar.replace("<<<", ""); assert!(start_index <= end_index); @@ -71,3 +71,17 @@ fn dup_assoc_type() { type >>>Location <<<= u32; enum Tok { } }"#); } + +#[test] +fn lookahead_without_loc_type() { + check_err( + r#"lookahead/lookbehind require you to declare the type of a location"#, + r#"grammar; extern token { enum Tok { } } Foo = >>>@<<<<;"#); +} + +#[test] +fn multiple_extern_token() { + check_err( + r#"multiple extern token definitions are not permitted"#, + r#"grammar; extern token { enum Tok { } } >>>extern token <<<{ enum Tok { } }"#); +} diff --git a/lalrpop/src/parser/mod.rs b/lalrpop/src/parser/mod.rs index ab69339..26f6672 100644 --- a/lalrpop/src/parser/mod.rs +++ b/lalrpop/src/parser/mod.rs @@ -110,7 +110,16 @@ rusty_peg! { IF_COND: Condition = ("if" ) => c; - ACTION: String = ("=>" ) => b; + ACTION: ActionKind = (LOOKAHEAD_ACTION / LOOKBEHIND_ACTION / USER_ACTION); + + USER_ACTION: ActionKind = + ("=>" ) => ActionKind::User(b); + + LOOKAHEAD_ACTION: ActionKind = + ("=>@<") => ActionKind::Lookahead; + + LOOKBEHIND_ACTION: ActionKind = + ("=>@>") => ActionKind::Lookbehind; // Conditions @@ -154,7 +163,8 @@ rusty_peg! { REPEAT_OP_QUESTION: RepeatOp = "?" => RepeatOp::Question; SYMBOL1: Symbol = - (MACRO_SYMBOL / TERMINAL_SYMBOL / NT_SYMBOL / ESCAPE_SYMBOL / PAREN_SYMBOL); + (MACRO_SYMBOL / TERMINAL_SYMBOL / NT_SYMBOL / ESCAPE_SYMBOL / PAREN_SYMBOL/ + LOOKAHEAD_SYMBOL / LOOKBEHIND_SYMBOL); MACRO_SYMBOL: Symbol = ( ">" ) => { @@ -183,6 +193,16 @@ rusty_peg! { Symbol::new(Span(lo, hi), SymbolKind::Expr(s)) }; + LOOKAHEAD_SYMBOL: Symbol = + ( "@<" ) => { + Symbol::new(Span(lo, hi), SymbolKind::Lookahead) + }; + + LOOKBEHIND_SYMBOL: Symbol = + ( "@>" ) => { + Symbol::new(Span(lo, hi), SymbolKind::Lookbehind) + }; + EXPR_SYMBOL: ExprSymbol = () => ExprSymbol { symbols: s }; @@ -247,7 +267,7 @@ rusty_peg! { // TOKEN DEFINITIONS EXTERN_TOKEN: GrammarItem = - ("extern" "token" "{" + ( "extern" "token" "{" "enum" "{" @@ -255,6 +275,7 @@ rusty_peg! { "}") => { GrammarItem::ExternToken(ExternToken { + span: Span(lo0, hi0), associated_types: a0.into_iter().chain(a1).collect(), enum_token: EnumToken { type_name: t, diff --git a/lalrpop/src/parser/test.rs b/lalrpop/src/parser/test.rs index 080bcdd..36d3bd7 100644 --- a/lalrpop/src/parser/test.rs +++ b/lalrpop/src/parser/test.rs @@ -124,6 +124,12 @@ fn macro_symbols() { assert!(super::parse_symbol(r#"Foo "#).is_err()); } +#[test] +fn lookaround() { + super::parse_symbol(r#"@<"#).unwrap(); + super::parse_symbol(r#"@>"#).unwrap(); +} + #[test] fn symbol_precedence() { // check that we parse this as choosing a X+