From a1da099572eaecfd96c59e621b26d398b822dbb8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 15 Jul 2015 09:35:24 -0400 Subject: [PATCH] various annoying things to get macros working --- lalrpop-test/src/expr.rs | 1713 ++++---- lalrpop-test/src/expr_arena.lalrpop | 7 + lalrpop-test/src/expr_arena.rs | 4736 +++++++++++++++------ lalrpop-test/src/expr_arena_ast.rs | 1 + lalrpop-test/src/main.rs | 19 +- lalrpop-test/src/sub.rs | 795 ++-- lalrpop-test/src/util/tok.rs | 2 + lalrpop/src/build/mod.rs | 3 + lalrpop/src/grammar/parse_tree.rs | 63 +- lalrpop/src/grammar/pattern.rs | 18 +- lalrpop/src/grammar/repr.rs | 14 +- lalrpop/src/lr1/ascent.rs | 24 +- lalrpop/src/normalize/macro_expand/mod.rs | 22 +- lalrpop/src/normalize/tyinfer/mod.rs | 10 +- lalrpop/src/parser/mod.rs | 59 +- lalrpop/src/util.rs | 17 + 16 files changed, 4922 insertions(+), 2581 deletions(-) diff --git a/lalrpop-test/src/expr.rs b/lalrpop-test/src/expr.rs index a47b8cb..2e715c7 100644 --- a/lalrpop-test/src/expr.rs +++ b/lalrpop-test/src/expr.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports)] use util::tok::Tok; #[allow(non_snake_case)] @@ -17,14 +18,14 @@ pub fn parse_Expr< } mod __parse__Expr { - #![allow(non_snake_case, unused_mut, unused_variables)] + #![allow(non_snake_case, non_camel_case_types, unused_mut, unused_variables, unused_imports)] use util::tok::Tok; pub enum __Nonterminal<> { - __Expr(i32), Expr(i32), Factor(i32), + __Expr(i32), Term(i32), } @@ -65,12 +66,12 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // __Expr = (*) Expr [EOF] // + // "Num" -> Shift(S4) // "(" -> Shift(S5) - // "Num" -> Shift(S3) // + // Expr -> S3 // Term -> S2 - // Factor -> S4 - // Expr -> S1 + // Factor -> S1 pub fn __state0< __TOKENS: Iterator, >( @@ -81,16 +82,16 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym0 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state4(scale, __lookahead, __tokens, __sym0)); + } Some(__tok @ Tok::LParen(..)) => { let mut __sym0 = &mut Some(__tok); let __lookahead = __tokens.next(); __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); } @@ -98,15 +99,15 @@ mod __parse__Expr { loop { let (__lookahead, __nt) = __result; match __nt { + __Nonterminal::Expr(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state3(scale, __lookahead, __tokens, __sym0)); + } __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!(__state4(scale, __lookahead, __tokens, __sym0)); - } - __Nonterminal::Expr(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state1(scale, __lookahead, __tokens, __sym0)); } @@ -118,17 +119,25 @@ 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] + // 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(S6) - // "+" -> Shift(S7) - // EOF -> Reduce(__Expr = Expr => ActionFn(0);) + // "*" -> Shift(S7) + // EOF -> Reduce(Expr = Factor => ActionFn(3);) + // "/" -> Shift(S6) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) // pub fn __state1< __TOKENS: Iterator, @@ -141,20 +150,30 @@ mod __parse__Expr { { 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(..)) => { + Some(__tok @ Tok::Times(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); __result = try!(__state7(scale, __lookahead, __tokens, __sym0, __sym1)); } + Some(__tok @ Tok::Div(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state6(scale, __lookahead, __tokens, __sym0, __sym1)); + } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action0(scale, __sym0); - return Ok((__lookahead, __Nonterminal::__Expr(__nt))); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -170,11 +189,11 @@ mod __parse__Expr { // Factor = Term (*) ["-"] // Factor = Term (*) ["/"] // - // EOF -> 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);) // "/" -> Reduce(Factor = Term => ActionFn(6);) - // "*" -> Reduce(Factor = Term => ActionFn(6);) // pub fn __state2< __TOKENS: Iterator, @@ -187,12 +206,17 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } None => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action6(scale, __sym0); return Ok((__lookahead, __Nonterminal::Factor(__nt))); } - Some(Tok::Plus(..)) => { + Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action6(scale, __sym0); return Ok((__lookahead, __Nonterminal::Factor(__nt))); @@ -207,11 +231,6 @@ mod __parse__Expr { 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); } @@ -219,17 +238,17 @@ mod __parse__Expr { } // State 3 - // Term = "Num" (*) [EOF] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] + // 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(Term = "Num" => ActionFn(7);) - // "-" -> Reduce(Term = "Num" => ActionFn(7);) - // "+" -> Reduce(Term = "Num" => ActionFn(7);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Shift(S8) + // "+" -> Shift(S9) + // EOF -> Reduce(__Expr = Expr => ActionFn(0);) // pub fn __state3< __TOKENS: Iterator, @@ -242,26 +261,72 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(scale, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state9(scale, __lookahead, __tokens, __sym0, __sym1)); + } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__actions::__action0(scale, __sym0); + return Ok((__lookahead, __Nonterminal::__Expr(__nt))); } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(scale, __sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + _ => { + return Err(__lookahead); } + } + return Ok(__result); + } + + // State 4 + // Term = "Num" (*) [EOF] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // EOF -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // + 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::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action7(scale, __sym0); return Ok((__lookahead, __Nonterminal::Term(__nt))); } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action7(scale, __sym0); return Ok((__lookahead, __Nonterminal::Term(__nt))); } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action7(scale, __sym0); @@ -273,70 +338,6 @@ mod __parse__Expr { } } - // 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 ["+"] @@ -378,12 +379,12 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S10) - // "(" -> Shift(S12) + // "(" -> Shift(S10) + // "Num" -> Shift(S12) // + // Factor -> S13 + // Expr -> S14 // Term -> S11 - // Factor -> S14 - // Expr -> S13 pub fn __state5< __TOKENS: Iterator, >( @@ -395,13 +396,13 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym1 = &mut Some((__tok0)); + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); __result = try!(__state10(scale, __lookahead, __tokens, __sym1)); } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym1 = &mut Some(__tok); + Some(Tok::Num(__tok0)) => { + let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); __result = try!(__state12(scale, __lookahead, __tokens, __sym1)); } @@ -412,17 +413,17 @@ mod __parse__Expr { while __sym0.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Term(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state11(scale, __lookahead, __tokens, __sym1)); - } __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state14(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state13(scale, __lookahead, __tokens, __sym1)); } __Nonterminal::Expr(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state13(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state14(scale, __lookahead, __tokens, __sym0, __sym1)); + } + __Nonterminal::Term(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state11(scale, __lookahead, __tokens, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -433,6 +434,130 @@ mod __parse__Expr { } // State 6 + // 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(S4) + // "(" -> Shift(S5) + // + // Term -> S15 + pub fn __state6< + __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::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state4(scale, __lookahead, __tokens, __sym2)); + } + 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::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state15(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 7 + // 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(S4) + // + // Term -> 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<>); + 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!(__state4(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!(__state16(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 8 // Expr = Expr "-" (*) Factor [EOF] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -462,12 +587,12 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S3) // "(" -> Shift(S5) + // "Num" -> Shift(S4) // - // Factor -> S15 + // Factor -> S17 // Term -> S2 - pub fn __state6< + pub fn __state8< __TOKENS: Iterator, >( scale: i32, @@ -479,16 +604,16 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state3(scale, __lookahead, __tokens, __sym2)); - } 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!(__state4(scale, __lookahead, __tokens, __sym2)); + } _ => { return Err(__lookahead); } @@ -498,7 +623,7 @@ mod __parse__Expr { match __nt { __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state15(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state17(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); } __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); @@ -512,7 +637,7 @@ mod __parse__Expr { return Ok(__result); } - // State 7 + // State 9 // Expr = Expr "+" (*) Factor [EOF] // Expr = Expr "+" (*) Factor ["+"] // Expr = Expr "+" (*) Factor ["-"] @@ -542,139 +667,11 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S3) // "(" -> Shift(S5) + // "Num" -> Shift(S4) // + // Factor -> S18 // 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<>); - match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state3(scale, __lookahead, __tokens, __sym2)); - } - 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::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, >( @@ -695,7 +692,7 @@ mod __parse__Expr { Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state3(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state4(scale, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -704,10 +701,14 @@ mod __parse__Expr { while __sym1.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Term(__nt) => { + __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); __result = try!(__state18(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)); } @@ -717,116 +718,6 @@ mod __parse__Expr { } // 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 ["-"] @@ -867,13 +758,13 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S10) - // "(" -> Shift(S12) + // "(" -> Shift(S10) + // "Num" -> Shift(S12) // - // Factor -> S14 - // Term -> S11 // Expr -> S19 - pub fn __state12< + // Term -> S11 + // Factor -> S13 + pub fn __state10< __TOKENS: Iterator, >( scale: i32, @@ -884,13 +775,13 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym1 = &mut Some((__tok0)); + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); __result = try!(__state10(scale, __lookahead, __tokens, __sym1)); } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym1 = &mut Some(__tok); + Some(Tok::Num(__tok0)) => { + let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); __result = try!(__state12(scale, __lookahead, __tokens, __sym1)); } @@ -901,17 +792,17 @@ mod __parse__Expr { while __sym0.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Factor(__nt) => { + __Nonterminal::Expr(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state14(scale, __lookahead, __tokens, __sym1)); + __result = try!(__state19(scale, __lookahead, __tokens, __sym0, __sym1)); } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); __result = try!(__state11(scale, __lookahead, __tokens, __sym1)); } - __Nonterminal::Expr(__nt) => { + __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state19(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state13(scale, __lookahead, __tokens, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -921,58 +812,117 @@ mod __parse__Expr { return Ok(__result); } - // 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 (*) ")" ["/"] + // State 11 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] // - // ")" -> Shift(S22) - // "+" -> Shift(S21) - // "-" -> Shift(S20) + // "+" -> 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 __state13< + pub fn __state11< __TOKENS: Iterator, >( scale: i32, mut __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, + __sym0: &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::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } - Some(__tok @ Tok::Plus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state21(scale, __lookahead, __tokens, __sym1, __sym2)); + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state20(scale, __lookahead, __tokens, __sym1, __sym2)); + 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::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action6(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); } } - return Ok(__result); } - // State 14 + // State 12 + // 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 __state12< + __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::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(scale, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 13 // Expr = Factor (*) [")"] // Expr = Factor (*) ["+"] // Expr = Factor (*) ["-"] @@ -988,12 +938,12 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["/"] // // "-" -> Reduce(Expr = Factor => ActionFn(3);) - // "*" -> Shift(S24) // ")" -> Reduce(Expr = Factor => ActionFn(3);) // "+" -> Reduce(Expr = Factor => ActionFn(3);) - // "/" -> Shift(S23) + // "*" -> Shift(S21) + // "/" -> Shift(S20) // - pub fn __state14< + pub fn __state13< __TOKENS: Iterator, >( scale: i32, @@ -1007,12 +957,12 @@ mod __parse__Expr { Some(__tok @ Tok::Times(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state24(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state21(scale, __lookahead, __tokens, __sym0, __sym1)); } Some(__tok @ Tok::Div(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state23(scale, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state20(scale, __lookahead, __tokens, __sym0, __sym1)); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); @@ -1036,26 +986,69 @@ mod __parse__Expr { 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 ["/"] + // State 14 + // 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 (*) ")" ["/"] // - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S9) - // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "*" -> Shift(S8) + // "-" -> Shift(S24) + // "+" -> Shift(S22) + // ")" -> Shift(S23) + // + pub fn __state14< + __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!(__state24(scale, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state22(scale, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state23(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 15 + // Factor = Factor "/" Term (*) [EOF] + // 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);) + // EOF -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) // pub fn __state15< __TOKENS: Iterator, @@ -1070,64 +1063,59 @@ mod __parse__Expr { { 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::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + 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::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))); + 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))); } 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))); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__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 ["/"] + // Factor = Factor "*" Term (*) [EOF] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] // - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "/" -> Shift(S9) - // "*" -> Shift(S8) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // 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);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // pub fn __state16< __TOKENS: Iterator, @@ -1142,56 +1130,67 @@ mod __parse__Expr { { 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(..)) => { + None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } - None => { + Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__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 (*) ["/"] + // 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(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);) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "*" -> Shift(S7) + // "/" -> Shift(S6) + // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // pub fn __state17< __TOKENS: Iterator, @@ -1206,59 +1205,64 @@ mod __parse__Expr { { 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 @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state7(scale, __lookahead, __tokens, __sym2, __sym3)); } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::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 @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state6(scale, __lookahead, __tokens, __sym2, __sym3)); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + 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::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + 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))); } _ => { return Err(__lookahead); } } + return Ok(__result); } // State 18 - // Factor = Factor "/" Term (*) [EOF] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] + // Expr = Expr "+" Factor (*) [EOF] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "/" -> 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);) + // "/" -> Shift(S6) + // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S7) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // pub fn __state18< __TOKENS: Iterator, @@ -1273,45 +1277,42 @@ mod __parse__Expr { { 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))); + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state6(scale, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state7(scale, __lookahead, __tokens, __sym2, __sym3)); } None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__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))); + 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::__action5(scale, __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::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); } } + return Ok(__result); } // State 19 @@ -1327,9 +1328,9 @@ mod __parse__Expr { // Term = "(" Expr (*) ")" ["-"] // Term = "(" Expr (*) ")" ["/"] // - // "-" -> Shift(S20) + // "+" -> Shift(S22) + // "-" -> Shift(S24) // ")" -> Shift(S25) - // "+" -> Shift(S21) // pub fn __state19< __TOKENS: Iterator, @@ -1343,21 +1344,21 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state22(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)); + __result = try!(__state24(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); } @@ -1366,24 +1367,11 @@ mod __parse__Expr { } // State 20 - // Expr = Expr "-" (*) Factor [")"] - // Expr = Expr "-" (*) Factor ["+"] - // Expr = Expr "-" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [")"] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [")"] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [")"] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] + // Factor = Factor "/" (*) Term [")"] + // Factor = Factor "/" (*) Term ["*"] + // Factor = Factor "/" (*) Term ["+"] + // Factor = Factor "/" (*) Term ["-"] + // Factor = Factor "/" (*) Term ["/"] // Term = (*) "(" Expr ")" [")"] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -1395,11 +1383,10 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S10) - // "(" -> Shift(S12) + // "Num" -> Shift(S12) + // "(" -> Shift(S10) // - // Term -> S11 - // Factor -> S26 + // Term -> S26 pub fn __state20< __TOKENS: Iterator, >( @@ -1415,12 +1402,12 @@ mod __parse__Expr { Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); } Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1430,10 +1417,6 @@ mod __parse__Expr { let (__lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state11(scale, __lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); __result = try!(__state26(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); } @@ -1446,6 +1429,68 @@ mod __parse__Expr { } // State 21 + // Factor = Factor "*" (*) Term [")"] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S12) + // "(" -> Shift(S10) + // + // Term -> S27 + 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<>); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state10(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!(__state27(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 22 // Expr = Expr "+" (*) Factor [")"] // Expr = Expr "+" (*) Factor ["+"] // Expr = Expr "+" (*) Factor ["-"] @@ -1475,12 +1520,12 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S12) - // "Num" -> Shift(S10) + // "(" -> Shift(S10) + // "Num" -> Shift(S12) // - // Factor -> S27 + // Factor -> S28 // Term -> S11 - pub fn __state21< + pub fn __state22< __TOKENS: Iterator, >( scale: i32, @@ -1495,12 +1540,12 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state10(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)); + __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1511,7 +1556,7 @@ mod __parse__Expr { match __nt { __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state27(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state28(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); } __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); @@ -1525,20 +1570,20 @@ mod __parse__Expr { return Ok(__result); } - // State 22 + // State 23 // 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);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // - pub fn __state22< + pub fn __state23< __TOKENS: Iterator, >( scale: i32, @@ -1551,7 +1596,14 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { - None => { + 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(); @@ -1572,14 +1624,7 @@ mod __parse__Expr { 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(..)) => { + None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); @@ -1592,74 +1637,25 @@ mod __parse__Expr { } } - // State 23 - // 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) - // "Num" -> Shift(S10) - // - // 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<>); - match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __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); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state28(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - // State 24 - // Factor = Factor "*" (*) Term [")"] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] + // 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 ")" ["+"] @@ -1671,10 +1667,11 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S10) - // "(" -> Shift(S12) + // "Num" -> Shift(S12) + // "(" -> Shift(S10) // - // Term -> S29 + // Term -> S11 + // Factor -> S29 pub fn __state24< __TOKENS: Iterator, >( @@ -1690,12 +1687,12 @@ mod __parse__Expr { Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); } Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state12(scale, __lookahead, __tokens, __sym2)); + __result = try!(__state10(scale, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1705,6 +1702,10 @@ mod __parse__Expr { let (__lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state11(scale, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); __result = try!(__state29(scale, __lookahead, __tokens, __sym0, __sym1, __sym2)); } @@ -1723,11 +1724,11 @@ mod __parse__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);) - // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // pub fn __state25< __TOKENS: Iterator, @@ -1742,6 +1743,13 @@ mod __parse__Expr { { 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::__action8(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); @@ -1770,13 +1778,6 @@ mod __parse__Expr { 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); } @@ -1784,25 +1785,17 @@ mod __parse__Expr { } // State 26 - // Expr = Expr "-" Factor (*) [")"] - // Expr = Expr "-" Factor (*) ["+"] - // Expr = Expr "-" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] + // Factor = Factor "/" Term (*) [")"] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] // - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S23) - // "*" -> Shift(S24) - // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> 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 __state26< __TOKENS: Iterator, @@ -1817,64 +1810,59 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state23(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::__actions::__action5(scale, __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::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::__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::__actions::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + 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::__action1(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); } } - return Ok(__result); } // State 27 - // Expr = Expr "+" Factor (*) [")"] - // Expr = Expr "+" Factor (*) ["+"] - // Expr = Expr "+" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] + // Factor = Factor "*" Term (*) [")"] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] // - // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "*" -> Shift(S24) - // "/" -> Shift(S23) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "-" -> 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 __state27< __TOKENS: Iterator, @@ -1889,56 +1877,67 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state24(scale, __lookahead, __tokens, __sym2, __sym3)); - } - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state23(scale, __lookahead, __tokens, __sym2, __sym3)); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + 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::__action2(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + 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::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); } } - return Ok(__result); } // State 28 - // Factor = Factor "/" Term (*) [")"] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] + // 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(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);) + // "*" -> Shift(S21) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "/" -> Shift(S20) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // pub fn __state28< __TOKENS: Iterator, @@ -1953,59 +1952,64 @@ mod __parse__Expr { { 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 @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(scale, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state20(scale, __lookahead, __tokens, __sym2, __sym3)); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(scale, __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::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); } } + return Ok(__result); } // State 29 - // Factor = Factor "*" Term (*) [")"] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] + // 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(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);) + // "*" -> Shift(S21) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S20) + // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // pub fn __state29< __TOKENS: Iterator, @@ -2020,45 +2024,42 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<>); match __lookahead { + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(scale, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state20(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::__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))); + 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::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } - Some(Tok::Div(..)) => { + Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action4(scale, __sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__actions::__action1(scale, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); } } + return Ok(__result); } } diff --git a/lalrpop-test/src/expr_arena.lalrpop b/lalrpop-test/src/expr_arena.lalrpop index b3a7c26..ed6f54a 100644 --- a/lalrpop-test/src/expr_arena.lalrpop +++ b/lalrpop-test/src/expr_arena.lalrpop @@ -11,6 +11,7 @@ extern token { "+" => Tok::Plus(..), "*" => Tok::Times(..), "/" => Tok::Div(..), + "," => Tok::Comma(..), "Num" => Tok::Num() } } @@ -21,9 +22,15 @@ pub Expr: &'ast Node<'ast> = { Factor; }; +Comma: Vec = { + ",")*> => + h.into_iter().chain(t).collect(); +}; + Factor = { "*" => arena.alloc(Node::Binary(Op::Mul, l, r)); "/" => arena.alloc(Node::Binary(Op::Div, l, r)); + "*" "(" > ")" => arena.alloc(Node::Reduce(Op::Mul, <>)); Term; }; diff --git a/lalrpop-test/src/expr_arena.rs b/lalrpop-test/src/expr_arena.rs index 1669fe4..89642fe 100644 --- a/lalrpop-test/src/expr_arena.rs +++ b/lalrpop-test/src/expr_arena.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports)] use expr_arena_ast::{Arena, Node, Op}; use util::tok::Tok; @@ -19,16 +20,20 @@ pub fn parse_Expr< } mod __parse__Expr { - #![allow(non_snake_case, unused_mut, unused_variables)] + #![allow(non_snake_case, non_camel_case_types, unused_mut, unused_variables, unused_imports)] 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>), + Expr_(::std::option::Option<&'ast Node<'ast>>), + __Expr_______(::std::vec::Vec<&'ast Node<'ast>>), + Comma_Expr_(Vec<&'ast Node<'ast>>), + __Expr(&'ast Node<'ast>), + __Expr______(&'ast Node<'ast>), } // State 0 @@ -56,6 +61,11 @@ mod __parse__Expr { // Factor = (*) Term ["+"] // Factor = (*) Term ["-"] // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [EOF] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] // Term = (*) "(" Expr ")" [EOF] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -68,12 +78,13 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // __Expr = (*) Expr [EOF] // - // "Num" -> Shift(S3) - // "(" -> Shift(S4) + // "*" -> Shift(S5) + // "Num" -> Shift(S1) + // "(" -> Shift(S3) // - // Expr -> S1 - // Factor -> S5 + // Expr -> S6 // Term -> S2 + // Factor -> S4 pub fn __state0< 'ast, __TOKENS: Iterator, @@ -85,15 +96,20 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<'ast, >); match __lookahead { + Some(__tok @ Tok::Times(..)) => { + let mut __sym0 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state5(arena, __lookahead, __tokens, __sym0)); + } Some(Tok::Num(__tok0)) => { let mut __sym0 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state3(arena, __lookahead, __tokens, __sym0)); + __result = try!(__state1(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)); + __result = try!(__state3(arena, __lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); @@ -104,16 +120,16 @@ mod __parse__Expr { 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)); + __result = try!(__state6(arena, __lookahead, __tokens, __sym0)); } __Nonterminal::Term(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state2(arena, __lookahead, __tokens, __sym0)); } + __Nonterminal::Factor(__nt) => { + let __sym0 = &mut Some(__nt); + __result = try!(__state4(arena, __lookahead, __tokens, __sym0)); + } _ => { return Ok((__lookahead, __nt)); } @@ -122,122 +138,19 @@ 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< - '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);) + // "*" -> Reduce(Term = "Num" => ActionFn(8);) + // EOF -> Reduce(Term = "Num" => ActionFn(8);) + // "/" -> Reduce(Term = "Num" => ActionFn(8);) + // "-" -> Reduce(Term = "Num" => ActionFn(8);) + // "+" -> Reduce(Term = "Num" => ActionFn(8);) // - pub fn __state3< + pub fn __state1< 'ast, __TOKENS: Iterator, >( @@ -251,27 +164,27 @@ mod __parse__Expr { 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); + let __nt = super::__actions::__action8(arena, __sym0); return Ok((__lookahead, __Nonterminal::Term(__nt))); } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); return Ok((__lookahead, __Nonterminal::Term(__nt))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action7(arena, __sym0); + let __nt = super::__actions::__action8(arena, __sym0); return Ok((__lookahead, __Nonterminal::Term(__nt))); } _ => { @@ -280,7 +193,63 @@ mod __parse__Expr { } } - // State 4 + // State 2 + // Factor = Term (*) [EOF] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "-" -> Reduce(Factor = Term => ActionFn(7);) + // "*" -> Reduce(Factor = Term => ActionFn(7);) + // EOF -> Reduce(Factor = Term => ActionFn(7);) + // "+" -> Reduce(Factor = Term => ActionFn(7);) + // "/" -> Reduce(Factor = Term => ActionFn(7);) + // + 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::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 3 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -305,6 +274,11 @@ mod __parse__Expr { // Factor = (*) Term ["+"] // Factor = (*) Term ["-"] // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] // Term = (*) "(" Expr ")" [")"] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -321,13 +295,14 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S8) - // "Num" -> Shift(S9) + // "(" -> Shift(S12) + // "*" -> Shift(S8) + // "Num" -> Shift(S10) // - // Expr -> S12 - // Term -> S11 - // Factor -> S10 - pub fn __state4< + // Factor -> S7 + // Term -> S9 + // Expr -> S11 + pub fn __state3< 'ast, __TOKENS: Iterator, >( @@ -340,6 +315,11 @@ mod __parse__Expr { let mut __result: (Option, __Nonterminal<'ast, >); match __lookahead { Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(arena, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::Times(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); __result = try!(__state8(arena, __lookahead, __tokens, __sym1)); @@ -347,7 +327,7 @@ mod __parse__Expr { Some(Tok::Num(__tok0)) => { let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state9(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state10(arena, __lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); @@ -356,17 +336,17 @@ mod __parse__Expr { while __sym0.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Expr(__nt) => { + __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state12(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state7(arena, __lookahead, __tokens, __sym1)); } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state11(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state9(arena, __lookahead, __tokens, __sym1)); } - __Nonterminal::Factor(__nt) => { + __Nonterminal::Expr(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state10(arena, __lookahead, __tokens, __sym1)); + __result = try!(__state11(arena, __lookahead, __tokens, __sym0, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -376,7 +356,7 @@ mod __parse__Expr { return Ok(__result); } - // State 5 + // State 4 // Expr = Factor (*) [EOF] // Expr = Factor (*) ["+"] // Expr = Factor (*) ["-"] @@ -391,13 +371,13 @@ mod __parse__Expr { // 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) + // "*" -> Shift(S13) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "/" -> Shift(S14) + // EOF -> Reduce(Expr = Factor => ActionFn(3);) // - pub fn __state5< + pub fn __state4< 'ast, __TOKENS: Iterator, >( @@ -412,14 +392,14 @@ mod __parse__Expr { Some(__tok @ Tok::Times(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state14(arena, __lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state13(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)); + __result = try!(__state14(arena, __lookahead, __tokens, __sym0, __sym1)); } - None => { + Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(arena, __sym0); return Ok((__lookahead, __Nonterminal::Expr(__nt))); @@ -429,7 +409,7 @@ mod __parse__Expr { let __nt = super::__actions::__action3(arena, __sym0); return Ok((__lookahead, __Nonterminal::Expr(__nt))); } - Some(Tok::Plus(..)) => { + None => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__actions::__action3(arena, __sym0); return Ok((__lookahead, __Nonterminal::Expr(__nt))); @@ -441,25 +421,461 @@ mod __parse__Expr { return Ok(__result); } + // State 5 + // Factor = "*" (*) "(" Comma ")" [EOF] + // Factor = "*" (*) "(" Comma ")" ["*"] + // Factor = "*" (*) "(" Comma ")" ["+"] + // Factor = "*" (*) "(" Comma ")" ["-"] + // Factor = "*" (*) "(" Comma ")" ["/"] + // + // "(" -> Shift(S15) + // + pub fn __state5< + '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!(__state15(arena, __lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + // State 6 - // Expr = Expr "+" (*) Factor [EOF] - // Expr = Expr "+" (*) Factor ["+"] - // Expr = Expr "+" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] + // 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(S16) + // "+" -> Shift(S17) + // + pub fn __state6< + '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::Minus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state16(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state17(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 7 + // Expr = Factor (*) [")"] + // Expr = Factor (*) ["+"] + // Expr = Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "*" -> Shift(S18) + // "/" -> Shift(S19) + // ")" -> Reduce(Expr = Factor => ActionFn(3);) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // + pub fn __state7< + '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!(__state18(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state19(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + 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))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 8 + // Factor = "*" (*) "(" Comma ")" [")"] + // Factor = "*" (*) "(" Comma ")" ["*"] + // Factor = "*" (*) "(" Comma ")" ["+"] + // Factor = "*" (*) "(" Comma ")" ["-"] + // Factor = "*" (*) "(" Comma ")" ["/"] + // + // "(" -> Shift(S20) + // + 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 @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state20(arena, __lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 9 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "-" -> Reduce(Factor = Term => ActionFn(7);) + // "*" -> Reduce(Factor = Term => ActionFn(7);) + // ")" -> Reduce(Factor = Term => ActionFn(7);) + // "/" -> Reduce(Factor = Term => ActionFn(7);) + // "+" -> Reduce(Factor = Term => ActionFn(7);) + // + pub fn __state9< + '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::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 10 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "/" -> Reduce(Term = "Num" => ActionFn(8);) + // "+" -> Reduce(Term = "Num" => ActionFn(8);) + // ")" -> Reduce(Term = "Num" => ActionFn(8);) + // "-" -> Reduce(Term = "Num" => ActionFn(8);) + // "*" -> Reduce(Term = "Num" => ActionFn(8);) + // + pub fn __state10< + '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::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 11 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [EOF] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // "-" -> Shift(S21) + // ")" -> Shift(S22) + // "+" -> Shift(S23) + // + pub fn __state11< + '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::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(arena, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state22(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state23(arena, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 12 + // 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 [EOF] + // Factor = (*) Factor "/" Term [")"] // Factor = (*) Factor "/" Term ["*"] // Factor = (*) Factor "/" Term ["+"] // Factor = (*) Factor "/" Term ["-"] // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] + // Factor = (*) Term [")"] // Factor = (*) Term ["*"] // Factor = (*) Term ["+"] // Factor = (*) Term ["-"] // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = "(" (*) Expr ")" [")"] + // Term = "(" (*) Expr ")" ["*"] + // Term = "(" (*) Expr ")" ["+"] + // Term = "(" (*) Expr ")" ["-"] + // Term = "(" (*) Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S12) + // "*" -> Shift(S8) + // "Num" -> Shift(S10) + // + // Term -> S9 + // Expr -> S24 + // Factor -> S7 + pub fn __state12< + '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!(__state12(arena, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::Times(..)) => { + 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!(__state10(arena, __lookahead, __tokens, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + while __sym0.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state9(arena, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state24(arena, __lookahead, __tokens, __sym0, __sym1)); + } + __Nonterminal::Factor(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state7(arena, __lookahead, __tokens, __sym1)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + 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 ")" ["+"] @@ -471,12 +887,11 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S3) - // "(" -> Shift(S4) + // "(" -> Shift(S3) + // "Num" -> Shift(S1) // - // Factor -> S15 - // Term -> S2 - pub fn __state6< + // Term -> S25 + pub fn __state13< 'ast, __TOKENS: Iterator, >( @@ -489,15 +904,15 @@ mod __parse__Expr { { 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)); + __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -506,13 +921,9 @@ mod __parse__Expr { 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)); + __result = try!(__state25(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -522,7 +933,145 @@ mod __parse__Expr { return Ok(__result); } - // State 7 + // 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" ["/"] + // + // "(" -> Shift(S3) + // "Num" -> Shift(S1) + // + // Term -> S26 + 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 @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state26(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 15 + // ( ",")* = (*) ["("] + // ( ",")* = (*) [")"] + // ( ",")* = (*) ["*"] + // ( ",")* = (*) ["Num"] + // ( ",")* = (*) ( ",")* ( ",") ["("] + // ( ",")* = (*) ( ",")* ( ",") [")"] + // ( ",")* = (*) ( ",")* ( ",") ["*"] + // ( ",")* = (*) ( ",")* ( ",") ["Num"] + // Comma = (*) ( ",")* Expr? [")"] + // Factor = "*" "(" (*) Comma ")" [EOF] + // Factor = "*" "(" (*) Comma ")" ["*"] + // Factor = "*" "(" (*) Comma ")" ["+"] + // Factor = "*" "(" (*) Comma ")" ["-"] + // Factor = "*" "(" (*) Comma ")" ["/"] + // + // "(" -> Reduce(( ",")* = => ActionFn(13);) + // "*" -> Reduce(( ",")* = => ActionFn(13);) + // "Num" -> Reduce(( ",")* = => ActionFn(13);) + // ")" -> Reduce(( ",")* = => ActionFn(13);) + // + // ( ",")* -> S27 + // Comma -> S28 + pub fn __state15< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::LParen(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::Times(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::Num(_)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::RParen(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::__Expr_______(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state27(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Comma_Expr_(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state28(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 16 // Expr = Expr "-" (*) Factor [EOF] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -541,6 +1090,11 @@ mod __parse__Expr { // Factor = (*) Term ["+"] // Factor = (*) Term ["-"] // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [EOF] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] // Term = (*) "(" Expr ")" [EOF] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -552,12 +1106,13 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S3) - // "(" -> Shift(S4) + // "(" -> Shift(S3) + // "Num" -> Shift(S1) + // "*" -> Shift(S5) // // Term -> S2 - // Factor -> S16 - pub fn __state7< + // Factor -> S29 + pub fn __state16< 'ast, __TOKENS: Iterator, >( @@ -570,15 +1125,20 @@ mod __parse__Expr { { 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)); + __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state5(arena, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -593,7 +1153,7 @@ mod __parse__Expr { } __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state16(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state29(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -603,620 +1163,47 @@ mod __parse__Expr { 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 (*) ")" ["/"] + // Expr = Expr "+" (*) Factor [EOF] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [EOF] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] // - // ")" -> Shift(S25) - // "+" -> Shift(S21) - // "-" -> Shift(S22) + // "(" -> Shift(S3) + // "Num" -> Shift(S1) + // "*" -> Shift(S5) // + // Factor -> S30 + // Term -> S2 pub fn __state17< 'ast, __TOKENS: Iterator, @@ -1224,31 +1211,47 @@ mod __parse__Expr { arena: &'ast Arena<'ast>, mut __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option<&'ast Node<'ast>>, + __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::RParen(..)) => { + Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state25(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state3(arena, __lookahead, __tokens, __sym2)); } - 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!(__state21(arena, __lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state1(arena, __lookahead, __tokens, __sym2)); } - Some(__tok @ Tok::Minus(..)) => { + Some(__tok @ Tok::Times(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state22(arena, __lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state5(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!(__state30(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); } @@ -1269,10 +1272,10 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S8) - // "Num" -> Shift(S9) + // "(" -> Shift(S12) + // "Num" -> Shift(S10) // - // Term -> S26 + // Term -> S31 pub fn __state18< 'ast, __TOKENS: Iterator, @@ -1289,12 +1292,12 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state8(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state12(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)); + __result = try!(__state10(arena, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1305,7 +1308,7 @@ mod __parse__Expr { match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state26(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state31(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1332,10 +1335,10 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S9) - // "(" -> Shift(S8) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) // - // Term -> S27 + // Term -> S32 pub fn __state19< 'ast, __TOKENS: Iterator, @@ -1352,12 +1355,12 @@ mod __parse__Expr { Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state9(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state10(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)); + __result = try!(__state12(arena, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1368,7 +1371,7 @@ mod __parse__Expr { match __nt { __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state27(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state32(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1379,18 +1382,28 @@ mod __parse__Expr { } // State 20 - // Term = "(" Expr ")" (*) [EOF] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] + // ( ",")* = (*) ["("] + // ( ",")* = (*) [")"] + // ( ",")* = (*) ["*"] + // ( ",")* = (*) ["Num"] + // ( ",")* = (*) ( ",")* ( ",") ["("] + // ( ",")* = (*) ( ",")* ( ",") [")"] + // ( ",")* = (*) ( ",")* ( ",") ["*"] + // ( ",")* = (*) ( ",")* ( ",") ["Num"] + // Comma = (*) ( ",")* Expr? [")"] + // Factor = "*" "(" (*) Comma ")" [")"] + // Factor = "*" "(" (*) Comma ")" ["*"] + // Factor = "*" "(" (*) Comma ")" ["+"] + // Factor = "*" "(" (*) Comma ")" ["-"] + // Factor = "*" "(" (*) Comma ")" ["/"] // - // "-" -> 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);) + // "(" -> Reduce(( ",")* = => ActionFn(13);) + // "*" -> Reduce(( ",")* = => ActionFn(13);) + // "Num" -> Reduce(( ",")* = => ActionFn(13);) + // ")" -> Reduce(( ",")* = => ActionFn(13);) // + // ( ",")* -> S27 + // Comma -> S33 pub fn __state20< 'ast, __TOKENS: Iterator, @@ -1399,110 +1412,26 @@ mod __parse__Expr { 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::LParen(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state9(arena, __lookahead, __tokens, __sym2)); + Some(Tok::Times(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::Num(_)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::RParen(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); } _ => { return Err(__lookahead); @@ -1511,13 +1440,13 @@ mod __parse__Expr { while __sym1.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Term(__nt) => { + __Nonterminal::__Expr_______(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state11(arena, __lookahead, __tokens, __sym2)); + __result = try!(__state27(arena, __lookahead, __tokens, __sym2)); } - __Nonterminal::Factor(__nt) => { + __Nonterminal::Comma_Expr_(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state28(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state33(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1527,7 +1456,7 @@ mod __parse__Expr { return Ok(__result); } - // State 22 + // State 21 // Expr = Expr "-" (*) Factor [")"] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -1546,6 +1475,11 @@ mod __parse__Expr { // Factor = (*) Term ["+"] // Factor = (*) Term ["-"] // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] // Term = (*) "(" Expr ")" [")"] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -1557,12 +1491,13 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S9) - // "(" -> Shift(S8) + // "*" -> Shift(S8) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) // - // Term -> S11 - // Factor -> S29 - pub fn __state22< + // Factor -> S34 + // Term -> S9 + pub fn __state21< 'ast, __TOKENS: Iterator, >( @@ -1575,15 +1510,20 @@ mod __parse__Expr { { let mut __result: (Option, __Nonterminal<'ast, >); match __lookahead { + Some(__tok @ Tok::Times(..)) => { + 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)); + __result = try!(__state10(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)); + __result = try!(__state12(arena, __lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1592,13 +1532,13 @@ mod __parse__Expr { 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)); + __result = try!(__state34(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state9(arena, __lookahead, __tokens, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1608,156 +1548,20 @@ mod __parse__Expr { 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 ")" (*) [")"] + // State 22 + // 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);) - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) // - pub fn __state25< + pub fn __state22< 'ast, __TOKENS: Iterator, >( @@ -1775,35 +1579,35 @@ mod __parse__Expr { 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); + let __nt = super::__actions::__action9(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); + let __nt = super::__actions::__action9(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::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::Term(__nt))); } _ => { @@ -1812,18 +1616,230 @@ mod __parse__Expr { } } - // State 26 - // Factor = Factor "*" Term (*) [")"] + // State 23 + // Expr = Expr "+" (*) Factor [")"] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [")"] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [")"] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "*" -> Shift(S8) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) + // + // Term -> S9 + // Factor -> S35 + 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, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::Times(..)) => { + 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!(__state10(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(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!(__state9(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state35(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 24 + // 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(S23) + // "-" -> Shift(S21) + // ")" -> Shift(S36) + // + pub fn __state24< + '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::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state23(arena, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(arena, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state36(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 25 + // 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);) // "/" -> 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 __state25< + '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::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::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::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::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 26 + // Factor = Factor "/" Term (*) [EOF] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> 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);) // pub fn __state26< 'ast, @@ -1839,39 +1855,39 @@ mod __parse__Expr { { 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); + 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::__action4(arena, __sym0, __sym1, __sym2); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + 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))); } _ => { @@ -1881,18 +1897,76 @@ mod __parse__Expr { } // State 27 - // Factor = Factor "/" Term (*) [")"] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] + // ( ",") = (*) Expr "," ["("] + // ( ",") = (*) Expr "," [")"] + // ( ",") = (*) Expr "," ["*"] + // ( ",") = (*) Expr "," ["Num"] + // ( ",")* = ( ",")* (*) ( ",") ["("] + // ( ",")* = ( ",")* (*) ( ",") [")"] + // ( ",")* = ( ",")* (*) ( ",") ["*"] + // ( ",")* = ( ",")* (*) ( ",") ["Num"] + // Comma = ( ",")* (*) Expr? [")"] + // Expr = (*) Expr "+" Factor [")"] + // Expr = (*) Expr "+" Factor ["+"] + // Expr = (*) Expr "+" Factor [","] + // Expr = (*) Expr "+" Factor ["-"] + // Expr = (*) Expr "-" Factor [")"] + // Expr = (*) Expr "-" Factor ["+"] + // Expr = (*) Expr "-" Factor [","] + // Expr = (*) Expr "-" Factor ["-"] + // Expr = (*) Factor [")"] + // Expr = (*) Factor ["+"] + // Expr = (*) Factor [","] + // Expr = (*) Factor ["-"] + // Expr? = (*) [")"] + // Expr? = (*) Expr [")"] + // Factor = (*) Factor "*" Term [")"] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term [","] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [")"] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term [","] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term [","] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" [","] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" [","] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" [","] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] // - // "+" -> 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(Expr? = => ActionFn(12);) + // "(" -> Shift(S39) + // "*" -> Shift(S37) + // "Num" -> Shift(S41) // + // Term -> S40 + // Expr? -> S38 + // ( ",") -> S42 + // Factor -> S44 + // Expr -> S43 pub fn __state27< 'ast, __TOKENS: Iterator, @@ -1900,74 +1974,73 @@ mod __parse__Expr { 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>>, + __sym0: &mut Option<::std::vec::Vec<&'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 @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state37(arena, __lookahead, __tokens, __sym1)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym1 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state41(arena, __lookahead, __tokens, __sym1)); } 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))); + let __nt = super::__actions::__action12(arena, ); + __result = (__lookahead, __Nonterminal::Expr_(__nt)); } _ => { return Err(__lookahead); } } + while __sym0.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state40(arena, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr_(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state38(arena, __lookahead, __tokens, __sym0, __sym1)); + } + __Nonterminal::__Expr______(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state42(arena, __lookahead, __tokens, __sym0, __sym1)); + } + __Nonterminal::Factor(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state44(arena, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state43(arena, __lookahead, __tokens, __sym1)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); } // 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 ["/"] + // Factor = "*" "(" Comma (*) ")" [EOF] + // Factor = "*" "(" Comma (*) ")" ["*"] + // Factor = "*" "(" Comma (*) ")" ["+"] + // Factor = "*" "(" Comma (*) ")" ["-"] + // Factor = "*" "(" Comma (*) ")" ["/"] // - // "/" -> Shift(S19) - // "*" -> Shift(S18) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // ")" -> Shift(S45) // pub fn __state28< 'ast, @@ -1976,43 +2049,17 @@ mod __parse__Expr { arena: &'ast Arena<'ast>, mut __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option<&'ast Node<'ast>>, + __sym0: &mut Option, __sym1: &mut Option, - __sym2: &mut Option<&'ast Node<'ast>>, + __sym2: &mut Option>>, ) -> Result<(Option, __Nonterminal<'ast, >), Option> { let mut __result: (Option, __Nonterminal<'ast, >); match __lookahead { - Some(__tok @ Tok::Div(..)) => { + Some(__tok @ Tok::RParen(..)) => { 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))); + __result = try!(__state45(arena, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); } _ => { return Err(__lookahead); @@ -2022,25 +2069,25 @@ mod __parse__Expr { } // State 29 - // Expr = Expr "-" Factor (*) [")"] + // Expr = Expr "-" Factor (*) [EOF] // Expr = Expr "-" Factor (*) ["+"] // Expr = Expr "-" Factor (*) ["-"] - // 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 [EOF] // Factor = Factor (*) "/" Term ["*"] // Factor = Factor (*) "/" Term ["+"] // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "*" -> Shift(S18) - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S19) + // "*" -> Shift(S13) // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S14) + // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // pub fn __state29< 'ast, @@ -2053,6 +2100,396 @@ mod __parse__Expr { __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!(__state13(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state14(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(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::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 30 + // Expr = Expr "+" Factor (*) [EOF] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "/" -> Shift(S14) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S13) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // + pub fn __state30< + '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!(__state14(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state13(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 31 + // 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 __state31< + '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::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::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::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 32 + // 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 __state32< + '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::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::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + 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::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 33 + // Factor = "*" "(" Comma (*) ")" [")"] + // Factor = "*" "(" Comma (*) ")" ["*"] + // Factor = "*" "(" Comma (*) ")" ["+"] + // Factor = "*" "(" Comma (*) ")" ["-"] + // Factor = "*" "(" Comma (*) ")" ["/"] + // + // ")" -> Shift(S46) + // + pub fn __state33< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state46(arena, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 34 + // Expr = Expr "-" Factor (*) [")"] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S19) + // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "*" -> Shift(S18) + // + pub fn __state34< + '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::__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))); + } + 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 35 + // 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(2);) + // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "/" -> Shift(S19) + // + pub fn __state35< + '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 { @@ -2066,7 +2503,1495 @@ mod __parse__Expr { let __lookahead = __tokens.next(); __result = try!(__state19(arena, __lookahead, __tokens, __sym2, __sym3)); } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 36 + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // + pub fn __state36< + '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::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 37 + // Factor = "*" (*) "(" Comma ")" [")"] + // Factor = "*" (*) "(" Comma ")" ["*"] + // Factor = "*" (*) "(" Comma ")" ["+"] + // Factor = "*" (*) "(" Comma ")" [","] + // Factor = "*" (*) "(" Comma ")" ["-"] + // Factor = "*" (*) "(" Comma ")" ["/"] + // + // "(" -> Shift(S47) + // + pub fn __state37< + '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!(__state47(arena, __lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 38 + // Comma = ( ",")* Expr? (*) [")"] + // + // ")" -> Reduce(Comma = ( ",")*, Expr? => ActionFn(10);) + // + pub fn __state38< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<::std::vec::Vec<&'ast Node<'ast>>>, + __sym1: &mut Option<::std::option::Option<&'ast Node<'ast>>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action10(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::Comma_Expr_(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 39 + // 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 ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [")"] + // 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" ["/"] + // + // "*" -> Shift(S8) + // "Num" -> Shift(S10) + // "(" -> Shift(S12) + // + // Factor -> S7 + // Expr -> S48 + // Term -> S9 + pub fn __state39< + '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::Times(..)) => { + 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!(__state10(arena, __lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(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!(__state7(arena, __lookahead, __tokens, __sym1)); + } + __Nonterminal::Expr(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state48(arena, __lookahead, __tokens, __sym0, __sym1)); + } + __Nonterminal::Term(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state9(arena, __lookahead, __tokens, __sym1)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 40 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) [","] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // ")" -> Reduce(Factor = Term => ActionFn(7);) + // "/" -> Reduce(Factor = Term => ActionFn(7);) + // "," -> Reduce(Factor = Term => ActionFn(7);) + // "-" -> Reduce(Factor = Term => ActionFn(7);) + // "*" -> Reduce(Factor = Term => ActionFn(7);) + // "+" -> Reduce(Factor = Term => ActionFn(7);) + // + pub fn __state40< + '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::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action7(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 41 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) [","] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // ")" -> Reduce(Term = "Num" => ActionFn(8);) + // "*" -> Reduce(Term = "Num" => ActionFn(8);) + // "," -> Reduce(Term = "Num" => ActionFn(8);) + // "/" -> Reduce(Term = "Num" => ActionFn(8);) + // "-" -> Reduce(Term = "Num" => ActionFn(8);) + // "+" -> Reduce(Term = "Num" => ActionFn(8);) + // + pub fn __state41< + '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::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action8(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 42 + // ( ",")* = ( ",")* ( ",") (*) ["("] + // ( ",")* = ( ",")* ( ",") (*) [")"] + // ( ",")* = ( ",")* ( ",") (*) ["*"] + // ( ",")* = ( ",")* ( ",") (*) ["Num"] + // + // ")" -> Reduce(( ",")* = ( ",")*, ( ",") => ActionFn(14);) + // "(" -> Reduce(( ",")* = ( ",")*, ( ",") => ActionFn(14);) + // "*" -> Reduce(( ",")* = ( ",")*, ( ",") => ActionFn(14);) + // "Num" -> Reduce(( ",")* = ( ",")*, ( ",") => ActionFn(14);) + // + pub fn __state42< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option<::std::vec::Vec<&'ast Node<'ast>>>, + __sym1: &mut Option<&'ast Node<'ast>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr_______(__nt))); + } + Some(Tok::LParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr_______(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr_______(__nt))); + } + Some(Tok::Num(_)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action14(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr_______(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 43 + // ( ",") = Expr (*) "," ["("] + // ( ",") = Expr (*) "," [")"] + // ( ",") = Expr (*) "," ["*"] + // ( ",") = Expr (*) "," ["Num"] + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor [","] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor [","] + // Expr = Expr (*) "-" Factor ["-"] + // Expr? = Expr (*) [")"] + // + // "," -> Shift(S51) + // "+" -> Shift(S49) + // "-" -> Shift(S50) + // ")" -> Reduce(Expr? = Expr => ActionFn(11);) + // + pub fn __state43< + '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::Comma(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state51(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state49(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state50(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action11(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Expr_(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 44 + // 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 = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "/" -> Shift(S53) + // "," -> Reduce(Expr = Factor => ActionFn(3);) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S52) + // ")" -> Reduce(Expr = Factor => ActionFn(3);) + // + pub fn __state44< + '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!(__state53(arena, __lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state52(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::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action3(arena, __sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + 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 45 + // Factor = "*" "(" Comma ")" (*) [EOF] + // Factor = "*" "(" Comma ")" (*) ["*"] + // Factor = "*" "(" Comma ")" (*) ["+"] + // Factor = "*" "(" Comma ")" (*) ["-"] + // Factor = "*" "(" Comma ")" (*) ["/"] + // + // EOF -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "*" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "/" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "-" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "+" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // + pub fn __state45< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option>>, + __sym3: &mut Option, + ) -> 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 __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 46 + // Factor = "*" "(" Comma ")" (*) [")"] + // Factor = "*" "(" Comma ")" (*) ["*"] + // Factor = "*" "(" Comma ")" (*) ["+"] + // Factor = "*" "(" Comma ")" (*) ["-"] + // Factor = "*" "(" Comma ")" (*) ["/"] + // + // "-" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // ")" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "/" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "*" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "+" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // + pub fn __state46< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option>>, + __sym3: &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 __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + 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 __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 47 + // ( ",")* = (*) ["("] + // ( ",")* = (*) [")"] + // ( ",")* = (*) ["*"] + // ( ",")* = (*) ["Num"] + // ( ",")* = (*) ( ",")* ( ",") ["("] + // ( ",")* = (*) ( ",")* ( ",") [")"] + // ( ",")* = (*) ( ",")* ( ",") ["*"] + // ( ",")* = (*) ( ",")* ( ",") ["Num"] + // Comma = (*) ( ",")* Expr? [")"] + // Factor = "*" "(" (*) Comma ")" [")"] + // Factor = "*" "(" (*) Comma ")" ["*"] + // Factor = "*" "(" (*) Comma ")" ["+"] + // Factor = "*" "(" (*) Comma ")" [","] + // Factor = "*" "(" (*) Comma ")" ["-"] + // Factor = "*" "(" (*) Comma ")" ["/"] + // + // "*" -> Reduce(( ",")* = => ActionFn(13);) + // "Num" -> Reduce(( ",")* = => ActionFn(13);) + // ")" -> Reduce(( ",")* = => ActionFn(13);) + // "(" -> Reduce(( ",")* = => ActionFn(13);) + // + // ( ",")* -> S27 + // Comma -> S54 + pub fn __state47< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::Times(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::Num(_)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::RParen(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + Some(Tok::LParen(..)) => { + let __nt = super::__actions::__action13(arena, ); + __result = (__lookahead, __Nonterminal::__Expr_______(__nt)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::__Expr_______(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state27(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Comma_Expr_(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state54(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 48 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [")"] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" [","] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // ")" -> Shift(S55) + // "-" -> Shift(S21) + // "+" -> Shift(S23) + // + pub fn __state48< + '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!(__state55(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state21(arena, __lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state23(arena, __lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 49 + // Expr = Expr "+" (*) Factor [")"] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor [","] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [")"] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term [","] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [")"] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term [","] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term [","] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" [","] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" [","] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" [","] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "*" -> Shift(S37) + // "(" -> Shift(S39) + // "Num" -> Shift(S41) + // + // Term -> S40 + // Factor -> S56 + pub fn __state49< + '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::Times(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state37(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state41(arena, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state40(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state56(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 50 + // Expr = Expr "-" (*) Factor [")"] + // Expr = Expr "-" (*) Factor ["+"] + // Expr = Expr "-" (*) Factor [","] + // Expr = Expr "-" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [")"] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term [","] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [")"] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term [","] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [")"] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term [","] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Factor = (*) "*" "(" Comma ")" [")"] + // Factor = (*) "*" "(" Comma ")" ["*"] + // Factor = (*) "*" "(" Comma ")" ["+"] + // Factor = (*) "*" "(" Comma ")" [","] + // Factor = (*) "*" "(" Comma ")" ["-"] + // Factor = (*) "*" "(" Comma ")" ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" [","] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" [","] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "*" -> Shift(S37) + // "Num" -> Shift(S41) + // "(" -> Shift(S39) + // + // Term -> S40 + // Factor -> S57 + pub fn __state50< + '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::Times(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state37(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state41(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state40(arena, __lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state57(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 51 + // ( ",") = Expr "," (*) ["("] + // ( ",") = Expr "," (*) [")"] + // ( ",") = Expr "," (*) ["*"] + // ( ",") = Expr "," (*) ["Num"] + // + // "*" -> Reduce(( ",") = Expr, "," => ActionFn(15);) + // "Num" -> Reduce(( ",") = Expr, "," => ActionFn(15);) + // "(" -> Reduce(( ",") = Expr, "," => ActionFn(15);) + // ")" -> Reduce(( ",") = Expr, "," => ActionFn(15);) + // + pub fn __state51< + '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::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr______(__nt))); + } + Some(Tok::Num(_)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr______(__nt))); + } + Some(Tok::LParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr______(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __nt = super::__actions::__action15(arena, __sym0, __sym1); + return Ok((__lookahead, __Nonterminal::__Expr______(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 52 + // 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 = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" [","] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S39) + // "Num" -> Shift(S41) + // + // Term -> S58 + pub fn __state52< + '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!(__state39(arena, __lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state41(arena, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state58(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 53 + // 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 = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" [","] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S41) + // "(" -> Shift(S39) + // + // Term -> S59 + pub fn __state53< + '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!(__state41(arena, __lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state39(arena, __lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state59(arena, __lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 54 + // Factor = "*" "(" Comma (*) ")" [")"] + // Factor = "*" "(" Comma (*) ")" ["*"] + // Factor = "*" "(" Comma (*) ")" ["+"] + // Factor = "*" "(" Comma (*) ")" [","] + // Factor = "*" "(" Comma (*) ")" ["-"] + // Factor = "*" "(" Comma (*) ")" ["/"] + // + // ")" -> Shift(S60) + // + pub fn __state54< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option>>, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state60(arena, __lookahead, __tokens, __sym0, __sym1, __sym2, __sym3)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 55 + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) [","] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "," -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(9);) + // + pub fn __state55< + '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::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action9(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 56 + // Expr = Expr "+" Factor (*) [")"] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) [","] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term [","] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term [","] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "*" -> Shift(S52) + // "/" -> Shift(S53) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "," -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // + pub fn __state56< + '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!(__state52(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state53(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 57 + // Expr = Expr "-" Factor (*) [")"] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) [","] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term [","] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term [","] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "/" -> Shift(S53) + // "," -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "*" -> Shift(S52) + // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // + pub fn __state57< + '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!(__state53(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state52(arena, __lookahead, __tokens, __sym2, __sym3)); + } + Some(Tok::Comma(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); @@ -2087,12 +4012,257 @@ mod __parse__Expr { let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::Expr(__nt))); } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action1(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } _ => { return Err(__lookahead); } } return Ok(__result); } + + // State 58 + // Factor = Factor "*" Term (*) [")"] + // 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);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // + pub fn __state58< + '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::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action4(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 59 + // 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(5);) + // + pub fn __state59< + '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::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(arena, __sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::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::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::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::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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 60 + // Factor = "*" "(" Comma ")" (*) [")"] + // Factor = "*" "(" Comma ")" (*) ["*"] + // Factor = "*" "(" Comma ")" (*) ["+"] + // Factor = "*" "(" Comma ")" (*) [","] + // Factor = "*" "(" Comma ")" (*) ["-"] + // Factor = "*" "(" Comma ")" (*) ["/"] + // + // ")" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "," -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "*" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "/" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "-" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // "+" -> Reduce(Factor = "*", "(", Comma, ")" => ActionFn(6);) + // + pub fn __state60< + 'ast, + __TOKENS: Iterator, + >( + arena: &'ast Arena<'ast>, + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option>>, + __sym3: &mut Option, + ) -> Result<(Option, __Nonterminal<'ast, >), Option> + { + let mut __result: (Option, __Nonterminal<'ast, >); + match __lookahead { + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Comma(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __sym3 = __sym3.take().unwrap(); + let __nt = super::__actions::__action6(arena, __sym0, __sym1, __sym2, __sym3); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } } mod __actions { @@ -2171,6 +4341,19 @@ mod __actions { pub fn __action6< 'ast, + >( + arena: &'ast Arena<'ast>, + _: Tok, + _: Tok, + __0: Vec<&'ast Node<'ast>>, + _: Tok, + ) -> &'ast Node<'ast> + { + arena.alloc(Node::Reduce(Op::Mul, __0)) + } + + pub fn __action7< + 'ast, >( arena: &'ast Arena<'ast>, __0: &'ast Node<'ast>, @@ -2179,7 +4362,7 @@ mod __actions { (__0) } - pub fn __action7< + pub fn __action8< 'ast, >( arena: &'ast Arena<'ast>, @@ -2189,7 +4372,7 @@ mod __actions { arena.alloc(Node::Value(n)) } - pub fn __action8< + pub fn __action9< 'ast, >( arena: &'ast Arena<'ast>, @@ -2200,4 +4383,65 @@ mod __actions { { (__0) } + + pub fn __action10< + 'ast, + >( + arena: &'ast Arena<'ast>, + h: ::std::vec::Vec<&'ast Node<'ast>>, + t: ::std::option::Option<&'ast Node<'ast>>, + ) -> Vec<&'ast Node<'ast>> + { + h.into_iter().chain(t).collect() + } + + pub fn __action11< + 'ast, + >( + arena: &'ast Arena<'ast>, + __0: &'ast Node<'ast>, + ) -> ::std::option::Option<&'ast Node<'ast>> + { + Some(__0) + } + + pub fn __action12< + 'ast, + >( + arena: &'ast Arena<'ast>, + ) -> ::std::option::Option<&'ast Node<'ast>> + { + None + } + + pub fn __action13< + 'ast, + >( + arena: &'ast Arena<'ast>, + ) -> ::std::vec::Vec<&'ast Node<'ast>> + { + vec![] + } + + pub fn __action14< + 'ast, + >( + arena: &'ast Arena<'ast>, + v: ::std::vec::Vec<&'ast Node<'ast>>, + e: &'ast Node<'ast>, + ) -> ::std::vec::Vec<&'ast Node<'ast>> + { + { let mut v = v; v.push(e); v } + } + + pub fn __action15< + 'ast, + >( + arena: &'ast Arena<'ast>, + __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 index 8445889..8216c49 100644 --- a/lalrpop-test/src/expr_arena_ast.rs +++ b/lalrpop-test/src/expr_arena_ast.rs @@ -9,6 +9,7 @@ pub enum Op { pub enum Node<'ast> { Value(i32), Binary(Op, &'ast Node<'ast>, &'ast Node<'ast>), + Reduce(Op, Vec<&'ast Node<'ast>>), } pub struct Arena<'ast> { diff --git a/lalrpop-test/src/main.rs b/lalrpop-test/src/main.rs index bc20c6a..3b07dad 100644 --- a/lalrpop-test/src/main.rs +++ b/lalrpop-test/src/main.rs @@ -4,10 +4,6 @@ mod expr_arena_ast; mod sub; mod util; -fn main() { - println!("Hello, world!"); -} - #[test] fn expr_test1() { util::test(|v| expr::parse_Expr(1, v), "22 - 3", 22 - 3); @@ -51,7 +47,7 @@ fn sub_test3() { #[test] fn expr_arena_test1() { use expr_arena_ast::*; - let mut arena = Arena::new(); + let arena = Arena::new(); let expected = arena.alloc(Node::Binary(Op::Sub, arena.alloc(Node::Binary(Op::Mul, @@ -61,3 +57,16 @@ fn expr_arena_test1() { util::test(|v| expr_arena::parse_Expr(&arena, v), "22 * 3 - 6", expected); } +#[test] +fn expr_arena_test2() { + use expr_arena_ast::*; + let arena = Arena::new(); + let expected = + arena.alloc(Node::Reduce(Op::Mul, + vec![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); + 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 e8c7075..6c623c4 100644 --- a/lalrpop-test/src/sub.rs +++ b/lalrpop-test/src/sub.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports)] use util::tok::Tok; #[allow(non_snake_case)] @@ -16,15 +17,15 @@ pub fn parse_S< } mod __parse__S { - #![allow(non_snake_case, unused_mut, unused_variables)] + #![allow(non_snake_case, non_camel_case_types, unused_mut, unused_variables, unused_imports)] use util::tok::Tok; pub enum __Nonterminal<> { - S(i32), - __S(i32), E(i32), + S(i32), T(i32), + __S(i32), } // State 0 @@ -39,12 +40,12 @@ mod __parse__S { // T = (*) "Num" ["-"] // __S = (*) S [EOF] // - // "(" -> Shift(S1) - // "Num" -> Shift(S4) + // "(" -> Shift(S4) + // "Num" -> Shift(S5) // - // T -> S5 - // E -> S2 - // S -> S3 + // S -> S1 + // T -> S2 + // E -> S3 pub fn __state0< __TOKENS: Iterator, >( @@ -57,12 +58,12 @@ mod __parse__S { Some(__tok @ Tok::LParen(..)) => { let mut __sym0 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state1(__lookahead, __tokens, __sym0)); + __result = try!(__state4(__lookahead, __tokens, __sym0)); } Some(Tok::Num(__tok0)) => { let mut __sym0 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state4(__lookahead, __tokens, __sym0)); + __result = try!(__state5(__lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); @@ -71,15 +72,15 @@ mod __parse__S { loop { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::T(__nt) => { + __Nonterminal::S(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state5(__lookahead, __tokens, __sym0)); + __result = try!(__state1(__lookahead, __tokens, __sym0)); } - __Nonterminal::E(__nt) => { + __Nonterminal::T(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state2(__lookahead, __tokens, __sym0)); } - __Nonterminal::S(__nt) => { + __Nonterminal::E(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state3(__lookahead, __tokens, __sym0)); } @@ -91,106 +92,11 @@ mod __parse__S { } // State 1 - // E = (*) E "-" T [")"] - // E = (*) E "-" T ["-"] - // E = (*) T [")"] - // E = (*) T ["-"] - // T = (*) "(" E ")" [")"] - // T = (*) "(" E ")" ["-"] - // T = "(" (*) E ")" [EOF] - // T = "(" (*) E ")" ["-"] - // T = (*) "Num" [")"] - // T = (*) "Num" ["-"] - // - // "Num" -> Shift(S6) - // "(" -> Shift(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<>); - match __lookahead { - 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); - } - } - while __sym0.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __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)); - } - } - } - return Ok(__result); - } - - // State 2 - // E = E (*) "-" T [EOF] - // E = E (*) "-" T ["-"] - // S = E (*) [EOF] - // - // "-" -> Shift(S10) - // EOF -> Reduce(S = E => ActionFn(1);) - // - 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::Minus(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state10(__lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action1(__sym0); - return Ok((__lookahead, __Nonterminal::S(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 3 // __S = S (*) [EOF] // // EOF -> Reduce(__S = S => ActionFn(0);) // - pub fn __state3< + pub fn __state1< __TOKENS: Iterator, >( mut __lookahead: Option, @@ -211,47 +117,14 @@ mod __parse__S { } } - // State 4 - // T = "Num" (*) [EOF] - // T = "Num" (*) ["-"] - // - // "-" -> Reduce(T = "Num" => ActionFn(4);) - // EOF -> Reduce(T = "Num" => ActionFn(4);) - // - pub fn __state4< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__actions::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 5 + // State 2 // E = T (*) [EOF] // E = T (*) ["-"] // - // "-" -> Reduce(E = T => ActionFn(3);) // EOF -> Reduce(E = T => ActionFn(3);) + // "-" -> Reduce(E = T => ActionFn(3);) // - pub fn __state5< + pub fn __state2< __TOKENS: Iterator, >( mut __lookahead: Option, @@ -261,77 +134,11 @@ mod __parse__S { { let mut __result: (Option, __Nonterminal<>); match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - 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))); } - _ => { - return Err(__lookahead); - } - } - } - - // State 6 - // T = "Num" (*) [")"] - // T = "Num" (*) ["-"] - // - // "-" -> Reduce(T = "Num" => ActionFn(4);) - // ")" -> Reduce(T = "Num" => ActionFn(4);) - // - pub fn __state6< - __TOKENS: Iterator, - >( - mut __lookahead: Option, - __tokens: &mut __TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal<>), Option> - { - let mut __result: (Option, __Nonterminal<>); - match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - 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))); - } - _ => { - return Err(__lookahead); - } - } - } - - // 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); @@ -343,35 +150,33 @@ mod __parse__S { } } - // State 8 - // E = E (*) "-" T [")"] + // State 3 + // E = E (*) "-" T [EOF] // E = E (*) "-" T ["-"] - // T = "(" E (*) ")" [EOF] - // T = "(" E (*) ")" ["-"] + // S = E (*) [EOF] // - // ")" -> Shift(S11) - // "-" -> Shift(S12) + // "-" -> Shift(S6) + // EOF -> Reduce(S = E => ActionFn(1);) // - pub fn __state8< + pub fn __state3< __TOKENS: Iterator, >( mut __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, + __sym0: &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 mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state6(__lookahead, __tokens, __sym0, __sym1)); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action1(__sym0); + return Ok((__lookahead, __Nonterminal::S(__nt))); } _ => { return Err(__lookahead); @@ -380,24 +185,24 @@ mod __parse__S { return Ok(__result); } - // State 9 + // State 4 // E = (*) E "-" T [")"] // E = (*) E "-" T ["-"] // E = (*) T [")"] // E = (*) T ["-"] // T = (*) "(" E ")" [")"] // T = (*) "(" E ")" ["-"] - // T = "(" (*) E ")" [")"] + // T = "(" (*) E ")" [EOF] // T = "(" (*) E ")" ["-"] // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "(" -> Shift(S9) - // "Num" -> Shift(S6) + // "(" -> Shift(S8) + // "Num" -> Shift(S10) // // T -> S7 - // E -> S13 - pub fn __state9< + // E -> S9 + pub fn __state4< __TOKENS: Iterator, >( mut __lookahead: Option, @@ -410,12 +215,12 @@ mod __parse__S { Some(__tok @ Tok::LParen(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state9(__lookahead, __tokens, __sym1)); + __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(__lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); @@ -430,7 +235,7 @@ mod __parse__S { } __Nonterminal::E(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state13(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state9(__lookahead, __tokens, __sym0, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -440,7 +245,40 @@ mod __parse__S { return Ok(__result); } - // State 10 + // State 5 + // T = "Num" (*) [EOF] + // T = "Num" (*) ["-"] + // + // "-" -> Reduce(T = "Num" => ActionFn(4);) + // EOF -> Reduce(T = "Num" => ActionFn(4);) + // + 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 { + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action4(__sym0); + return Ok((__lookahead, __Nonterminal::T(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__actions::__action4(__sym0); + return Ok((__lookahead, __Nonterminal::T(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 6 // E = E "-" (*) T [EOF] // E = E "-" (*) T ["-"] // T = (*) "(" E ")" [EOF] @@ -448,11 +286,11 @@ mod __parse__S { // T = (*) "Num" [EOF] // T = (*) "Num" ["-"] // - // "Num" -> Shift(S4) - // "(" -> Shift(S1) + // "Num" -> Shift(S5) + // "(" -> Shift(S4) // - // T -> S14 - pub fn __state10< + // T -> S11 + pub fn __state6< __TOKENS: Iterator, >( mut __lookahead: Option, @@ -466,12 +304,12 @@ mod __parse__S { Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state4(__lookahead, __tokens, __sym2)); + __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)); + __result = try!(__state4(__lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -482,7 +320,7 @@ mod __parse__S { match __nt { __Nonterminal::T(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state14(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state11(__lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -492,38 +330,201 @@ mod __parse__S { return Ok(__result); } - // State 11 - // T = "(" E ")" (*) [EOF] - // T = "(" E ")" (*) ["-"] + // State 7 + // E = T (*) [")"] + // E = T (*) ["-"] // - // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) - // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) + // "-" -> Reduce(E = T => ActionFn(3);) + // ")" -> Reduce(E = T => ActionFn(3);) // - pub fn __state11< + pub fn __state7< __TOKENS: Iterator, >( mut __lookahead: Option, __tokens: &mut __TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, + __sym0: &mut Option, ) -> Result<(Option, __Nonterminal<>), Option> { let mut __result: (Option, __Nonterminal<>); match __lookahead { Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); + let __nt = super::__actions::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::E(__nt))); + } + Some(Tok::RParen(..)) => { + 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 ["-"] + // E = (*) T [")"] + // E = (*) T ["-"] + // T = (*) "(" E ")" [")"] + // T = (*) "(" E ")" ["-"] + // T = "(" (*) E ")" [")"] + // T = "(" (*) E ")" ["-"] + // T = (*) "Num" [")"] + // T = (*) "Num" ["-"] + // + // "Num" -> Shift(S10) + // "(" -> Shift(S8) + // + // T -> S7 + // E -> S12 + pub fn __state8< + __TOKENS: Iterator, + >( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, __Nonterminal<>), Option> + { + let mut __result: (Option, __Nonterminal<>); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym1 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state10(__lookahead, __tokens, __sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(__lookahead, __tokens, __sym1)); + } + _ => { + return Err(__lookahead); + } + } + while __sym0.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::T(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state7(__lookahead, __tokens, __sym1)); + } + __Nonterminal::E(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state12(__lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 9 + // E = E (*) "-" T [")"] + // E = E (*) "-" T ["-"] + // T = "(" E (*) ")" [EOF] + // T = "(" E (*) ")" ["-"] + // + // "-" -> Shift(S13) + // ")" -> Shift(S14) + // + pub fn __state9< + __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!(__state14(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 10 + // T = "Num" (*) [")"] + // T = "Num" (*) ["-"] + // + // "-" -> Reduce(T = "Num" => ActionFn(4);) + // ")" -> Reduce(T = "Num" => ActionFn(4);) + // + 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::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + 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))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 11 + // E = E "-" T (*) [EOF] + // E = E "-" T (*) ["-"] + // + // EOF -> Reduce(E = E, "-", T => ActionFn(2);) + // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // + pub fn __state11< + __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::__actions::__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::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::E(__nt))); } _ => { return Err(__lookahead); @@ -532,67 +533,15 @@ mod __parse__S { } // State 12 - // E = E "-" (*) T [")"] - // E = E "-" (*) T ["-"] - // T = (*) "(" E ")" [")"] - // T = (*) "(" E ")" ["-"] - // T = (*) "Num" [")"] - // T = (*) "Num" ["-"] - // - // "Num" -> Shift(S6) - // "(" -> Shift(S9) - // - // 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<>); - 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!(__state9(__lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::T(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state15(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 13 // E = E (*) "-" T [")"] // E = E (*) "-" T ["-"] // T = "(" E (*) ")" [")"] // T = "(" E (*) ")" ["-"] // - // ")" -> Shift(S16) - // "-" -> Shift(S12) + // ")" -> Shift(S15) + // "-" -> Shift(S13) // - pub fn __state13< + pub fn __state12< __TOKENS: Iterator, >( mut __lookahead: Option, @@ -606,12 +555,12 @@ mod __parse__S { Some(__tok @ Tok::RParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state16(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state15(__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)); + __result = try!(__state13(__lookahead, __tokens, __sym1, __sym2)); } _ => { return Err(__lookahead); @@ -620,92 +569,66 @@ mod __parse__S { return Ok(__result); } + // State 13 + // E = E "-" (*) T [")"] + // E = E "-" (*) T ["-"] + // T = (*) "(" E ")" [")"] + // T = (*) "(" E ")" ["-"] + // T = (*) "Num" [")"] + // T = (*) "Num" ["-"] + // + // "(" -> Shift(S8) + // "Num" -> Shift(S10) + // + // T -> S16 + 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::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(__lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state10(__lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::T(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state16(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + // State 14 - // E = E "-" T (*) [EOF] - // E = E "-" T (*) ["-"] - // - // EOF -> Reduce(E = E, "-", T => ActionFn(2);) - // "-" -> Reduce(E = E, "-", T => ActionFn(2);) - // - pub fn __state14< - __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::__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::__actions::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 15 - // E = E "-" T (*) [")"] - // E = E "-" T (*) ["-"] - // - // "-" -> 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<>); - match __lookahead { - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 16 - // T = "(" E ")" (*) [")"] + // T = "(" E ")" (*) [EOF] // T = "(" E ")" (*) ["-"] // // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) - // ")" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) // - pub fn __state16< + pub fn __state14< __TOKENS: Iterator, >( mut __lookahead: Option, @@ -724,6 +647,38 @@ mod __parse__S { let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::T(__nt))); } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::T(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 15 + // T = "(" E ")" (*) [")"] + // T = "(" E ")" (*) ["-"] + // + // ")" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // + 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<>); + match __lookahead { Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); @@ -731,6 +686,52 @@ mod __parse__S { let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::T(__nt))); } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::T(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 16 + // E = E "-" T (*) [")"] + // E = E "-" T (*) ["-"] + // + // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // ")" -> Reduce(E = E, "-", T => ActionFn(2);) + // + 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<>); + match __lookahead { + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::E(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__actions::__action2(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::E(__nt))); + } _ => { return Err(__lookahead); } diff --git a/lalrpop-test/src/util/tok.rs b/lalrpop-test/src/util/tok.rs index 424612c..679385a 100644 --- a/lalrpop-test/src/util/tok.rs +++ b/lalrpop-test/src/util/tok.rs @@ -9,6 +9,7 @@ pub enum Tok { Plus, Times, Div, + Comma, } // simplest and stupidest possible tokenizer @@ -25,6 +26,7 @@ pub fn tokenize(s: &str) -> Vec { '-' => tokens.push(Tok::Minus), '+' => tokens.push(Tok::Plus), '*' => tokens.push(Tok::Times), + ',' => tokens.push(Tok::Comma), '/' => tokens.push(Tok::Div), _ if c.is_digit(10) => { let (tmp, next) = take_while(c, &mut chars, |c| c.is_digit(10)); diff --git a/lalrpop/src/build/mod.rs b/lalrpop/src/build/mod.rs index cc63663..b883d6f 100644 --- a/lalrpop/src/build/mod.rs +++ b/lalrpop/src/build/mod.rs @@ -135,6 +135,9 @@ fn emit_recursive_ascent(output_path: &Path, grammar: &r::Grammar) -> io::Result let output_file = try!(fs::File::create(output_path)); let mut rust = RustWrite::new(output_file); + // often some of the uses are not used here + rust!(rust, "#![allow(unused_imports)]"); + try!(emit_uses(grammar, &mut rust)); if grammar.start_nonterminals.is_empty() { diff --git a/lalrpop/src/grammar/parse_tree.rs b/lalrpop/src/grammar/parse_tree.rs index 02a9169..f1dc6ff 100644 --- a/lalrpop/src/grammar/parse_tree.rs +++ b/lalrpop/src/grammar/parse_tree.rs @@ -5,10 +5,11 @@ some pre-expansion and so forth before creating the proper AST. */ -use intern::{InternedString}; +use intern::{intern, InternedString}; use grammar::repr::{NominalTypeRepr, TypeRepr}; use grammar::pattern::Pattern; use std::fmt::{Debug, Display, Formatter, Error}; +use std::iter::once; use util::Sep; #[derive(Clone, Debug, PartialEq, Eq)] @@ -49,6 +50,12 @@ pub struct Conversion { pub to: Pattern, } +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Path { + pub absolute: bool, + pub ids: Vec, +} + #[derive(Clone, Debug, PartialEq, Eq)] pub enum TypeRef { // (T1, T2) @@ -56,7 +63,7 @@ pub enum TypeRef { // Foo<'a, 'b, T1, T2>, Foo::Bar, etc Nominal { - path: Vec, + path: Path, types: Vec }, @@ -240,6 +247,14 @@ impl Display for TerminalString { } } +impl Display for Path { + fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { + write!(fmt, "{}{}", + if self.absolute {"::"} else {""}, + Sep("::", &self.ids)) + } +} + impl Debug for TerminalString { fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { Display::fmt(self, fmt) @@ -346,9 +361,9 @@ impl Display for TypeRef { TypeRef::Tuple(ref types) => write!(fmt, "({})", Sep(", ", types)), TypeRef::Nominal { ref path, ref types } if types.len() == 0 => - write!(fmt, "{}", Sep("::", path)), + write!(fmt, "{}", path), TypeRef::Nominal { ref path, ref types } => - write!(fmt, "{}<{}>", Sep("::", path), Sep(", ", types)), + write!(fmt, "{}<{}>", path, Sep(", ", types)), TypeRef::Lifetime(ref s) => write!(fmt, "{}", s), TypeRef::Id(ref s) => @@ -384,7 +399,7 @@ impl TypeRef { TypeRepr::Lifetime(id), TypeRef::Id(id) => TypeRepr::Nominal(NominalTypeRepr { - path: vec![id], + path: Path::from_id(id), types: vec![] }), TypeRef::OfSymbol(_) => @@ -396,3 +411,41 @@ impl TypeRef { } } } + +impl Path { + pub fn from_id(id: InternedString) -> Path { + Path { + absolute: false, + ids: vec![id] + } + } + + pub fn vec() -> Path { + Path { + absolute: true, + ids: vec![intern("std"), intern("vec"), intern("Vec")] + } + } + + pub fn option() -> Path { + Path { + absolute: true, + ids: vec![intern("std"), intern("option"), intern("Option")] + } + } + + pub fn as_id(&self) -> Option { + if !self.absolute && self.ids.len() == 1 { + Some(self.ids[0]) + } else { + None + } + } + + pub fn append(&self, id: InternedString) -> Path { + Path { + absolute: self.absolute, + ids: self.ids.iter().cloned().chain(once(id)).collect() + } + } +} diff --git a/lalrpop/src/grammar/pattern.rs b/lalrpop/src/grammar/pattern.rs index 6ee0831..478381c 100644 --- a/lalrpop/src/grammar/pattern.rs +++ b/lalrpop/src/grammar/pattern.rs @@ -7,7 +7,7 @@ representations. */ use intern::{InternedString}; -use grammar::parse_tree::Span; +use grammar::parse_tree::{Path, Span}; use std::fmt::{Display, Formatter, Error}; use util::Sep; @@ -26,9 +26,9 @@ pub struct FieldPattern { #[derive(Clone, Debug, PartialEq, Eq)] pub enum PatternKind { - Enum(Vec, Vec>), - Struct(Vec, Vec>, /* trailing ..? */ bool), - Path(Vec), + Enum(Path, Vec>), + Struct(Path, Vec>, /* trailing ..? */ bool), + Path(Path), Tuple(Vec>), Underscore, DotDot, @@ -96,15 +96,15 @@ impl Display for PatternKind { fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { match *self { PatternKind::Path(ref path) => - write!(fmt, "{}", Sep("::", path)), + write!(fmt, "{}", path), PatternKind::Enum(ref path, ref pats) => - write!(fmt, "{}({})", Sep("::", path), Sep(", ", pats)), + write!(fmt, "{}({})", path, Sep(", ", pats)), PatternKind::Struct(ref path, ref fields, false) => - write!(fmt, "{} {{ {} }}", Sep("::", path), Sep(", ", fields)), + write!(fmt, "{} {{ {} }}", path, Sep(", ", fields)), PatternKind::Struct(ref path, ref fields, true) if fields.len() == 0 => - write!(fmt, "{} {{ .. }}", Sep("::", path)), + write!(fmt, "{} {{ .. }}", path), PatternKind::Struct(ref path, ref fields, true) => - write!(fmt, "{} {{ {}, .. }}", Sep("::", path), Sep(", ", fields)), + write!(fmt, "{} {{ {}, .. }}", path, Sep(", ", fields)), PatternKind::Tuple(ref paths) => write!(fmt, "({})", Sep(", ", paths)), PatternKind::Underscore => diff --git a/lalrpop/src/grammar/repr.rs b/lalrpop/src/grammar/repr.rs index 932c06b..1a90084 100644 --- a/lalrpop/src/grammar/repr.rs +++ b/lalrpop/src/grammar/repr.rs @@ -6,12 +6,12 @@ use intern::{InternedString}; use grammar::pattern::{Pattern, PatternKind}; -use std::iter::once; use std::fmt::{Debug, Display, Formatter, Error}; use util::{map, Map, Sep}; // These concepts we re-use wholesale pub use grammar::parse_tree::{NonterminalString, + Path, Span, TerminalString, TypeParameter}; @@ -92,7 +92,7 @@ pub enum TypeRepr { #[derive(Clone, PartialEq, Eq)] pub struct NominalTypeRepr { - pub path: Vec, + pub path: Path, pub types: Vec } @@ -173,9 +173,9 @@ impl Debug for TypeRepr { impl Display for NominalTypeRepr { fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { if self.types.len() == 0 { - write!(fmt, "{}", Sep("::", &self.path)) + write!(fmt, "{}", self.path) } else { - write!(fmt, "{}<{}>", Sep("::", &self.path), Sep(", ", &self.types)) + write!(fmt, "{}<{}>", self.path, Sep(", ", &self.types)) } } } @@ -253,11 +253,7 @@ impl ActionFnDefn { impl Grammar { pub fn default_pattern(&self, id: InternedString) -> Pattern { - let path: Vec = - self.types.terminal_enum_type().path.iter() - .cloned() - .chain(once(id)) - .collect(); + let path = self.types.terminal_enum_type().path.append(id); Pattern { span: self.token_span, kind: PatternKind::Enum(path, vec![ diff --git a/lalrpop/src/lr1/ascent.rs b/lalrpop/src/lr1/ascent.rs index 5c4ea5e..5006143 100644 --- a/lalrpop/src/lr1/ascent.rs +++ b/lalrpop/src/lr1/ascent.rs @@ -2,14 +2,11 @@ //! //! [recursive ascent]: https://en.wikipedia.org/wiki/Recursive_ascent_parser -use intern::{InternedString}; use grammar::repr::{Grammar, NonterminalString, Symbol, TerminalString, Types}; use lr1::{Lookahead, State, StateIndex}; use rust::RustWrite; use std::io::{self, Write}; -use util::Sep; - -pub type Path = Vec; +use util::{Escape, Sep}; pub fn compile<'grammar,W:Write>( grammar: &'grammar Grammar, @@ -61,7 +58,10 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { rust!(self.out, "mod {}parse{} {{", self.prefix, self.start_symbol); - rust!(self.out, "#![allow(non_snake_case, unused_mut, unused_variables)]"); + // these stylistic lints are annoying for the generated code, + // which doesn't follow conventions: + rust!(self.out, "#![allow(non_snake_case, non_camel_case_types, \ + unused_mut, unused_variables, unused_imports)]"); rust!(self.out, ""); try!(self.write_uses()); @@ -96,7 +96,7 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { // have to unwrap and rewrap as we pass up the stack, which // seems silly for &nt in self.grammar.productions.keys() { - rust!(self.out, "{}({}),", nt, self.types.nonterminal_type(nt)); + rust!(self.out, "{}({}),", Escape(nt), self.types.nonterminal_type(nt)); } rust!(self.out, "}}"); @@ -122,7 +122,7 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { 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, + self.prefix, self.prefix, self.start_symbol, self.prefix, Escape(self.start_symbol), self.prefix, self.prefix, self.prefix); rust!(self.out, "_ => unreachable!(),"); rust!(self.out, "}}"); @@ -241,11 +241,12 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { if !transfer_syms.is_empty() { // if we popped anything off of the stack, then this frame is done rust!(self.out, "return Ok(({}lookahead, {}Nonterminal::{}({}nt)));", - self.prefix, self.prefix, production.nonterminal, self.prefix); + self.prefix, self.prefix, Escape(production.nonterminal), self.prefix); } else { // otherwise, pop back - rust!(self.out, "result = ({}lookahead, {}Nonterminal::{}({}nt));", - self.prefix, self.prefix, production.nonterminal, self.prefix); + rust!(self.out, "{}result = ({}lookahead, {}Nonterminal::{}({}nt));", + self.prefix, self.prefix, self.prefix, + Escape(production.nonterminal), self.prefix); fallthrough = true; } @@ -272,7 +273,8 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { rust!(self.out, "match {}nt {{", self.prefix); for (&nt, &next_index) in &this_state.gotos { - rust!(self.out, "{}Nonterminal::{}({}nt) => {{", self.prefix, nt, self.prefix); + rust!(self.out, "{}Nonterminal::{}({}nt) => {{", + self.prefix, Escape(nt), self.prefix); rust!(self.out, "let {}sym{} = &mut Some({}nt);", self.prefix, this_prefix.len(), self.prefix); let transition = self.transition(this_prefix, next_index, "lookahead", "tokens"); diff --git a/lalrpop/src/normalize/macro_expand/mod.rs b/lalrpop/src/normalize/macro_expand/mod.rs index ffaeee8..c4f1f3a 100644 --- a/lalrpop/src/normalize/macro_expand/mod.rs +++ b/lalrpop/src/normalize/macro_expand/mod.rs @@ -1,8 +1,15 @@ use std::collections::{HashMap, HashSet}; use intern::{intern, read, InternedString}; -use grammar::parse_tree::{Alternative, Condition, ConditionOp, ExprSymbol, Grammar, GrammarItem, - MacroSymbol, NonterminalData, NonterminalString, RepeatOp, RepeatSymbol, - Span, Symbol, SymbolKind, TypeRef}; +use grammar::parse_tree::{Alternative, + Condition, ConditionOp, + ExprSymbol, + Grammar, GrammarItem, + MacroSymbol, + NonterminalData, NonterminalString, + Path, + RepeatOp, RepeatSymbol, + Span, Symbol, SymbolKind, + TypeRef}; use normalize::{NormResult, NormError}; use normalize::norm_util::{self, Symbols}; use regex::Regex; @@ -212,7 +219,8 @@ impl MacroExpander { TypeRef::Id(id) => { match args.get(&NonterminalString(id)) { Some(sym) => TypeRef::OfSymbol(sym.clone()), - None => TypeRef::Nominal { path: vec![id], types: vec![] }, + None => TypeRef::Nominal { path: Path::from_id(id), + types: vec![] }, } } } @@ -351,7 +359,7 @@ impl MacroExpander { match repeat.op { RepeatOp::Star => { - let path = vec![intern("std"), intern("vec"), intern("Vec")]; + let path = Path::vec(); let ty_ref = TypeRef::Nominal { path: path, types: vec![base_symbol_ty] }; Ok(GrammarItem::Nonterminal(NonterminalData { @@ -394,7 +402,7 @@ impl MacroExpander { } RepeatOp::Plus => { - let path = vec![intern("std"), intern("vec"), intern("Vec")]; + let path = Path::vec(); let ty_ref = TypeRef::Nominal { path: path, types: vec![base_symbol_ty] }; Ok(GrammarItem::Nonterminal(NonterminalData { @@ -432,7 +440,7 @@ impl MacroExpander { } RepeatOp::Question => { - let path = vec![intern("std"), intern("option"), intern("Option")]; + let path = Path::option(); let ty_ref = TypeRef::Nominal { path: path, types: vec![base_symbol_ty] }; Ok(GrammarItem::Nonterminal(NonterminalData { diff --git a/lalrpop/src/normalize/tyinfer/mod.rs b/lalrpop/src/normalize/tyinfer/mod.rs index b897696..a6198cf 100644 --- a/lalrpop/src/normalize/tyinfer/mod.rs +++ b/lalrpop/src/normalize/tyinfer/mod.rs @@ -2,9 +2,13 @@ use super::{NormResult, NormError}; use super::norm_util::{self, AlternativeAction, Symbols}; use std::collections::{HashMap}; -use grammar::parse_tree::{Alternative, EnumToken, Grammar, GrammarItem, +use grammar::parse_tree::{Alternative, + EnumToken, + Grammar, GrammarItem, NonterminalData, NonterminalString, - Span, SymbolKind, TypeRef}; + Path, + Span, + SymbolKind, TypeRef}; use grammar::repr::{NominalTypeRepr, Types, TypeRepr}; #[cfg(test)] @@ -199,7 +203,7 @@ impl<'grammar> TypeInferencer<'grammar> { Ok(TypeRepr::Lifetime(id)) } TypeRef::Id(id) => { - Ok(TypeRepr::Nominal(NominalTypeRepr { path: vec![id], + Ok(TypeRepr::Nominal(NominalTypeRepr { path: Path::from_id(id), types: vec![] })) } TypeRef::Ref { lifetime, mutable, ref referent } => { diff --git a/lalrpop/src/parser/mod.rs b/lalrpop/src/parser/mod.rs index fb92d9f..5b6d7c5 100644 --- a/lalrpop/src/parser/mod.rs +++ b/lalrpop/src/parser/mod.rs @@ -2,16 +2,15 @@ use intern::{intern, InternedString}; use grammar::parse_tree::*; use grammar::pattern::*; use rusty_peg; -use std::iter; #[cfg(test)] mod test; fn make_list(head: Vec<(T, &'static str)>, - tail: Option<(T, Option<&'static str>)>) + tail: Option) -> Vec { head.into_iter().map(|(a,_)| a) - .chain(tail.map(|(a, _)| a).into_iter()) + .chain(tail) .collect() } @@ -32,7 +31,7 @@ rusty_peg! { }; GRAMMAR_TPS: Vec = - ("<" ">") => make_list(h, t); + ("<" ">") => make_list(h, t); TYPE_PARAMETER: TypeParameter = (LIFETIME_TYPE_PARAMETER / ID_TYPE_PARAMETER); @@ -44,13 +43,13 @@ rusty_peg! { () => TypeParameter::Id(l); GRAMMAR_PARAMS: Vec = - ("(" ")") => make_list(h, t); + ("(" ")") => make_list(h, t); GRAMMAR_PARAM: Parameter = ( ":" ) => Parameter { name: id, ty: t }; WHERE_CLAUSES: Vec = - ("where" ) => make_list(h, t); + ("where" ) => make_list(h, t); GRAMMAR_ITEM: GrammarItem = (EXTERN_TOKEN / NONTERMINAL / USE); @@ -83,7 +82,7 @@ rusty_peg! { () => (NonterminalString(a), vec![]); NONTERMINAL_NAME_MACRO: (NonterminalString, Vec) = - ( "<" ">") => { + ( "<" ">") => { (a, make_list(b, c)) }; @@ -157,7 +156,7 @@ rusty_peg! { (MACRO_SYMBOL / TERMINAL_SYMBOL / NT_SYMBOL / ESCAPE_SYMBOL / PAREN_SYMBOL); MACRO_SYMBOL: Symbol = - ( ">" ) => { + ( ">" ) => { Symbol::new(Span(lo, hi), SymbolKind::Macro(MacroSymbol { name: l, args: make_list(m, n) })) @@ -213,14 +212,15 @@ rusty_peg! { NOMINAL_TYPE_REF: TypeRef = ( ) => { - if p.len() == 1 && a.is_none() { - // detect something like `Foo` and treat it specially, - // so that macro expansion can pattern match here - TypeRef::Id(p.into_iter().next().unwrap()) - } else { - // otherwise, `Vec<..>` or `Foo::Bar` etc expand to - // this full path - TypeRef::Nominal { path: p, types: a.unwrap_or(vec![]) } + match p.as_id() { + Some(id) if a.is_none() => + // detect something like `Foo` and treat it specially, + // so that macro expansion can pattern match here + TypeRef::Id(id), + _ => + // otherwise, `Vec<..>` or `Foo::Bar` etc expand to + // this full path + TypeRef::Nominal { path: p, types: a.unwrap_or(vec![]) } } }; @@ -237,22 +237,18 @@ rusty_peg! { TYPE_REF_COMMA: TypeRef = ( ",") => t; - PATH: Vec = - ( ) => { - let mut b = b; - b.push(c); - b + PATH: Path = + ( ) => { + Path { absolute: a.is_some(), + ids: make_list(h, Some(t)) } }; - PATH_BASE: InternedString = - ( "::") => i; - // TOKEN DEFINITIONS EXTERN_TOKEN: GrammarItem = ("extern" "token" "{" "enum" "{" - + "}" "}") => { GrammarItem::ExternToken(ExternToken { @@ -274,14 +270,14 @@ rusty_peg! { DOTDOT_PATTERN / CHOOSE_PATTERN / TUPLE_PATTERN / PATH_PATTERN); ENUM_PATTERN: Pattern = - ( "(" ")" ) => { + ( "(" ")" ) => { Pattern { span: Span(lo, hi), kind: PatternKind::Enum(p, make_list(s0, s1)) } }; STRUCT_PATTERN0: Pattern = ( "{" - "}" ) => { + "}" ) => { Pattern { span: Span(lo, hi), kind: PatternKind::Struct(p, make_list(s0, s1), @@ -322,17 +318,14 @@ rusty_peg! { }; TUPLE_PATTERN: Pattern = - ( "(" ")" ) => { + ( "(" ")" ) => { Pattern { span: Span(lo, hi), kind: PatternKind::Tuple(make_list(p0, p1)) } }; PATH_PATTERN: Pattern = - ( ) => { - let path = iter::once(id0).chain(id1.into_iter().map(|pair| pair.1)) - .collect(); - Pattern { span: Span(lo, hi), - kind: PatternKind::Path(path) } + ( ) => { + Pattern { span: Span(lo, hi), kind: PatternKind::Path(p) } }; // IDENTIFIERS, LIFETIMES diff --git a/lalrpop/src/util.rs b/lalrpop/src/util.rs index 6b83113..defb348 100644 --- a/lalrpop/src/util.rs +++ b/lalrpop/src/util.rs @@ -19,6 +19,23 @@ impl<'a,S:Display> Display for Sep<&'a Vec> { } } +pub struct Escape(pub S); + +impl Display for Escape { + fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { + let tmp = format!("{}", self.0); + for c in tmp.chars() { + match c { + 'a' ... 'z' | '_' | '0' ... '9' | 'A' ... 'Z' => + try!(write!(fmt, "{}", c)), + _ => + try!(write!(fmt, "_")), // um, obviously not the best escaping :) + } + } + Ok(()) + } +} + pub struct Prefix(pub &'static str, pub S); impl<'a,S:Display> Display for Prefix<&'a [S]> {