From bfe72e14fc86843b9062cb2b64ce0dea1c9a37f7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 15 Jul 2015 06:21:43 -0400 Subject: [PATCH] Misc changes to make the expr-arena-ast test case work (threading through type parameters etc) --- lalrpop-test/src/expr.lalrpop | 6 +- lalrpop-test/src/expr.rs | 2784 +++++++++++---------- lalrpop-test/src/expr_arena.lalrpop | 33 + lalrpop-test/src/expr_arena.rs | 2203 ++++++++++++++++ lalrpop-test/src/expr_arena_ast.rs | 29 + lalrpop-test/src/main.rs | 31 +- lalrpop-test/src/sub.rs | 628 ++--- lalrpop-test/src/util/mod.rs | 48 +- lalrpop/src/build/mod.rs | 14 +- lalrpop/src/grammar/parse_tree.rs | 20 +- lalrpop/src/grammar/repr.rs | 33 + lalrpop/src/lr1/ascent.rs | 26 +- lalrpop/src/normalize/macro_expand/mod.rs | 4 + lalrpop/src/normalize/tyinfer/mod.rs | 5 + lalrpop/src/parser/mod.rs | 16 +- lalrpop/src/rust/mod.rs | 13 - 16 files changed, 4158 insertions(+), 1735 deletions(-) create mode 100644 lalrpop-test/src/expr_arena.lalrpop create mode 100644 lalrpop-test/src/expr_arena.rs create mode 100644 lalrpop-test/src/expr_arena_ast.rs diff --git a/lalrpop-test/src/expr.lalrpop b/lalrpop-test/src/expr.lalrpop index 55b46e1..2b59ad0 100644 --- a/lalrpop-test/src/expr.lalrpop +++ b/lalrpop-test/src/expr.lalrpop @@ -1,4 +1,4 @@ -grammar; +grammar(scale: i32); use util::tok::Tok; @@ -26,7 +26,7 @@ Factor = { Term; }; -Term = { - <"Num">; +Term: i32 = { + => n * scale; "(" ")"; }; diff --git a/lalrpop-test/src/expr.rs b/lalrpop-test/src/expr.rs index d535258..a47b8cb 100644 --- a/lalrpop-test/src/expr.rs +++ b/lalrpop-test/src/expr.rs @@ -4,12 +4,13 @@ use util::tok::Tok; pub fn parse_Expr< __TOKENS: IntoIterator, >( + scale: i32, __tokens: __TOKENS, ) -> Result<(Option, i32), Option> { let mut __tokens = __tokens.into_iter(); let __lookahead = __tokens.next(); - match try!(__parse__Expr::__state0(__lookahead, &mut __tokens)) { + match try!(__parse__Expr::__state0(scale, __lookahead, &mut __tokens)) { (__lookahead, __parse__Expr::__Nonterminal::__Expr(__nt)) => Ok((__lookahead, __nt)), _ => unreachable!(), } @@ -20,10 +21,10 @@ mod __parse__Expr { use util::tok::Tok; - pub enum __Nonterminal { + pub enum __Nonterminal<> { + __Expr(i32), Expr(i32), Factor(i32), - __Expr(i32), Term(i32), } @@ -64,29 +65,31 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // __Expr = (*) Expr [EOF] // - // "Num" -> Shift(S5) - // "(" -> Shift(S1) + // "(" -> Shift(S5) + // "Num" -> Shift(S3) // - // Factor -> S2 - // Expr -> S3 - // Term -> S4 + // Term -> S2 + // Factor -> S4 + // Expr -> S1 pub fn __state0< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym0 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state5(__lookahead, __tokens, __sym0)); - } Some(__tok @ Tok::LParen(..)) => { let mut __sym0 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state1(__lookahead, __tokens, __sym0)); + __result = try!(__state5(scale, __lookahead, __tokens, __sym0)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym0 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(scale, __lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); @@ -95,17 +98,17 @@ mod __parse__Expr { loop { let (__lookahead, __nt) = __result; match __nt { + __Nonterminal::Term(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state2(scale, __lookahead, __tokens, __sym0)); + } __Nonterminal::Factor(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state2(__lookahead, __tokens, __sym0)); + __result = try!(__state4(scale, __lookahead, __tokens, __sym0)); } __Nonterminal::Expr(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state3(__lookahead, __tokens, __sym0)); - } - __Nonterminal::Term(__nt) => { - let __sym0 = &mut Some(__nt); - __result = try!(__state4(__lookahead, __tokens, __sym0)); + __result = try!(__state1(scale, __lookahead, __tokens, __sym0)); } _ => { return Ok((__lookahead, __nt)); @@ -115,6 +118,226 @@ mod __parse__Expr { } // 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) + // "+" -> Shift(S7) + // EOF -> Reduce(__Expr = Expr => ActionFn(0);) + // + pub fn __state1< + __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 @ Tok::Minus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state6(scale, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state7(scale, __lookahead, __tokens, __sym0, __sym1)); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action0(scale, __sym0); + return Ok((__lookahead, __Nonterminal::__Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 2 + // Factor = Term (*) [EOF] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // EOF -> Reduce(Factor = Term => ActionFn(6);) + // "+" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) + // "/" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // + 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::__action6(scale, __sym0); + return Ok((__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))); + } + 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::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 3 + // Term = "Num" (*) [EOF] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // EOF -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // + pub fn __state3< + __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::Minus(..)) => { + 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::Div(..)) => { + 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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 4 + // Expr = Factor (*) [EOF] + // Expr = Factor (*) ["+"] + // 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) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S8) + // EOF -> Reduce(Expr = Factor => ActionFn(3);) + // + pub fn __state4< + __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 @ Tok::Div(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state9(scale, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(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))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 5 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -155,30 +378,32 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S8) - // "Num" -> Shift(S6) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) // - // Term -> S10 - // Expr -> S7 - // Factor -> S9 - pub fn __state1< + // Term -> S11 + // Factor -> S14 + // Expr -> S13 + pub fn __state5< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (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 __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym1)); + __result = try!(__state10(scale, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(scale, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); @@ -189,15 +414,15 @@ mod __parse__Expr { match __nt { __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state10(__lookahead, __tokens, __sym1)); - } - __Nonterminal::Expr(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state7(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state11(scale, __lookahead, __tokens, __sym1)); } __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state9(__lookahead, __tokens, __sym1)); + __result = try!(__state14(scale, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state13(scale, __lookahead, __tokens, __sym0, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -207,321 +432,401 @@ mod __parse__Expr { return Ok(__result); } - // State 2 - // Expr = Factor (*) [EOF] - // Expr = Factor (*) ["+"] - // 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 = Factor => ActionFn(3);) - // "-" -> Reduce(Expr = Factor => ActionFn(3);) - // "+" -> Reduce(Expr = Factor => ActionFn(3);) - // "*" -> Shift(S12) - // "/" -> Shift(S11) - // - pub fn __state2< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym0, __sym1)); - } - Some(__tok @ Tok::Div(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state11(__lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // 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] - // - // EOF -> Reduce(__Expr = Expr => ActionFn(0);) - // "-" -> Shift(S13) - // "+" -> Shift(S14) - // - pub fn __state3< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(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!(__state13(__lookahead, __tokens, __sym0, __sym1)); - } - Some(__tok @ Tok::Plus(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state14(__lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action0(__sym0); - return Ok((__lookahead, __Nonterminal::__Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 4 - // Factor = Term (*) [EOF] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] - // - // "*" -> Reduce(Factor = Term => ActionFn(6);) - // "/" -> Reduce(Factor = Term => ActionFn(6);) - // "+" -> Reduce(Factor = Term => ActionFn(6);) - // "-" -> Reduce(Factor = Term => ActionFn(6);) - // EOF -> Reduce(Factor = Term => ActionFn(6);) - // - pub fn __state4< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 5 - // Term = "Num" (*) [EOF] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] - // - // EOF -> Reduce(Term = "Num" => ActionFn(7);) - // "+" -> Reduce(Term = "Num" => ActionFn(7);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // "-" -> Reduce(Term = "Num" => ActionFn(7);) - // "*" -> Reduce(Term = "Num" => ActionFn(7);) - // - pub fn __state5< - __TOKENS: Iterator, - >( - 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::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - // State 6 - // 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 ["/"] + // 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(Term = "Num" => ActionFn(7);) - // ")" -> Reduce(Term = "Num" => ActionFn(7);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // "-" -> Reduce(Term = "Num" => ActionFn(7);) - // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // "Num" -> Shift(S3) + // "(" -> Shift(S5) // + // Factor -> S15 + // Term -> S2 pub fn __state6< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(scale, __lookahead, __tokens, __sym2)); } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state5(scale, __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!(__state15(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state2(scale, __lookahead, __tokens, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); } // State 7 - // 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 (*) ")" ["/"] + // 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" ["/"] // - // "+" -> Shift(S15) - // ")" -> Shift(S16) - // "-" -> Shift(S17) + // "Num" -> Shift(S3) + // "(" -> Shift(S5) // + // Term -> S2 + // Factor -> S16 pub fn __state7< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Plus(..)) => { - let mut __sym2 = &mut Some(__tok); + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state15(__lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state3(scale, __lookahead, __tokens, __sym2)); } - Some(__tok @ Tok::RParen(..)) => { + Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state16(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state17(__lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state5(scale, __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!(__state2(scale, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state16(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__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" ["/"] + // + // "(" -> Shift(S5) + // "Num" -> Shift(S3) + // + // Term -> S17 + pub fn __state8< + __TOKENS: Iterator, + >( + scale: i32, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state5(scale, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(scale, __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!(__state17(scale, __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(S3) + // + // Term -> S18 + pub fn __state9< + __TOKENS: Iterator, + >( + scale: i32, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state5(scale, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(scale, __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!(__state18(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 10 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // ")" -> Reduce(Term = "Num" => ActionFn(7);) + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // + pub fn __state10< + __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::Times(..)) => { + 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::Minus(..)) => { + 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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 11 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // ")" -> Reduce(Factor = Term => ActionFn(6);) + // "+" -> Reduce(Factor = Term => ActionFn(6);) + // "/" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // + pub fn __state11< + __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::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__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))); + } + Some(Tok::Div(..)) => { + 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::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 12 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -562,30 +867,32 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S8) - // "Num" -> Shift(S6) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) // - // Factor -> S9 - // Expr -> S18 - // Term -> S10 - pub fn __state8< + // Factor -> S14 + // Term -> S11 + // Expr -> S19 + pub fn __state12< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (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 __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym1)); + __result = try!(__state10(scale, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(scale, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); @@ -596,15 +903,15 @@ mod __parse__Expr { match __nt { __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state9(__lookahead, __tokens, __sym1)); - } - __Nonterminal::Expr(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state18(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state14(scale, __lookahead, __tokens, __sym1)); } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state10(__lookahead, __tokens, __sym1)); + __result = try!(__state11(scale, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state19(scale, __lookahead, __tokens, __sym0, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -614,7 +921,58 @@ mod __parse__Expr { return Ok(__result); } - // State 9 + // State 13 + // 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(S22) + // "+" -> Shift(S21) + // "-" -> Shift(S20) + // + pub fn __state13< + __TOKENS: Iterator, + >( + scale: i32, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state22(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(scale, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state20(scale, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 14 // Expr = Factor (*) [")"] // Expr = Factor (*) ["+"] // Expr = Factor (*) ["-"] @@ -629,44 +987,46 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // ")" -> Reduce(Expr = Factor => ActionFn(3);) // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S24) + // ")" -> Reduce(Expr = Factor => ActionFn(3);) // "+" -> Reduce(Expr = Factor => ActionFn(3);) - // "*" -> Shift(S19) - // "/" -> Shift(S20) + // "/" -> Shift(S23) // - pub fn __state9< + pub fn __state14< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::Times(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state19(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state24(scale, __lookahead, __tokens, __sym0, __sym1)); } Some(__tok @ Tok::Div(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state20(__lookahead, __tokens, __sym0, __sym1)); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state23(scale, __lookahead, __tokens, __sym0, __sym1)); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); + 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))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); + let __nt = super::__actions::__action3(scale, __sym0); return Ok((__lookahead, __Nonterminal::Expr(__nt))); } _ => { @@ -676,471 +1036,210 @@ mod __parse__Expr { return Ok(__result); } - // State 10 - // Factor = Term (*) [")"] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] - // - // "+" -> Reduce(Factor = Term => ActionFn(6);) - // "-" -> Reduce(Factor = Term => ActionFn(6);) - // "/" -> Reduce(Factor = Term => ActionFn(6);) - // "*" -> Reduce(Factor = Term => ActionFn(6);) - // ")" -> Reduce(Factor = Term => ActionFn(6);) - // - pub fn __state10< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 11 - // 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(S1) - // "Num" -> Shift(S5) - // - // Term -> S21 - pub fn __state11< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state1(__lookahead, __tokens, __sym2)); - } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state5(__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!(__state21(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 12 - // 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(S1) - // "Num" -> Shift(S5) - // - // Term -> S22 - pub fn __state12< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state1(__lookahead, __tokens, __sym2)); - } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state5(__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!(__state22(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 13 - // 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" ["/"] - // - // "Num" -> Shift(S5) - // "(" -> Shift(S1) - // - // Factor -> S23 - // Term -> S4 - pub fn __state13< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state5(__lookahead, __tokens, __sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state1(__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!(__state23(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state4(__lookahead, __tokens, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 14 - // 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" ["/"] - // - // "(" -> Shift(S1) - // "Num" -> Shift(S5) - // - // Term -> S4 - // Factor -> S24 - pub fn __state14< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state1(__lookahead, __tokens, __sym2)); - } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state5(__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!(__state4(__lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state24(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - // State 15 - // 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 ["/"] - // 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 ["/"] // - // "Num" -> Shift(S6) - // "(" -> Shift(S8) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S9) + // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "*" -> Shift(S8) // - // Term -> S10 - // Factor -> S25 pub fn __state15< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym2)); + __result = try!(__state9(scale, __lookahead, __tokens, __sym2, __sym3)); } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym2)); + __result = try!(__state8(scale, __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((__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))); + } + 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))); } _ => { return Err(__lookahead); } } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state10(__lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state25(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } return Ok(__result); } // State 16 - // Term = "(" Expr ")" (*) [EOF] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] + // 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(Term = "(", Expr, ")" => ActionFn(8);) - // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "/" -> Shift(S9) + // "*" -> Shift(S8) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // pub fn __state16< __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); + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state9(scale, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(scale, __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::__action8(__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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + 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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + 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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 17 + // Factor = Factor "*" Term (*) [EOF] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // EOF -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // + pub fn __state17< + __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::__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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + 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))); + } + 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))); } _ => { return Err(__lookahead); @@ -1148,7 +1247,125 @@ mod __parse__Expr { } } - // State 17 + // State 18 + // Factor = Factor "/" Term (*) [EOF] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // EOF -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // + pub fn __state18< + __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::__action5(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::__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))); + } + 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 Err(__lookahead); + } + } + } + + // State 19 + // 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(S20) + // ")" -> Shift(S25) + // "+" -> Shift(S21) + // + pub fn __state19< + __TOKENS: Iterator, + >( + scale: i32, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state20(scale, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state25(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(scale, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 20 // Expr = Expr "-" (*) Factor [")"] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -1178,30 +1395,32 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S6) - // "(" -> Shift(S8) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) // + // Term -> S11 // Factor -> S26 - // Term -> S10 - pub fn __state17< + pub fn __state20< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym2)); + __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); } Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym2)); + __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1210,13 +1429,13 @@ mod __parse__Expr { while __sym1.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state26(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state10(__lookahead, __tokens, __sym2)); + __result = try!(__state11(scale, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state26(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1226,61 +1445,25 @@ mod __parse__Expr { return Ok(__result); } - // State 18 - // 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(S15) - // "-" -> Shift(S17) - // ")" -> Shift(S27) - // - pub fn __state18< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::Plus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state15(__lookahead, __tokens, __sym1, __sym2)); - } - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state17(__lookahead, __tokens, __sym1, __sym2)); - } - Some(__tok @ Tok::RParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state27(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 19 - // Factor = Factor "*" (*) Term [")"] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] + // State 21 + // 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 ["/"] // Term = (*) "(" Expr ")" [")"] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -1292,29 +1475,32 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S8) - // "Num" -> Shift(S6) + // "(" -> Shift(S12) + // "Num" -> Shift(S10) // - // Term -> S28 - pub fn __state19< + // Factor -> S27 + // Term -> S11 + pub fn __state21< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym2)); + __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); } Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym2)); + __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1323,9 +1509,13 @@ mod __parse__Expr { while __sym1.is_some() { let (__lookahead, __nt) = __result; match __nt { + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state27(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state28(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state11(scale, __lookahead, __tokens, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1335,7 +1525,74 @@ mod __parse__Expr { return Ok(__result); } - // State 20 + // State 22 + // Term = "(" Expr ")" (*) [EOF] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // + pub fn __state22< + __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 { + 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::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::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::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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 23 // Factor = Factor "/" (*) Term [")"] // Factor = Factor "/" (*) Term ["*"] // Factor = Factor "/" (*) Term ["+"] @@ -1352,29 +1609,31 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S6) - // "(" -> Shift(S8) + // "(" -> Shift(S12) + // "Num" -> Shift(S10) // - // Term -> S29 - pub fn __state20< + // Term -> S28 + pub fn __state23< __TOKENS: Iterator, >( + scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym2)); - } Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym2)); + __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1385,7 +1644,7 @@ mod __parse__Expr { match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state29(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state28(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1395,344 +1654,133 @@ mod __parse__Expr { return Ok(__result); } - // State 21 - // Factor = Factor "/" Term (*) [EOF] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] - // - // EOF -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // - pub fn __state21< - __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 { - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__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::__action5(__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::__action5(__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::__action5(__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::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 22 - // Factor = Factor "*" Term (*) [EOF] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] - // - // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // EOF -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // - pub fn __state22< - __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::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__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::__action4(__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::__action4(__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::__action4(__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::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 23 - // 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(S12) - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S11) - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // - pub fn __state23< - __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 @ Tok::Times(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym2, __sym3)); - } - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state11(__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::__action1(__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::__action1(__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::__action1(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - // State 24 - // 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" ["/"] // - // "*" -> Shift(S12) - // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "/" -> Shift(S11) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) // + // Term -> S29 pub fn __state24< __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); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut __sym3 = &mut Some(__tok); + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); } - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some(__tok); + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state11(__lookahead, __tokens, __sym2, __sym3)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action2(__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::__action2(__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::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state12(scale, __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!(__state29(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } return Ok(__result); } // State 25 - // 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 ["/"] + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] // - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "*" -> Shift(S19) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "/" -> Shift(S20) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // pub fn __state25< __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); + __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!(__state19(__lookahead, __tokens, __sym2, __sym3)); - } - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state20(__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::__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::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); } - Some(Tok::Minus(..)) => { + Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + 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::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + 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))); } _ => { return Err(__lookahead); } } - return Ok(__result); } // State 26 @@ -1750,52 +1798,54 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S20) // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "*" -> Shift(S19) + // "/" -> Shift(S23) + // "*" -> Shift(S24) // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // 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); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::Div(..)) => { let mut __sym3 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state20(__lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state23(scale, __lookahead, __tokens, __sym2, __sym3)); } Some(__tok @ Tok::Times(..)) => { let mut __sym3 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state19(__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::__action1(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + __result = try!(__state24(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::__action1(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action1(scale, __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::__action1(__sym0, __sym1, __sym2); + 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))); } _ => { @@ -1806,127 +1856,136 @@ mod __parse__Expr { } // State 27 - // Term = "(" Expr ")" (*) [")"] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] + // 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(Term = "(", Expr, ")" => ActionFn(8);) - // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S24) + // "/" -> Shift(S23) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // pub fn __state27< __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::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__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::__action8(__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::__action8(__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::__action8(__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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 28 - // Factor = Factor "*" Term (*) [")"] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] - // - // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // - pub fn __state28< - __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); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (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::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state24(scale, __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::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state23(scale, __lookahead, __tokens, __sym2, __sym3)); } - Some(Tok::Times(..)) => { + Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + 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::__action4(__sym0, __sym1, __sym2); + 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 Err(__lookahead); + } + } + return Ok(__result); + } + + // State 28 + // Factor = Factor "/" Term (*) [")"] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // ")" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // + pub fn __state28< + __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::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::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))); } Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action5(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::__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))); } _ => { @@ -1936,62 +1995,64 @@ mod __parse__Expr { } // State 29 - // 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(Factor = Factor, "/", Term => ActionFn(5);) - // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // ")" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // pub fn __state29< __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); + ) -> 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::__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::__action5(__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::__action5(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action4(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::__action5(__sym0, __sym1, __sym2); + 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::__action5(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::Factor(__nt))); } - Some(Tok::Minus(..)) => { + Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::Factor(__nt))); } _ => { @@ -2001,84 +2062,99 @@ mod __parse__Expr { } } -fn __action0< ->( - __0: i32, -) -> i32 -{ - (__0) -} +mod __actions { + #![allow(unused_variables)] + use util::tok::Tok; -fn __action1< ->( - l: i32, - _: Tok, - r: i32, -) -> i32 -{ - l - r -} -fn __action2< ->( - l: i32, - _: Tok, - r: i32, -) -> i32 -{ - l + r -} + pub fn __action0< + >( + scale: i32, + __0: i32, + ) -> i32 + { + (__0) + } -fn __action3< ->( - __0: i32, -) -> i32 -{ - (__0) -} + pub fn __action1< + >( + scale: i32, + l: i32, + _: Tok, + r: i32, + ) -> i32 + { + l - r + } -fn __action4< ->( - l: i32, - _: Tok, - r: i32, -) -> i32 -{ - l * r -} + pub fn __action2< + >( + scale: i32, + l: i32, + _: Tok, + r: i32, + ) -> i32 + { + l + r + } -fn __action5< ->( - l: i32, - _: Tok, - r: i32, -) -> i32 -{ - l / r -} + pub fn __action3< + >( + scale: i32, + __0: i32, + ) -> i32 + { + (__0) + } -fn __action6< ->( - __0: i32, -) -> i32 -{ - (__0) -} + pub fn __action4< + >( + scale: i32, + l: i32, + _: Tok, + r: i32, + ) -> i32 + { + l * r + } -fn __action7< ->( - __0: i32, -) -> i32 -{ - (__0) -} + pub fn __action5< + >( + scale: i32, + l: i32, + _: Tok, + r: i32, + ) -> i32 + { + l / r + } -fn __action8< ->( - _: Tok, - __0: i32, - _: Tok, -) -> i32 -{ - (__0) + pub fn __action6< + >( + scale: i32, + __0: i32, + ) -> i32 + { + (__0) + } + + pub fn __action7< + >( + scale: i32, + n: i32, + ) -> i32 + { + n * scale + } + + pub fn __action8< + >( + scale: i32, + _: Tok, + __0: i32, + _: Tok, + ) -> i32 + { + (__0) + } } diff --git a/lalrpop-test/src/expr_arena.lalrpop b/lalrpop-test/src/expr_arena.lalrpop new file mode 100644 index 0000000..b3a7c26 --- /dev/null +++ b/lalrpop-test/src/expr_arena.lalrpop @@ -0,0 +1,33 @@ +grammar<'ast>(arena: &'ast Arena<'ast>); + +use expr_arena_ast::{Arena, Node, Op}; +use util::tok::Tok; + +extern token { + enum Tok { + "(" => Tok::LParen(..), + ")" => Tok::RParen(..), + "-" => Tok::Minus(..), + "+" => Tok::Plus(..), + "*" => Tok::Times(..), + "/" => Tok::Div(..), + "Num" => Tok::Num() + } +} + +pub Expr: &'ast Node<'ast> = { + "-" => arena.alloc(Node::Binary(Op::Sub, l, r)); + "+" => arena.alloc(Node::Binary(Op::Add, l, r)); + Factor; +}; + +Factor = { + "*" => arena.alloc(Node::Binary(Op::Mul, l, r)); + "/" => arena.alloc(Node::Binary(Op::Div, l, r)); + Term; +}; + +Term = { + => arena.alloc(Node::Value(n)); + "(" ")"; +}; diff --git a/lalrpop-test/src/expr_arena.rs b/lalrpop-test/src/expr_arena.rs new file mode 100644 index 0000000..1669fe4 --- /dev/null +++ b/lalrpop-test/src/expr_arena.rs @@ -0,0 +1,2203 @@ +use expr_arena_ast::{Arena, Node, Op}; +use util::tok::Tok; + +#[allow(non_snake_case)] +pub fn parse_Expr< + 'ast, + __TOKENS: IntoIterator, +>( + arena: &'ast Arena<'ast>, + __tokens: __TOKENS, +) -> Result<(Option, &'ast Node<'ast>), Option> +{ + 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)), + _ => unreachable!(), + } +} + +mod __parse__Expr { + #![allow(non_snake_case, unused_mut, unused_variables)] + + use expr_arena_ast::{Arena, Node, Op}; + use util::tok::Tok; + + pub enum __Nonterminal<'ast, > { + __Expr(&'ast Node<'ast>), + Factor(&'ast Node<'ast>), + Expr(&'ast Node<'ast>), + Term(&'ast Node<'ast>), + } + + // State 0 + // Expr = (*) Expr "+" Factor [EOF] + // Expr = (*) Expr "+" Factor ["+"] + // Expr = (*) Expr "+" Factor ["-"] + // Expr = (*) Expr "-" Factor [EOF] + // Expr = (*) Expr "-" Factor ["+"] + // Expr = (*) Expr "-" Factor ["-"] + // Expr = (*) Factor [EOF] + // Expr = (*) Factor ["+"] + // 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 = (*) Expr [EOF] + // + // "Num" -> Shift(S3) + // "(" -> Shift(S4) + // + // Expr -> S1 + // Factor -> S5 + // Term -> S2 + pub fn __state0< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym0 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(arena, __lookahead, __tokens, __sym0)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym0 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state4(arena, __lookahead, __tokens, __sym0)); + } + _ => { + return Err(__lookahead); + } + } + loop { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Expr(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state1(arena, __lookahead, __tokens, __sym0)); + } + __Nonterminal::Factor(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state5(arena, __lookahead, __tokens, __sym0)); + } + __Nonterminal::Term(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state2(arena, __lookahead, __tokens, __sym0)); + } + _ => { + return Ok((__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) + // "-" -> Shift(S7) + // EOF -> Reduce(__Expr = Expr => ActionFn(0);) + // + pub fn __state1< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Plus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state6(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state7(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 2 + // Factor = Term (*) [EOF] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "/" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) + // EOF -> Reduce(Factor = Term => ActionFn(6);) + // "+" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // + pub fn __state2< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 3 + // Term = "Num" (*) [EOF] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // EOF -> Reduce(Term = "Num" => ActionFn(7);) + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // + pub fn __state3< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 4 + // Expr = (*) Expr "+" Factor [")"] + // Expr = (*) Expr "+" Factor ["+"] + // Expr = (*) Expr "+" Factor ["-"] + // Expr = (*) Expr "-" Factor [")"] + // Expr = (*) Expr "-" Factor ["+"] + // Expr = (*) Expr "-" Factor ["-"] + // 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 ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = "(" (*) Expr ")" [EOF] + // Term = "(" (*) Expr ")" ["*"] + // Term = "(" (*) Expr ")" ["+"] + // Term = "(" (*) Expr ")" ["-"] + // Term = "(" (*) Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S8) + // "Num" -> Shift(S9) + // + // Expr -> S12 + // Term -> S11 + // Factor -> S10 + pub fn __state4< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(arena, __lookahead, __tokens, __sym1)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym1 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state9(arena, __lookahead, __tokens, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + while __sym0.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state12(arena, __lookahead, __tokens, __sym0, __sym1)); + } + __Nonterminal::Term(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state11(arena, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Factor(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state10(arena, __lookahead, __tokens, __sym1)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 5 + // Expr = Factor (*) [EOF] + // Expr = Factor (*) ["+"] + // 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 = Factor => ActionFn(3);) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S14) + // "/" -> Shift(S13) + // + pub fn __state5< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Times(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state14(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state13(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::Minus(..)) => { + 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 6 + // 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" ["/"] + // + // "Num" -> Shift(S3) + // "(" -> Shift(S4) + // + // Factor -> S15 + // Term -> S2 + pub fn __state6< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state4(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!(__state15(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state2(arena, __lookahead, __tokens, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // 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 ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S3) + // "(" -> Shift(S4) + // + // Term -> S2 + // Factor -> S16 + pub fn __state7< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state4(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!(__state2(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state16(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 8 + // Expr = (*) Expr "+" Factor [")"] + // Expr = (*) Expr "+" Factor ["+"] + // Expr = (*) Expr "+" Factor ["-"] + // Expr = (*) Expr "-" Factor [")"] + // Expr = (*) Expr "-" Factor ["+"] + // Expr = (*) Expr "-" Factor ["-"] + // 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 ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = "(" (*) Expr ")" [")"] + // Term = "(" (*) Expr ")" ["*"] + // Term = "(" (*) Expr ")" ["+"] + // Term = "(" (*) Expr ")" ["-"] + // Term = "(" (*) Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S9) + // "(" -> Shift(S8) + // + // Factor -> S10 + // Term -> S11 + // Expr -> S17 + pub fn __state8< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym1 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state9(arena, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(arena, __lookahead, __tokens, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + while __sym0.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Factor(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state10(arena, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Term(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state11(arena, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state17(arena, __lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 9 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // ")" -> Reduce(Term = "Num" => ActionFn(7);) + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // + pub fn __state9< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // 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 ["/"] + // + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "/" -> Shift(S19) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S18) + // ")" -> Reduce(Expr = Factor => ActionFn(3);) + // + pub fn __state10< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Div(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state19(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state18(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(Tok::Plus(..)) => { + 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))); + } + Some(Tok::RParen(..)) => { + 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 11 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "/" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // "+" -> Reduce(Factor = Term => ActionFn(6);) + // ")" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) + // + pub fn __state11< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // 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(S20) + // "+" -> Shift(S21) + // "-" -> Shift(S22) + // + pub fn __state12< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state20(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(arena, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state22(arena, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 13 + // 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(S4) + // "Num" -> Shift(S3) + // + // Term -> S23 + pub fn __state13< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state4(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(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!(__state23(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 14 + // 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(S3) + // "(" -> Shift(S4) + // + // Term -> S24 + pub fn __state14< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state4(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!(__state24(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 15 + // 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 => ActionFn(2);) + // "/" -> Shift(S13) + // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S14) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // + pub fn __state15< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state13(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state14(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::__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::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))); + } + _ => { + return Err(__lookahead); + } + } + 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 ["/"] + // + // "/" -> Shift(S13) + // "*" -> Shift(S14) + // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // + pub fn __state16< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state13(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state14(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::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))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 17 + // 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(S25) + // "+" -> Shift(S21) + // "-" -> Shift(S22) + // + pub fn __state17< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state25(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(arena, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state22(arena, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 18 + // 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" ["/"] + // + // "(" -> Shift(S8) + // "Num" -> Shift(S9) + // + // Term -> S26 + pub fn __state18< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state9(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!(__state26(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 19 + // 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(S9) + // "(" -> Shift(S8) + // + // Term -> S27 + pub fn __state19< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state9(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(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!(__state27(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 20 + // Term = "(" Expr ")" (*) [EOF] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // + pub fn __state20< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __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::__action8(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::__action8(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::__action8(arena, __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(arena, __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(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 21 + // 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 ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S8) + // "Num" -> Shift(S9) + // + // Term -> S11 + // Factor -> S28 + pub fn __state21< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state9(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!(__state11(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state28(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // 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 ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S9) + // "(" -> Shift(S8) + // + // Term -> S11 + // Factor -> S29 + pub fn __state22< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state9(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(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!(__state11(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state29(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 23 + // Factor = Factor "/" Term (*) [EOF] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // EOF -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // + pub fn __state23< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + 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::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))); + } + 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))); + } + 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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 24 + // Factor = Factor "*" Term (*) [EOF] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // EOF -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // + pub fn __state24< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __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::__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))); + } + 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))); + } + 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 Err(__lookahead); + } + } + } + + // State 25 + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // + pub fn __state25< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option<&'ast Node<'ast>>, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __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::__action8(arena, __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(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::__action8(arena, __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(arena, __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(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 26 + // Factor = Factor "*" Term (*) [")"] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // + pub fn __state26< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __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::__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::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::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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 27 + // Factor = Factor "/" Term (*) [")"] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // ")" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // + pub fn __state27< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __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::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))); + } + 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 Err(__lookahead); + } + } + } + + // State 28 + // 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 ["/"] + // + // "/" -> Shift(S19) + // "*" -> Shift(S18) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // + pub fn __state28< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state19(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state18(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::__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))); + } + 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))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 29 + // 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 ["/"] + // + // "*" -> Shift(S18) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S19) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // + pub fn __state29< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<&'ast Node<'ast>>, + __sym1: &mut Option, + __sym2: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state18(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state19(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))); + } + 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))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } +} + +mod __actions { + #![allow(unused_variables)] + use expr_arena_ast::{Arena, Node, Op}; + use util::tok::Tok; + + + pub fn __action0< + 'ast, + >( + arena: &'ast Arena<'ast>, + __0: &'ast Node<'ast>, + ) -> &'ast Node<'ast> + { + (__0) + } + + pub fn __action1< + 'ast, + >( + arena: &'ast Arena<'ast>, + l: &'ast Node<'ast>, + _: Tok, + r: &'ast Node<'ast>, + ) -> &'ast Node<'ast> + { + arena.alloc(Node::Binary(Op::Sub, l, r)) + } + + pub fn __action2< + 'ast, + >( + arena: &'ast Arena<'ast>, + l: &'ast Node<'ast>, + _: Tok, + r: &'ast Node<'ast>, + ) -> &'ast Node<'ast> + { + arena.alloc(Node::Binary(Op::Add, l, r)) + } + + pub fn __action3< + 'ast, + >( + arena: &'ast Arena<'ast>, + __0: &'ast Node<'ast>, + ) -> &'ast Node<'ast> + { + (__0) + } + + pub fn __action4< + 'ast, + >( + arena: &'ast Arena<'ast>, + l: &'ast Node<'ast>, + _: Tok, + r: &'ast Node<'ast>, + ) -> &'ast Node<'ast> + { + arena.alloc(Node::Binary(Op::Mul, l, r)) + } + + pub fn __action5< + 'ast, + >( + arena: &'ast Arena<'ast>, + l: &'ast Node<'ast>, + _: Tok, + r: &'ast Node<'ast>, + ) -> &'ast Node<'ast> + { + arena.alloc(Node::Binary(Op::Div, l, r)) + } + + pub fn __action6< + 'ast, + >( + arena: &'ast Arena<'ast>, + __0: &'ast Node<'ast>, + ) -> &'ast Node<'ast> + { + (__0) + } + + pub fn __action7< + 'ast, + >( + arena: &'ast Arena<'ast>, + n: i32, + ) -> &'ast Node<'ast> + { + arena.alloc(Node::Value(n)) + } + + pub fn __action8< + 'ast, + >( + arena: &'ast Arena<'ast>, + _: Tok, + __0: &'ast Node<'ast>, + _: Tok, + ) -> &'ast Node<'ast> + { + (__0) + } +} diff --git a/lalrpop-test/src/expr_arena_ast.rs b/lalrpop-test/src/expr_arena_ast.rs new file mode 100644 index 0000000..8445889 --- /dev/null +++ b/lalrpop-test/src/expr_arena_ast.rs @@ -0,0 +1,29 @@ +use std::cell::RefCell; + +#[derive(Debug, PartialEq, Eq)] +pub enum Op { + Add, Sub, Mul, Div +} + +#[derive(Debug, PartialEq, Eq)] +pub enum Node<'ast> { + Value(i32), + Binary(Op, &'ast Node<'ast>, &'ast Node<'ast>), +} + +pub struct Arena<'ast> { + data: RefCell>>> +} + +impl<'ast> Arena<'ast> { + pub fn new() -> Arena<'ast> { + Arena { data: RefCell::new(vec![]) } + } + + pub fn alloc(&'ast self, n: Node<'ast>) -> &'ast Node<'ast> { + let b = Box::new(n); + let p: *const Node<'ast> = &*b; + self.data.borrow_mut().push(b); + unsafe { &*p } + } +} diff --git a/lalrpop-test/src/main.rs b/lalrpop-test/src/main.rs index 84586a0..bc20c6a 100644 --- a/lalrpop-test/src/main.rs +++ b/lalrpop-test/src/main.rs @@ -1,31 +1,36 @@ mod expr; +mod expr_arena; +mod expr_arena_ast; mod sub; mod util; -use expr::parse_Expr; - fn main() { println!("Hello, world!"); } #[test] fn expr_test1() { - util::test(parse_Expr, "22 - 3", 22 - 3); + util::test(|v| expr::parse_Expr(1, v), "22 - 3", 22 - 3); } #[test] fn expr_test2() { - util::test(parse_Expr, "22 - (3 + 5)", 22 - (3 + 5)); + util::test(|v| expr::parse_Expr(1, v), "22 - (3 + 5)", 22 - (3 + 5)); } #[test] fn expr_test3() { - util::test(parse_Expr, "22 - (3 - 5) - 13", 22 - (3 - 5) - 13); + util::test(|v| expr::parse_Expr(1, v), "22 - (3 - 5) - 13", 22 - (3 - 5) - 13); } #[test] fn expr_test4() { - util::test(parse_Expr, "22 * 3 - 6", 22 * 3 - 6); + util::test(|v| expr::parse_Expr(1, v), "22 * 3 - 6", 22 * 3 - 6); +} + +#[test] +fn expr_test5() { + util::test(|v| expr::parse_Expr(11, v), "22 * 3 - 6", 22*11 * 3*11 - 6*11); } #[test] @@ -42,3 +47,17 @@ fn sub_test2() { fn sub_test3() { util::test(sub::parse_S, "22 - (3 - 5) - 13", 22 - (3 - 5) - 13); } + +#[test] +fn expr_arena_test1() { + use expr_arena_ast::*; + let mut arena = Arena::new(); + let expected = + arena.alloc(Node::Binary(Op::Sub, + arena.alloc(Node::Binary(Op::Mul, + arena.alloc(Node::Value(22)), + arena.alloc(Node::Value(3)))), + arena.alloc(Node::Value(6)))); + util::test(|v| expr_arena::parse_Expr(&arena, v), "22 * 3 - 6", expected); +} + diff --git a/lalrpop-test/src/sub.rs b/lalrpop-test/src/sub.rs index 53056b0..e8c7075 100644 --- a/lalrpop-test/src/sub.rs +++ b/lalrpop-test/src/sub.rs @@ -20,11 +20,11 @@ mod __parse__S { use util::tok::Tok; - pub enum __Nonterminal { - T(i32), + pub enum __Nonterminal<> { + S(i32), __S(i32), E(i32), - S(i32), + T(i32), } // State 0 @@ -42,16 +42,17 @@ mod __parse__S { // "(" -> Shift(S1) // "Num" -> Shift(S4) // - // S -> S2 - // E -> S3 // T -> S5 + // E -> S2 + // S -> S3 pub fn __state0< __TOKENS: Iterator, >( mut __lookahead: Option, __tokens: &mut __TOKENS, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::LParen(..)) => { let mut __sym0 = &mut Some(__tok); @@ -70,18 +71,18 @@ mod __parse__S { loop { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::S(__nt) => { - let __sym0 = &mut Some(__nt); - __result = try!(__state2(__lookahead, __tokens, __sym0)); - } - __Nonterminal::E(__nt) => { - let __sym0 = &mut Some(__nt); - __result = try!(__state3(__lookahead, __tokens, __sym0)); - } __Nonterminal::T(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state5(__lookahead, __tokens, __sym0)); } + __Nonterminal::E(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state2(__lookahead, __tokens, __sym0)); + } + __Nonterminal::S(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state3(__lookahead, __tokens, __sym0)); + } _ => { return Ok((__lookahead, __nt)); } @@ -101,30 +102,31 @@ mod __parse__S { // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "(" -> Shift(S7) // "Num" -> Shift(S6) + // "(" -> Shift(S9) // - // T -> S9 // E -> S8 + // T -> S7 pub fn __state1< __TOKENS: Iterator, >( mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state7(__lookahead, __tokens, __sym1)); - } Some(Tok::Num(__tok0)) => { let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); __result = try!(__state6(__lookahead, __tokens, __sym1)); } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state9(__lookahead, __tokens, __sym1)); + } _ => { return Err(__lookahead); } @@ -132,14 +134,14 @@ mod __parse__S { while __sym0.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::T(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state9(__lookahead, __tokens, __sym1)); - } __Nonterminal::E(__nt) => { let __sym1 = &mut Some(__nt); __result = try!(__state8(__lookahead, __tokens, __sym0, __sym1)); } + __Nonterminal::T(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state7(__lookahead, __tokens, __sym1)); + } _ => { return Ok((__lookahead, __nt)); } @@ -149,31 +151,6 @@ mod __parse__S { } // State 2 - // __S = S (*) [EOF] - // - // EOF -> Reduce(__S = S => ActionFn(0);) - // - pub fn __state2< - __TOKENS: Iterator, - >( - 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::__action0(__sym0); - return Ok((__lookahead, __Nonterminal::__S(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 3 // E = E (*) "-" T [EOF] // E = E (*) "-" T ["-"] // S = E (*) [EOF] @@ -181,14 +158,15 @@ mod __parse__S { // "-" -> Shift(S10) // EOF -> Reduce(S = E => ActionFn(1);) // - pub fn __state3< + pub fn __state2< __TOKENS: Iterator, >( mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::Minus(..)) => { let mut __sym1 = &mut Some(__tok); @@ -197,7 +175,7 @@ mod __parse__S { } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action1(__sym0); + let __nt = super::__actions::__action1(__sym0); return Ok((__lookahead, __Nonterminal::S(__nt))); } _ => { @@ -207,6 +185,32 @@ mod __parse__S { return Ok(__result); } + // State 3 + // __S = S (*) [EOF] + // + // EOF -> Reduce(__S = S => ActionFn(0);) + // + pub fn __state3< + __TOKENS: Iterator, + >( + 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::__action0(__sym0); + return Ok((__lookahead, __Nonterminal::__S(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + // State 4 // T = "Num" (*) [EOF] // T = "Num" (*) ["-"] @@ -220,17 +224,18 @@ mod __parse__S { mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action4(__sym0); + let __nt = super::__actions::__action4(__sym0); return Ok((__lookahead, __Nonterminal::T(__nt))); } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action4(__sym0); + let __nt = super::__actions::__action4(__sym0); return Ok((__lookahead, __Nonterminal::T(__nt))); } _ => { @@ -243,8 +248,8 @@ mod __parse__S { // E = T (*) [EOF] // E = T (*) ["-"] // - // EOF -> Reduce(E = T => ActionFn(3);) // "-" -> Reduce(E = T => ActionFn(3);) + // EOF -> Reduce(E = T => ActionFn(3);) // pub fn __state5< __TOKENS: Iterator, @@ -252,17 +257,18 @@ mod __parse__S { mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); + let __nt = super::__actions::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::E(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(__sym0); return Ok((__lookahead, __Nonterminal::E(__nt))); } _ => { @@ -275,8 +281,8 @@ mod __parse__S { // T = "Num" (*) [")"] // T = "Num" (*) ["-"] // - // ")" -> Reduce(T = "Num" => ActionFn(4);) // "-" -> Reduce(T = "Num" => ActionFn(4);) + // ")" -> Reduce(T = "Num" => ActionFn(4);) // pub fn __state6< __TOKENS: Iterator, @@ -284,17 +290,18 @@ mod __parse__S { mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action4(__sym0); + let __nt = super::__actions::__action4(__sym0); + return Ok((__lookahead, __Nonterminal::T(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action4(__sym0); return Ok((__lookahead, __Nonterminal::T(__nt))); } _ => { @@ -304,6 +311,76 @@ mod __parse__S { } // State 7 + // E = T (*) [")"] + // E = T (*) ["-"] + // + // ")" -> Reduce(E = T => ActionFn(3);) + // "-" -> Reduce(E = T => ActionFn(3);) + // + pub fn __state7< + __TOKENS: Iterator, + >( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(Tok::RParen(..)) => { + 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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 8 + // E = E (*) "-" T [")"] + // E = E (*) "-" T ["-"] + // T = "(" E (*) ")" [EOF] + // T = "(" E (*) ")" ["-"] + // + // ")" -> Shift(S11) + // "-" -> Shift(S12) + // + pub fn __state8< + __TOKENS: Iterator, + >( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state11(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(__lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 9 // E = (*) E "-" T [")"] // E = (*) E "-" T ["-"] // E = (*) T [")"] @@ -315,24 +392,25 @@ mod __parse__S { // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "(" -> Shift(S7) + // "(" -> Shift(S9) // "Num" -> Shift(S6) // - // E -> S11 - // T -> S9 - pub fn __state7< + // T -> S7 + // E -> S13 + pub fn __state9< __TOKENS: Iterator, >( mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(__tok @ Tok::LParen(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state7(__lookahead, __tokens, __sym1)); + __result = try!(__state9(__lookahead, __tokens, __sym1)); } Some(Tok::Num(__tok0)) => { let mut __sym1 = &mut Some((__tok0)); @@ -346,13 +424,13 @@ mod __parse__S { while __sym0.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::E(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state11(__lookahead, __tokens, __sym0, __sym1)); - } __Nonterminal::T(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state9(__lookahead, __tokens, __sym1)); + __result = try!(__state7(__lookahead, __tokens, __sym1)); + } + __Nonterminal::E(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state13(__lookahead, __tokens, __sym0, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -362,74 +440,6 @@ mod __parse__S { return Ok(__result); } - // State 8 - // E = E (*) "-" T [")"] - // E = E (*) "-" T ["-"] - // T = "(" E (*) ")" [EOF] - // T = "(" E (*) ")" ["-"] - // - // "-" -> Shift(S13) - // ")" -> Shift(S12) - // - pub fn __state8< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state13(__lookahead, __tokens, __sym1, __sym2)); - } - Some(__tok @ Tok::RParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 9 - // E = T (*) [")"] - // E = T (*) ["-"] - // - // ")" -> Reduce(E = T => ActionFn(3);) - // "-" -> Reduce(E = T => ActionFn(3);) - // - pub fn __state9< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - // State 10 // E = E "-" (*) T [EOF] // E = E "-" (*) T ["-"] @@ -438,8 +448,8 @@ mod __parse__S { // T = (*) "Num" [EOF] // T = (*) "Num" ["-"] // - // "(" -> Shift(S1) // "Num" -> Shift(S4) + // "(" -> Shift(S1) // // T -> S14 pub fn __state10< @@ -449,19 +459,20 @@ mod __parse__S { __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state1(__lookahead, __tokens, __sym2)); - } Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); __result = try!(__state4(__lookahead, __tokens, __sym2)); } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state1(__lookahead, __tokens, __sym2)); + } _ => { return Err(__lookahead); } @@ -482,71 +493,36 @@ mod __parse__S { } // State 11 - // E = E (*) "-" T [")"] - // E = E (*) "-" T ["-"] - // T = "(" E (*) ")" [")"] - // T = "(" E (*) ")" ["-"] + // T = "(" E ")" (*) [EOF] + // T = "(" E ")" (*) ["-"] // - // "-" -> Shift(S13) - // ")" -> Shift(S15) + // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) // pub fn __state11< __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state13(__lookahead, __tokens, __sym1, __sym2)); - } - Some(__tok @ Tok::RParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state15(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 12 - // T = "(" E ")" (*) [EOF] - // T = "(" E ")" (*) ["-"] - // - // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) - // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) - // - pub fn __state12< - __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); + ) -> 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::__action5(__sym0, __sym1, __sym2); + 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::__action5(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::T(__nt))); } _ => { @@ -555,7 +531,7 @@ mod __parse__S { } } - // State 13 + // State 12 // E = E "-" (*) T [")"] // E = E "-" (*) T ["-"] // T = (*) "(" E ")" [")"] @@ -563,30 +539,31 @@ mod __parse__S { // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "(" -> Shift(S7) // "Num" -> Shift(S6) + // "(" -> Shift(S9) // - // T -> S16 - pub fn __state13< + // T -> S15 + pub fn __state12< __TOKENS: Iterator, >( mut __lookahead: Option, __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state7(__lookahead, __tokens, __sym2)); - } Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); __result = try!(__state6(__lookahead, __tokens, __sym2)); } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state9(__lookahead, __tokens, __sym2)); + } _ => { return Err(__lookahead); } @@ -596,7 +573,7 @@ mod __parse__S { match __nt { __Nonterminal::T(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state16(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state15(__lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -606,6 +583,43 @@ mod __parse__S { return Ok(__result); } + // State 13 + // E = E (*) "-" T [")"] + // E = E (*) "-" T ["-"] + // T = "(" E (*) ")" [")"] + // T = "(" E (*) ")" ["-"] + // + // ")" -> Shift(S16) + // "-" -> Shift(S12) + // + pub fn __state13< + __TOKENS: Iterator, + >( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state16(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(__lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + // State 14 // E = E "-" T (*) [EOF] // E = E "-" T (*) ["-"] @@ -621,21 +635,22 @@ mod __parse__S { __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); match __lookahead { None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action2(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); return Ok((__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::__action2(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::E(__nt))); } _ => { @@ -645,36 +660,37 @@ mod __parse__S { } // State 15 - // T = "(" E ")" (*) [")"] - // T = "(" E ")" (*) ["-"] + // E = E "-" T (*) [")"] + // E = E "-" T (*) ["-"] // - // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) - // ")" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // ")" -> Reduce(E = E, "-", T => ActionFn(2);) // pub fn __state15< __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); + __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::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::T(__nt))); + 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::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::T(__nt))); + let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::E(__nt))); } _ => { return Err(__lookahead); @@ -683,36 +699,37 @@ mod __parse__S { } // State 16 - // E = E "-" T (*) [")"] - // E = E "-" T (*) ["-"] + // T = "(" E ")" (*) [")"] + // T = "(" E ")" (*) ["-"] // - // ")" -> Reduce(E = E, "-", T => ActionFn(2);) - // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // ")" -> Reduce(T = "(", E, ")" => ActionFn(5);) // pub fn __state16< __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); + __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::__action2(__sym0, __sym1, __sym2); - return Ok((__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::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); + 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 Err(__lookahead); @@ -721,54 +738,59 @@ mod __parse__S { } } -fn __action0< ->( - __0: i32, -) -> i32 -{ - (__0) -} +mod __actions { + use util::tok::Tok; -fn __action1< ->( - __0: i32, -) -> i32 -{ - (__0) -} -fn __action2< ->( - l: i32, - _: Tok, - r: i32, -) -> i32 -{ - l-r -} + pub fn __action0< + >( + __0: i32, + ) -> i32 + { + (__0) + } -fn __action3< ->( - __0: i32, -) -> i32 -{ - (__0) -} + pub fn __action1< + >( + __0: i32, + ) -> i32 + { + (__0) + } -fn __action4< ->( - __0: i32, -) -> i32 -{ - (__0) -} + pub fn __action2< + >( + l: i32, + _: Tok, + r: i32, + ) -> i32 + { + l-r + } -fn __action5< ->( - _: Tok, - __0: i32, - _: Tok, -) -> i32 -{ - (__0) + pub fn __action3< + >( + __0: i32, + ) -> i32 + { + (__0) + } + + pub fn __action4< + >( + __0: i32, + ) -> i32 + { + (__0) + } + + pub fn __action5< + >( + _: Tok, + __0: i32, + _: Tok, + ) -> i32 + { + (__0) + } } diff --git a/lalrpop-test/src/util/mod.rs b/lalrpop-test/src/util/mod.rs index 4c1cf18..2e0cd09 100644 --- a/lalrpop-test/src/util/mod.rs +++ b/lalrpop-test/src/util/mod.rs @@ -1,54 +1,16 @@ //! Utilities for testing. -#![crate_type="rlib"] -#![crate_name="util"] - -use std::env; use std::fmt::Debug; - -use std::fs::File; -use std::io::{self, Read}; -use std::process::exit; use util::tok::Tok; // a simple tokenizer pub mod tok; -// a generic main fn suitable for being executed from the makefile -pub fn main(parse_fn: fn(Vec) -> Result<(Option,R),Option>) { - let mut args = env::args().skip(1); - - // read the input file - let mut input = String::new(); - match args.next() { - Some(input_path) => { - let mut f = File::open(&input_path).unwrap(); - f.read_to_string(&mut input).unwrap(); - } - None => { - let mut s = io::stdin(); - s.read_to_string(&mut input).unwrap(); - } - } - - // create tokens - let tokens = tok::tokenize(&input); - - // parse - let (lookahead, r) = parse_fn(tokens).unwrap(); - - // expect input to be completely consumed - if lookahead.is_some() { - println!("input not completely consumed"); - exit(1); - } - - println!("input ok: {:?}", r); -} - -pub fn test(parse_fn: fn(Vec) -> Result<(Option,R),Option>, - input: &str, - expected: R) { +pub fn test(parse_fn: F, + input: &str, + expected: R) + where F: FnOnce(Vec) -> Result<(Option,R),Option> +{ // create tokens let tokens = tok::tokenize(input); diff --git a/lalrpop/src/build/mod.rs b/lalrpop/src/build/mod.rs index 81aee25..cc63663 100644 --- a/lalrpop/src/build/mod.rs +++ b/lalrpop/src/build/mod.rs @@ -99,9 +99,20 @@ fn emit_action_code(grammar: &r::Grammar, rust: &mut RustWrite) -> io::Result<()> { + rust!(rust, ""); + rust!(rust, "mod {}actions {{", grammar.prefix); + + // we always thread the parameters through to the action code, + // even if they are not used, and hence we need to disable the + // unused variables lint, which otherwise gets very excited. + if !grammar.parameters.is_empty() { + rust!(rust, "#![allow(unused_variables)]"); + } + + try!(emit_uses(grammar, rust)); for (i, defn) in grammar.action_fn_defns.iter().enumerate() { rust!(rust, ""); - try!(rust.write_fn_header( + try!(rust.write_pub_fn_header( grammar, format!("{}action{}", grammar.prefix, i), vec![], @@ -115,6 +126,7 @@ fn emit_action_code(grammar: &r::Grammar, rust!(rust, "{}", defn.code); rust!(rust, "}}"); } + rust!(rust, "}}"); Ok(()) } diff --git a/lalrpop/src/grammar/parse_tree.rs b/lalrpop/src/grammar/parse_tree.rs index 57b7c93..02a9169 100644 --- a/lalrpop/src/grammar/parse_tree.rs +++ b/lalrpop/src/grammar/parse_tree.rs @@ -60,6 +60,12 @@ pub enum TypeRef { types: Vec }, + Ref { + lifetime: Option, + mutable: bool, + referent: Box, + }, + // 'x ==> only should appear within nominal types, but what do we care Lifetime(InternedString), @@ -349,6 +355,14 @@ impl Display for TypeRef { write!(fmt, "{}", s), TypeRef::OfSymbol(ref s) => write!(fmt, "`{}`", s), + TypeRef::Ref { lifetime: None, mutable: false, ref referent } => + write!(fmt, "&{}", referent), + TypeRef::Ref { lifetime: Some(l), mutable: false, ref referent } => + write!(fmt, "&{} {}", l, referent), + TypeRef::Ref { lifetime: None, mutable: true, ref referent } => + write!(fmt, "&mut {}", referent), + TypeRef::Ref { lifetime: Some(l), mutable: true, ref referent } => + write!(fmt, "&{} mut {}", l, referent), } } } @@ -374,7 +388,11 @@ impl TypeRef { types: vec![] }), TypeRef::OfSymbol(_) => - unreachable!("OfSymbol produced by parser") + unreachable!("OfSymbol produced by parser"), + TypeRef::Ref { lifetime, mutable, ref referent } => + TypeRepr::Ref { lifetime: lifetime, + mutable: mutable, + referent: Box::new(referent.type_repr()) }, } } } diff --git a/lalrpop/src/grammar/repr.rs b/lalrpop/src/grammar/repr.rs index 122d810..932c06b 100644 --- a/lalrpop/src/grammar/repr.rs +++ b/lalrpop/src/grammar/repr.rs @@ -83,6 +83,11 @@ pub enum TypeRepr { Tuple(Vec), Nominal(NominalTypeRepr), Lifetime(InternedString), + Ref { + lifetime: Option, + mutable: bool, + referent: Box, + }, } #[derive(Clone, PartialEq, Eq)] @@ -147,6 +152,14 @@ impl Display for TypeRepr { write!(fmt, "{}", data), TypeRepr::Lifetime(id) => write!(fmt, "{}", id), + TypeRepr::Ref { lifetime: None, mutable: false, ref referent } => + write!(fmt, "&{}", referent), + TypeRepr::Ref { lifetime: Some(l), mutable: false, ref referent } => + write!(fmt, "&{} {}", l, referent), + TypeRepr::Ref { lifetime: None, mutable: true, ref referent } => + write!(fmt, "&mut {}", referent), + TypeRepr::Ref { lifetime: Some(l), mutable: true, ref referent } => + write!(fmt, "&{} mut {}", l, referent), } } } @@ -269,5 +282,25 @@ impl Grammar { None => &[], // this...probably shouldn't happen actually? } } + + pub fn user_parameter_refs(&self) -> String { + let mut result = String::new(); + for parameter in &self.parameters { + result.push_str(&format!("{}, ", parameter.name)); + } + result + } + + pub fn user_type_parameter_decls(&self) -> String { + let mut result = String::new(); + for parameter in &self.type_parameters { + result.push_str(&format!("{}, ", parameter)); + } + result + } + + pub fn user_type_parameter_refs(&self) -> String { + self.user_type_parameter_decls() + } } diff --git a/lalrpop/src/lr1/ascent.rs b/lalrpop/src/lr1/ascent.rs index 49a31b9..5c4ea5e 100644 --- a/lalrpop/src/lr1/ascent.rs +++ b/lalrpop/src/lr1/ascent.rs @@ -87,7 +87,9 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { } fn write_return_type_defn(&mut self) -> io::Result<()> { - rust!(self.out, "pub enum {}Nonterminal {{", self.prefix); + rust!(self.out, "pub enum {}Nonterminal<{}> {{", + self.prefix, + self.grammar.user_type_parameter_decls()); // make an enum with one variant per nonterminal; I considered // making different enums per state, but this would mean we @@ -115,8 +117,9 @@ 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)) {{", - self.prefix, self.start_symbol, self.prefix, self.prefix, self.prefix); + rust!(self.out, "match try!({}parse{}::{}state0({}{}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)) => \ Ok(({}lookahead, {}nt)),", self.prefix, self.prefix, self.start_symbol, self.prefix, self.start_symbol, @@ -164,13 +167,15 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { format!("{}state{}", self.prefix, this_index.0), vec![format!("{}TOKENS: Iterator", self.prefix, terminal_type)], base_args.into_iter().chain(sym_args).collect(), - format!("Result<(Option<{}>, {}Nonterminal), Option<{}>>", - terminal_type, self.prefix, terminal_type), + format!("Result<(Option<{}>, {}Nonterminal<{}>), Option<{}>>", + terminal_type, self.prefix, + self.grammar.user_type_parameter_refs(), + terminal_type), vec![])); rust!(self.out, "{{"); - rust!(self.out, "let mut {}result: (Option<{}>, {}Nonterminal);", - self.prefix, terminal_type, self.prefix); + rust!(self.out, "let mut {}result: (Option<{}>, {}Nonterminal<{}>);", + self.prefix, terminal_type, self.prefix, self.grammar.user_type_parameter_refs()); rust!(self.out, "match {}lookahead {{", self.prefix); @@ -224,10 +229,12 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { } // invoke the action code - rust!(self.out, "let {}nt = super::{}action{}({});", + rust!(self.out, "let {}nt = super::{}actions::{}action{}({}{});", + self.prefix, self.prefix, self.prefix, production.action_fn.index(), + self.grammar.user_parameter_refs(), Sep(", ", &transfer_syms)); // wrap up the result along with the (unused) lookahead @@ -320,8 +327,9 @@ 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, lookahead, self.prefix, tokens, Sep(", ", &transfer_syms)) diff --git a/lalrpop/src/normalize/macro_expand/mod.rs b/lalrpop/src/normalize/macro_expand/mod.rs index 8fcfc9e..ffaeee8 100644 --- a/lalrpop/src/normalize/macro_expand/mod.rs +++ b/lalrpop/src/normalize/macro_expand/mod.rs @@ -205,6 +205,10 @@ impl MacroExpander { TypeRef::Lifetime(id), TypeRef::OfSymbol(ref sym) => TypeRef::OfSymbol(sym.clone()), + TypeRef::Ref { lifetime, mutable, ref referent } => + TypeRef::Ref { lifetime: lifetime, + mutable: mutable, + referent: Box::new(self.macro_expand_type_ref(args, referent)) }, TypeRef::Id(id) => { match args.get(&NonterminalString(id)) { Some(sym) => TypeRef::OfSymbol(sym.clone()), diff --git a/lalrpop/src/normalize/tyinfer/mod.rs b/lalrpop/src/normalize/tyinfer/mod.rs index a9d1d63..b897696 100644 --- a/lalrpop/src/normalize/tyinfer/mod.rs +++ b/lalrpop/src/normalize/tyinfer/mod.rs @@ -202,6 +202,11 @@ impl<'grammar> TypeInferencer<'grammar> { Ok(TypeRepr::Nominal(NominalTypeRepr { path: vec![id], types: vec![] })) } + TypeRef::Ref { lifetime, mutable, ref referent } => { + Ok(TypeRepr::Ref { lifetime: lifetime, + mutable: mutable, + referent: Box::new(try!(self.type_ref(referent))) }) + } TypeRef::OfSymbol(ref symbol) => { self.symbol_type(symbol) } diff --git a/lalrpop/src/parser/mod.rs b/lalrpop/src/parser/mod.rs index eb6a4a1..fb92d9f 100644 --- a/lalrpop/src/parser/mod.rs +++ b/lalrpop/src/parser/mod.rs @@ -189,7 +189,8 @@ rusty_peg! { // TypeRef TYPE_REF: TypeRef = - (TUPLE_TYPE_REF / LIFETIME_TYPE_REF / NOMINAL_TYPE_REF / ESCAPE_TYPE_REF); + (TUPLE_TYPE_REF / LIFETIME_TYPE_REF / NOMINAL_TYPE_REF / + REF_TYPE_REF / REF_MUT_TYPE_REF / ESCAPE_TYPE_REF); TUPLE_TYPE_REF: TypeRef = ("(" ")") => TypeRef::Tuple(l); @@ -200,6 +201,16 @@ rusty_peg! { ESCAPE_TYPE_REF: TypeRef = ("`" "`") => TypeRef::OfSymbol(s.kind); + REF_TYPE_REF: TypeRef = + ("&" ) => TypeRef::Ref { lifetime: l, + mutable: false, + referent: Box::new(t) }; + + REF_MUT_TYPE_REF: TypeRef = + ("&" "mut" ) => TypeRef::Ref { lifetime: l, + mutable: true, + referent: Box::new(t) }; + NOMINAL_TYPE_REF: TypeRef = ( ) => { if p.len() == 1 && a.is_none() { @@ -340,7 +351,8 @@ rusty_peg! { ID_RE: &'input str = regex(r"[a-zA-Z_][a-zA-Z0-9_]*") - [ - "if", "use", "where", "token", "grammar", "pub", "struct", "extern", "enum" + "if", "use", "where", "token", "grammar", "pub", "struct", "extern", "enum", + "mut" ]; ESCAPE: InternedString = diff --git a/lalrpop/src/rust/mod.rs b/lalrpop/src/rust/mod.rs index 45a43fa..935c843 100644 --- a/lalrpop/src/rust/mod.rs +++ b/lalrpop/src/rust/mod.rs @@ -86,19 +86,6 @@ impl RustWrite { parameters, return_type, where_clauses) } - pub fn write_fn_header(&mut self, - grammar: &Grammar, - name: String, - type_parameters: Vec, - parameters: Vec, - return_type: String, - where_clauses: Vec) - -> io::Result<()> - { - self.write_fn_header_helper(grammar, "", name, type_parameters, - parameters, return_type, where_clauses) - } - fn write_fn_header_helper(&mut self, grammar: &Grammar, qualifiers: &str,