From 0ee3ac81d65e75be627d8e4e414d532e3c84dd67 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 14 Jul 2015 11:47:31 -0400 Subject: [PATCH] add some more namespacing --- lalrpop-test/src/expr.rs | 2492 ++++++++++++++++++------------------- lalrpop-test/src/sub.rs | 306 ++--- lalrpop/src/lr1/ascent.rs | 12 +- 3 files changed, 1405 insertions(+), 1405 deletions(-) diff --git a/lalrpop-test/src/expr.rs b/lalrpop-test/src/expr.rs index 218e154..b089731 100644 --- a/lalrpop-test/src/expr.rs +++ b/lalrpop-test/src/expr.rs @@ -1,8 +1,8 @@ use util::tok::Tok; #[allow(non_snake_case)] -pub fn parse_Expr>( - __tokens: TOKENS) +pub fn parse_Expr<__TOKENS: IntoIterator>( + __tokens: __TOKENS) -> Result<(Option, i32), Option> { let mut __tokens = __tokens.into_iter(); @@ -19,10 +19,10 @@ mod __parse__Expr { use util::tok::Tok; pub enum __Nonterminal { - Term(i32), - Expr(i32), - __Expr(i32), Factor(i32), + Term(i32), + __Expr(i32), + Expr(i32), } // State 0 @@ -62,27 +62,27 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // __Expr = (*) Expr [EOF] // - // "Num" -> Shift(S4) - // "(" -> Shift(S3) + // "(" -> Shift(S1) + // "Num" -> Shift(S5) // - // Factor -> S2 - // Expr -> S1 - // Term -> S5 - pub fn __state0>( + // Term -> S2 + // Expr -> S4 + // Factor -> S3 + pub fn __state0<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(Tok::Num(__tok0)) => { - let mut __sym0 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state4(__lookahead, __tokens, __sym0)); - } Some(__tok @ Tok::LParen(..)) => { let mut __sym0 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state3(__lookahead, __tokens, __sym0)); + __result = try!(__state1(__lookahead, __tokens, __sym0)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym0 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(__lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); @@ -91,17 +91,17 @@ mod __parse__Expr { loop { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Factor(__nt) => { + __Nonterminal::Term(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state2(__lookahead, __tokens, __sym0)); } __Nonterminal::Expr(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state1(__lookahead, __tokens, __sym0)); + __result = try!(__state4(__lookahead, __tokens, __sym0)); } - __Nonterminal::Term(__nt) => { + __Nonterminal::Factor(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state5(__lookahead, __tokens, __sym0)); + __result = try!(__state3(__lookahead, __tokens, __sym0)); } _ => { return Ok((__lookahead, __nt)); @@ -111,108 +111,6 @@ 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>( - mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym0, __sym1)); - } - Some(__tok @ Tok::Plus(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state7(__lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action0(__sym0); - return Ok((__lookahead, __Nonterminal::__Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 2 - // Expr = Factor (*) [EOF] - // Expr = Factor (*) ["+"] - // Expr = Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // EOF -> Reduce(Expr = Factor => ActionFn(3);) - // "/" -> Shift(S8) - // "+" -> Reduce(Expr = Factor => ActionFn(3);) - // "*" -> Shift(S9) - // "-" -> Reduce(Expr = Factor => ActionFn(3);) - // - pub fn __state2>( - 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!(__state8(__lookahead, __tokens, __sym0, __sym1)); - } - Some(__tok @ Tok::Times(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state9(__lookahead, __tokens, __sym0, __sym1)); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 3 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -253,15 +151,15 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S14) - // "Num" -> Shift(S12) + // "(" -> Shift(S8) + // "Num" -> Shift(S7) // - // Factor -> S11 - // Term -> S10 - // Expr -> S13 - pub fn __state3>( + // Expr -> S9 + // Term -> S6 + // Factor -> S10 + pub fn __state1<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); @@ -269,12 +167,12 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state14(__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!(__state12(__lookahead, __tokens, __sym1)); + __result = try!(__state7(__lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); @@ -283,17 +181,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!(__state11(__lookahead, __tokens, __sym1)); + __result = try!(__state9(__lookahead, __tokens, __sym0, __sym1)); } __Nonterminal::Term(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state10(__lookahead, __tokens, __sym1)); + __result = try!(__state6(__lookahead, __tokens, __sym1)); } - __Nonterminal::Expr(__nt) => { + __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state13(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state10(__lookahead, __tokens, __sym1)); } _ => { return Ok((__lookahead, __nt)); @@ -303,50 +201,50 @@ mod __parse__Expr { return Ok(__result); } - // State 4 - // Term = "Num" (*) [EOF] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] + // State 2 + // Factor = Term (*) [EOF] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] // - // "*" -> Reduce(Term = "Num" => ActionFn(7);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // "+" -> Reduce(Term = "Num" => ActionFn(7);) - // "-" -> Reduce(Term = "Num" => ActionFn(7);) - // EOF -> Reduce(Term = "Num" => ActionFn(7);) + // 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 __state4>( + pub fn __state2<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(Tok::Times(..)) => { + None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action6(__sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action6(__sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action6(__sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action6(__sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } - None => { + Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action6(__sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); @@ -354,50 +252,152 @@ mod __parse__Expr { } } - // State 5 - // Factor = Term (*) [EOF] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] + // State 3 + // 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 ["/"] // - // "/" -> Reduce(Factor = Term => ActionFn(6);) - // "+" -> Reduce(Factor = Term => ActionFn(6);) - // "*" -> Reduce(Factor = Term => ActionFn(6);) - // "-" -> Reduce(Factor = Term => ActionFn(6);) - // EOF -> Reduce(Factor = Term => ActionFn(6);) + // "/" -> Shift(S12) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // EOF -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S11) // - pub fn __state5>( + pub fn __state3<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + Some(__tok @ Tok::Div(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(__lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state11(__lookahead, __tokens, __sym0, __sym1)); } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } None => { let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 4 + // Expr = Expr (*) "+" Factor [EOF] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [EOF] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // __Expr = Expr (*) [EOF] + // + // "-" -> Shift(S14) + // EOF -> Reduce(__Expr = Expr => ActionFn(0);) + // "+" -> Shift(S13) + // + 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 @ Tok::Minus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state14(__lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state13(__lookahead, __tokens, __sym0, __sym1)); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action0(__sym0); + return Ok((__lookahead, __Nonterminal::__Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 5 + // Term = "Num" (*) [EOF] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // EOF -> Reduce(Term = "Num" => ActionFn(7);) + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // + pub fn __state5<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action7(__sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action7(__sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action7(__sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action7(__sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action7(__sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); } _ => { return Err(__lookahead); @@ -406,313 +406,45 @@ mod __parse__Expr { } // State 6 - // Expr = Expr "-" (*) Factor [EOF] - // Expr = Expr "-" (*) Factor ["+"] - // Expr = Expr "-" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "Num" -> Shift(S4) - // "(" -> Shift(S3) - // - // Factor -> S15 - // Term -> S5 - pub fn __state6>( - 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(__lookahead, __tokens, __sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state3(__lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state15(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state5(__lookahead, __tokens, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 7 - // Expr = Expr "+" (*) Factor [EOF] - // Expr = Expr "+" (*) Factor ["+"] - // Expr = Expr "+" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "Num" -> Shift(S4) - // "(" -> Shift(S3) - // - // Term -> S5 - // Factor -> S16 - pub fn __state7>( - 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(__lookahead, __tokens, __sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state3(__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!(__state5(__lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state16(__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" ["/"] - // - // "Num" -> Shift(S4) - // "(" -> Shift(S3) - // - // Term -> S17 - pub fn __state8>( - 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(__lookahead, __tokens, __sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state3(__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(__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" ["/"] - // - // "Num" -> Shift(S4) - // "(" -> Shift(S3) - // - // Term -> S18 - pub fn __state9>( - 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(__lookahead, __tokens, __sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state3(__lookahead, __tokens, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - while __sym1.is_some() { - let (__lookahead, __nt) = __result; - match __nt { - __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state18(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 10 // Factor = Term (*) [")"] // Factor = Term (*) ["*"] // Factor = Term (*) ["+"] // Factor = Term (*) ["-"] // Factor = Term (*) ["/"] // - // "-" -> Reduce(Factor = Term => ActionFn(6);) // "*" -> Reduce(Factor = Term => ActionFn(6);) - // ")" -> Reduce(Factor = Term => ActionFn(6);) // "/" -> Reduce(Factor = Term => ActionFn(6);) + // ")" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) // "+" -> Reduce(Factor = Term => ActionFn(6);) // - pub fn __state10>( + pub fn __state6<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __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::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__action6(__sym0); return Ok((__lookahead, __Nonterminal::Factor(__nt))); } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action6(__sym0); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__action6(__sym0); return Ok((__lookahead, __Nonterminal::Factor(__nt))); } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action6(__sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action6(__sym0); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } Some(Tok::Plus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__action6(__sym0); @@ -724,67 +456,7 @@ mod __parse__Expr { } } - // State 11 - // 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);) - // "+" -> Reduce(Expr = Factor => ActionFn(3);) - // "/" -> Shift(S20) - // "*" -> Shift(S19) - // "-" -> Reduce(Expr = Factor => ActionFn(3);) - // - pub fn __state11>( - 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!(__state20(__lookahead, __tokens, __sym0, __sym1)); - } - Some(__tok @ Tok::Times(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state19(__lookahead, __tokens, __sym0, __sym1)); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 12 + // State 7 // Term = "Num" (*) [")"] // Term = "Num" (*) ["*"] // Term = "Num" (*) ["+"] @@ -792,14 +464,14 @@ mod __parse__Expr { // 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);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // "-" -> Reduce(Term = "Num" => ActionFn(7);) // - pub fn __state12>( + pub fn __state7<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); @@ -809,6 +481,16 @@ mod __parse__Expr { let __nt = super::__action7(__sym0); return Ok((__lookahead, __Nonterminal::Term(__nt))); } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action7(__sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action7(__sym0); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__action7(__sym0); @@ -819,70 +501,13 @@ mod __parse__Expr { let __nt = super::__action7(__sym0); return Ok((__lookahead, __Nonterminal::Term(__nt))); } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action7(__sym0); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } _ => { return Err(__lookahead); } } } - // State 13 - // Expr = Expr (*) "+" Factor [")"] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [")"] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // Term = "(" Expr (*) ")" [EOF] - // Term = "(" Expr (*) ")" ["*"] - // Term = "(" Expr (*) ")" ["+"] - // Term = "(" Expr (*) ")" ["-"] - // Term = "(" Expr (*) ")" ["/"] - // - // ")" -> Shift(S21) - // "-" -> Shift(S22) - // "+" -> Shift(S23) - // - pub fn __state13>( - mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::RParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state21(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state22(__lookahead, __tokens, __sym1, __sym2)); - } - Some(__tok @ Tok::Plus(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state23(__lookahead, __tokens, __sym1, __sym2)); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 14 + // State 8 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -923,28 +548,28 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S12) - // "(" -> Shift(S14) + // "(" -> Shift(S8) + // "Num" -> Shift(S7) // - // Factor -> S11 - // Term -> S10 - // Expr -> S24 - pub fn __state14>( + // Term -> S6 + // Factor -> S10 + // Expr -> S15 + pub fn __state8<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __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!(__state12(__lookahead, __tokens, __sym1)); - } Some(__tok @ Tok::LParen(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state14(__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!(__state7(__lookahead, __tokens, __sym1)); } _ => { return Err(__lookahead); @@ -953,17 +578,392 @@ mod __parse__Expr { while __sym0.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Factor(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state11(__lookahead, __tokens, __sym1)); - } __Nonterminal::Term(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state6(__lookahead, __tokens, __sym1)); + } + __Nonterminal::Factor(__nt) => { let __sym1 = &mut Some(__nt); __result = try!(__state10(__lookahead, __tokens, __sym1)); } __Nonterminal::Expr(__nt) => { let __sym1 = &mut Some(__nt); - __result = try!(__state24(__lookahead, __tokens, __sym0, __sym1)); + __result = try!(__state15(__lookahead, __tokens, __sym0, __sym1)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 9 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [EOF] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // ")" -> Shift(S17) + // "-" -> Shift(S16) + // "+" -> Shift(S18) + // + 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::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state17(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state16(__lookahead, __tokens, __sym1, __sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state18(__lookahead, __tokens, __sym1, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 10 + // Expr = Factor (*) [")"] + // Expr = Factor (*) ["+"] + // Expr = Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // ")" -> Reduce(Expr = Factor => ActionFn(3);) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S19) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // "/" -> Shift(S20) + // + 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 @ Tok::Times(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state19(__lookahead, __tokens, __sym0, __sym1)); + } + Some(__tok @ Tok::Div(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state20(__lookahead, __tokens, __sym0, __sym1)); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 11 + // Factor = Factor "*" (*) Term [EOF] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S1) + // "Num" -> Shift(S5) + // + // Term -> S21 + pub fn __state11<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state1(__lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(__lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state21(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 12 + // Factor = Factor "/" (*) Term [EOF] + // Factor = Factor "/" (*) Term ["*"] + // Factor = Factor "/" (*) Term ["+"] + // Factor = Factor "/" (*) Term ["-"] + // Factor = Factor "/" (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S1) + // "Num" -> Shift(S5) + // + // Term -> S22 + pub fn __state12<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state1(__lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(__lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state22(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 13 + // Expr = Expr "+" (*) Factor [EOF] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S1) + // "Num" -> Shift(S5) + // + // Factor -> S23 + // Term -> S2 + 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!(__state1(__lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(__lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state23(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state2(__lookahead, __tokens, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 14 + // Expr = Expr "-" (*) Factor [EOF] + // Expr = Expr "-" (*) Factor ["+"] + // Expr = Expr "-" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S5) + // "(" -> Shift(S1) + // + // Factor -> S24 + // Term -> S2 + pub fn __state14<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(__lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state1(__lookahead, __tokens, __sym2)); + } + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state24(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state2(__lookahead, __tokens, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -974,65 +974,44 @@ mod __parse__Expr { } // 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 ["/"] + // 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 (*) ")" ["/"] // - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "*" -> Shift(S9) - // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S8) + // "-" -> Shift(S16) + // ")" -> Shift(S25) + // "+" -> Shift(S18) // - pub fn __state15>( + pub fn __state15<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut __sym3 = &mut Some(__tok); + Some(__tok @ Tok::Minus(..)) => { + let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state9(__lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state16(__lookahead, __tokens, __sym1, __sym2)); } - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some(__tok); + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state8(__lookahead, __tokens, __sym2, __sym3)); + __result = try!(__state25(__lookahead, __tokens, __sym0, __sym1, __sym2)); } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action1(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action1(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action1(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); + Some(__tok @ Tok::Plus(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state18(__lookahead, __tokens, __sym1, __sym2)); } _ => { return Err(__lookahead); @@ -1042,379 +1021,6 @@ mod __parse__Expr { } // 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 ["/"] - // - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "*" -> Shift(S9) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "/" -> Shift(S8) - // - pub fn __state16>( - mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state9(__lookahead, __tokens, __sym2, __sym3)); - } - Some(__tok @ Tok::Div(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state8(__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::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } - _ => { - return Err(__lookahead); - } - } - return Ok(__result); - } - - // State 17 - // Factor = Factor "/" Term (*) [EOF] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] - // - // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(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 __state17>( - mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 18 - // Factor = Factor "*" Term (*) [EOF] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] - // - // 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 __state18>( - 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::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 19 - // Factor = Factor "*" (*) Term [")"] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "Num" -> Shift(S12) - // "(" -> Shift(S14) - // - // Term -> S25 - pub fn __state19>( - 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(__lookahead, __tokens, __sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state14(__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!(__state25(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 20 - // 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(S14) - // "Num" -> Shift(S12) - // - // Term -> S26 - pub fn __state20>( - 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!(__state14(__lookahead, __tokens, __sym2)); - } - Some(Tok::Num(__tok0)) => { - let mut __sym2 = &mut Some((__tok0)); - let __lookahead = __tokens.next(); - __result = try!(__state12(__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(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } - _ => { - return Ok((__lookahead, __nt)); - } - } - } - return Ok(__result); - } - - // State 21 - // Term = "(" Expr ")" (*) [EOF] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] - // - // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // - pub fn __state21>( - mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 22 // Expr = Expr "-" (*) Factor [")"] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -1444,14 +1050,14 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S14) - // "Num" -> Shift(S12) + // "(" -> Shift(S8) + // "Num" -> Shift(S7) // - // Factor -> S27 - // Term -> S10 - pub fn __state22>( + // Term -> S6 + // Factor -> S26 + pub fn __state16<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { @@ -1460,12 +1066,12 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state14(__lookahead, __tokens, __sym2)); + __result = try!(__state8(__lookahead, __tokens, __sym2)); } Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym2)); + __result = try!(__state7(__lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1474,13 +1080,13 @@ mod __parse__Expr { while __sym1.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::Factor(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state27(__lookahead, __tokens, __sym0, __sym1, __sym2)); - } __Nonterminal::Term(__nt) => { let __sym2 = &mut Some(__nt); - __result = try!(__state10(__lookahead, __tokens, __sym2)); + __result = try!(__state6(__lookahead, __tokens, __sym2)); + } + __Nonterminal::Factor(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state26(__lookahead, __tokens, __sym0, __sym1, __sym2)); } _ => { return Ok((__lookahead, __nt)); @@ -1490,7 +1096,70 @@ mod __parse__Expr { return Ok(__result); } - // State 23 + // State 17 + // 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);) + // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // + pub fn __state17<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 18 // Expr = Expr "+" (*) Factor [")"] // Expr = Expr "+" (*) Factor ["+"] // Expr = Expr "+" (*) Factor ["-"] @@ -1520,28 +1189,90 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S14) - // "Num" -> Shift(S12) + // "Num" -> Shift(S7) + // "(" -> Shift(S8) // - // Term -> S10 - // Factor -> S28 - pub fn __state23>( + // Factor -> S27 + // Term -> S6 + pub fn __state18<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __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!(__state14(__lookahead, __tokens, __sym2)); - } Some(Tok::Num(__tok0)) => { let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state12(__lookahead, __tokens, __sym2)); + __result = try!(__state7(__lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(__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!(__state27(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state6(__lookahead, __tokens, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 19 + // Factor = Factor "*" (*) Term [")"] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S7) + // "(" -> Shift(S8) + // + // Term -> S28 + pub fn __state19<__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!(__state7(__lookahead, __tokens, __sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state8(__lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -1551,10 +1282,6 @@ mod __parse__Expr { let (__lookahead, __nt) = __result; match __nt { __Nonterminal::Term(__nt) => { - let __sym2 = &mut Some(__nt); - __result = try!(__state10(__lookahead, __tokens, __sym2)); - } - __Nonterminal::Factor(__nt) => { let __sym2 = &mut Some(__nt); __result = try!(__state28(__lookahead, __tokens, __sym0, __sym1, __sym2)); } @@ -1566,45 +1293,318 @@ mod __parse__Expr { 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 (*) ")" ["/"] + // State 20 + // 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(S23) - // ")" -> Shift(S29) - // "-" -> Shift(S22) + // "(" -> Shift(S8) + // "Num" -> Shift(S7) // - pub fn __state24>( + // Term -> S29 + pub fn __state20<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(__tok @ Tok::Plus(..)) => { + Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state23(__lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state8(__lookahead, __tokens, __sym2)); } - Some(__tok @ Tok::RParen(..)) => { - let mut __sym2 = &mut Some(__tok); + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state29(__lookahead, __tokens, __sym0, __sym1, __sym2)); + __result = try!(__state7(__lookahead, __tokens, __sym2)); } - Some(__tok @ Tok::Minus(..)) => { - let mut __sym2 = &mut Some(__tok); + _ => { + return Err(__lookahead); + } + } + while __sym1.is_some() { + let (__lookahead, __nt) = __result; + match __nt { + __Nonterminal::Term(__nt) => { + let __sym2 = &mut Some(__nt); + __result = try!(__state29(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } + _ => { + return Ok((__lookahead, __nt)); + } + } + } + return Ok(__result); + } + + // State 21 + // Factor = Factor "*" Term (*) [EOF] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // EOF -> Reduce(Factor = Factor, "*", Term => ActionFn(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 __state21<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 22 + // Factor = Factor "/" Term (*) [EOF] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(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 __state22<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 23 + // Expr = Expr "+" Factor (*) [EOF] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "/" -> Shift(S12) + // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S11) + // + pub fn __state23<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state22(__lookahead, __tokens, __sym1, __sym2)); + __result = try!(__state12(__lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state11(__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::__action2(__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::__action2(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action2(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + _ => { + return Err(__lookahead); + } + } + return Ok(__result); + } + + // State 24 + // Expr = Expr "-" Factor (*) [EOF] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S12) + // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "*" -> Shift(S11) + // + pub fn __state24<__TOKENS: Iterator>( + mut __lookahead: Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut __result: (Option, __Nonterminal); + match __lookahead { + Some(__tok @ Tok::Div(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state12(__lookahead, __tokens, __sym2, __sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state11(__lookahead, __tokens, __sym2, __sym3)); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action1(__sym0, __sym1, __sym2); + 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::__action1(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action1(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } _ => { return Err(__lookahead); @@ -1614,61 +1614,61 @@ mod __parse__Expr { } // State 25 - // Factor = Factor "*" Term (*) [")"] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] + // Term = "(" Expr ")" (*) [")"] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] // - // "/" -> Reduce(Factor = Factor, "*", Term => 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(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>( + pub fn __state25<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } Some(Tok::Div(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); } Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); } Some(Tok::Times(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action4(__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::__action4(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); + let __nt = super::__action8(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Term(__nt))); } _ => { return Err(__lookahead); @@ -1677,69 +1677,6 @@ mod __parse__Expr { } // State 26 - // Factor = Factor "/" Term (*) [")"] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] - // - // "*" -> Reduce(Factor = Factor, "/", Term => 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>( - mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut __result: (Option, __Nonterminal); - match __lookahead { - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Div(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::RParen(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - Some(Tok::Minus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action5(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Factor(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 27 // Expr = Expr "-" Factor (*) [")"] // Expr = Expr "-" Factor (*) ["+"] // Expr = Expr "-" Factor (*) ["-"] @@ -1757,12 +1694,12 @@ mod __parse__Expr { // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // "*" -> Shift(S19) // "/" -> Shift(S20) - // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // - pub fn __state27>( + pub fn __state26<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, @@ -1786,14 +1723,14 @@ mod __parse__Expr { let __nt = super::__action1(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::Expr(__nt))); } - Some(Tok::RParen(..)) => { + Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__action1(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::Expr(__nt))); } - Some(Tok::Minus(..)) => { + Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); @@ -1807,7 +1744,7 @@ mod __parse__Expr { return Ok(__result); } - // State 28 + // State 27 // Expr = Expr "+" Factor (*) [")"] // Expr = Expr "+" Factor (*) ["+"] // Expr = Expr "+" Factor (*) ["-"] @@ -1822,30 +1759,37 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "/" -> Shift(S20) - // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "*" -> Shift(S19) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S19) + // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "/" -> Shift(S20) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // - pub fn __state28>( + pub fn __state27<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { + Some(__tok @ Tok::Times(..)) => { + let mut __sym3 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state19(__lookahead, __tokens, __sym2, __sym3)); + } Some(__tok @ Tok::Div(..)) => { let mut __sym3 = &mut Some(__tok); let __lookahead = __tokens.next(); __result = try!(__state20(__lookahead, __tokens, __sym2, __sym3)); } - Some(__tok @ Tok::Times(..)) => { - let mut __sym3 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state19(__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::__action2(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Expr(__nt))); } Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); @@ -1861,13 +1805,6 @@ mod __parse__Expr { let __nt = super::__action2(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::Expr(__nt))); } - Some(Tok::Plus(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action2(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Expr(__nt))); - } _ => { return Err(__lookahead); } @@ -1875,62 +1812,125 @@ mod __parse__Expr { return Ok(__result); } - // State 29 - // Term = "(" Expr ")" (*) [")"] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] + // State 28 + // Factor = Factor "*" Term (*) [")"] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] // - // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // - pub fn __state29>( + pub fn __state28<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, - __sym0: &mut Option, - __sym1: &mut Option, - __sym2: &mut Option, + __tokens: &mut __TOKENS, + __sym0: &mut Option, + __sym1: &mut Option, + __sym2: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(Tok::Div(..)) => { + Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); - } - Some(Tok::Times(..)) => { - let __sym0 = __sym0.take().unwrap(); - let __sym1 = __sym1.take().unwrap(); - let __sym2 = __sym2.take().unwrap(); - let __nt = super::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action4(__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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action4(__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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action4(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // State 29 + // 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 __state29<__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::__action8(__sym0, __sym1, __sym2); - return Ok((__lookahead, __Nonterminal::Term(__nt))); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Times(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Plus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::RParen(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); + } + Some(Tok::Div(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __sym1 = __sym1.take().unwrap(); + let __sym2 = __sym2.take().unwrap(); + let __nt = super::__action5(__sym0, __sym1, __sym2); + return Ok((__lookahead, __Nonterminal::Factor(__nt))); } _ => { return Err(__lookahead); diff --git a/lalrpop-test/src/sub.rs b/lalrpop-test/src/sub.rs index 0d7c9f7..15ad303 100644 --- a/lalrpop-test/src/sub.rs +++ b/lalrpop-test/src/sub.rs @@ -1,8 +1,8 @@ use util::tok::Tok; #[allow(non_snake_case)] -pub fn parse_S>( - __tokens: TOKENS) +pub fn parse_S<__TOKENS: IntoIterator>( + __tokens: __TOKENS) -> Result<(Option, i32), Option> { let mut __tokens = __tokens.into_iter(); @@ -19,10 +19,10 @@ mod __parse__S { use util::tok::Tok; pub enum __Nonterminal { - __S(i32), - T(i32), E(i32), S(i32), + __S(i32), + T(i32), } // State 0 @@ -37,27 +37,27 @@ mod __parse__S { // T = (*) "Num" ["-"] // __S = (*) S [EOF] // - // "(" -> Shift(S2) - // "Num" -> Shift(S1) + // "(" -> Shift(S1) + // "Num" -> Shift(S5) // - // S -> S4 - // E -> S5 - // T -> S3 - pub fn __state0>( + // T -> S4 + // S -> S2 + // E -> S3 + pub fn __state0<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { Some(__tok @ Tok::LParen(..)) => { let mut __sym0 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state2(__lookahead, __tokens, __sym0)); + __result = try!(__state1(__lookahead, __tokens, __sym0)); } Some(Tok::Num(__tok0)) => { let mut __sym0 = &mut Some((__tok0)); let __lookahead = __tokens.next(); - __result = try!(__state1(__lookahead, __tokens, __sym0)); + __result = try!(__state5(__lookahead, __tokens, __sym0)); } _ => { return Err(__lookahead); @@ -66,15 +66,15 @@ mod __parse__S { loop { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::S(__nt) => { + __Nonterminal::T(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state4(__lookahead, __tokens, __sym0)); } - __Nonterminal::E(__nt) => { + __Nonterminal::S(__nt) => { let __sym0 = &mut Some(__nt); - __result = try!(__state5(__lookahead, __tokens, __sym0)); + __result = try!(__state2(__lookahead, __tokens, __sym0)); } - __Nonterminal::T(__nt) => { + __Nonterminal::E(__nt) => { let __sym0 = &mut Some(__nt); __result = try!(__state3(__lookahead, __tokens, __sym0)); } @@ -86,36 +86,6 @@ mod __parse__S { } // State 1 - // T = "Num" (*) [EOF] - // T = "Num" (*) ["-"] - // - // "-" -> Reduce(T = "Num" => ActionFn(4);) - // EOF -> Reduce(T = "Num" => ActionFn(4);) - // - pub fn __state1>( - 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::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action4(__sym0); - return Ok((__lookahead, __Nonterminal::T(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 2 // E = (*) E "-" T [")"] // E = (*) E "-" T ["-"] // E = (*) T [")"] @@ -127,28 +97,28 @@ mod __parse__S { // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "Num" -> Shift(S8) // "(" -> Shift(S6) + // "Num" -> Shift(S8) // - // E -> S9 // T -> S7 - pub fn __state2>( + // E -> S9 + pub fn __state1<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __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!(__state8(__lookahead, __tokens, __sym1)); - } Some(__tok @ Tok::LParen(..)) => { let mut __sym1 = &mut Some(__tok); let __lookahead = __tokens.next(); __result = try!(__state6(__lookahead, __tokens, __sym1)); } + Some(Tok::Num(__tok0)) => { + let mut __sym1 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state8(__lookahead, __tokens, __sym1)); + } _ => { return Err(__lookahead); } @@ -156,14 +126,14 @@ mod __parse__S { while __sym0.is_some() { let (__lookahead, __nt) = __result; match __nt { - __Nonterminal::E(__nt) => { - let __sym1 = &mut Some(__nt); - __result = try!(__state9(__lookahead, __tokens, __sym0, __sym1)); - } __Nonterminal::T(__nt) => { let __sym1 = &mut Some(__nt); __result = try!(__state7(__lookahead, __tokens, __sym1)); } + __Nonterminal::E(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state9(__lookahead, __tokens, __sym0, __sym1)); + } _ => { return Ok((__lookahead, __nt)); } @@ -172,44 +142,14 @@ mod __parse__S { return Ok(__result); } - // State 3 - // E = T (*) [EOF] - // E = T (*) ["-"] - // - // "-" -> Reduce(E = T => ActionFn(3);) - // EOF -> Reduce(E = T => ActionFn(3);) - // - pub fn __state3>( - 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::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - None => { - let __sym0 = __sym0.take().unwrap(); - let __nt = super::__action3(__sym0); - return Ok((__lookahead, __Nonterminal::E(__nt))); - } - _ => { - return Err(__lookahead); - } - } - } - - // State 4 + // State 2 // __S = S (*) [EOF] // // EOF -> Reduce(__S = S => ActionFn(0);) // - pub fn __state4>( + pub fn __state2<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); @@ -225,17 +165,17 @@ mod __parse__S { } } - // State 5 + // State 3 // E = E (*) "-" T [EOF] // E = E (*) "-" T ["-"] // S = E (*) [EOF] // - // EOF -> Reduce(S = E => ActionFn(1);) // "-" -> Shift(S10) + // EOF -> Reduce(S = E => ActionFn(1);) // - pub fn __state5>( + pub fn __state3<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); @@ -257,6 +197,66 @@ mod __parse__S { return Ok(__result); } + // State 4 + // E = T (*) [EOF] + // E = T (*) ["-"] + // + // EOF -> Reduce(E = T => ActionFn(3);) + // "-" -> Reduce(E = T => ActionFn(3);) + // + 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 { + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::E(__nt))); + } + Some(Tok::Minus(..)) => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action3(__sym0); + return Ok((__lookahead, __Nonterminal::E(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + + // 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::__action4(__sym0); + return Ok((__lookahead, __Nonterminal::T(__nt))); + } + None => { + let __sym0 = __sym0.take().unwrap(); + let __nt = super::__action4(__sym0); + return Ok((__lookahead, __Nonterminal::T(__nt))); + } + _ => { + return Err(__lookahead); + } + } + } + // State 6 // E = (*) E "-" T [")"] // E = (*) E "-" T ["-"] @@ -269,28 +269,28 @@ mod __parse__S { // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "(" -> Shift(S6) // "Num" -> Shift(S8) + // "(" -> Shift(S6) // - // T -> S7 // E -> S11 - pub fn __state6>( + // T -> S7 + pub fn __state6<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut __sym1 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state6(__lookahead, __tokens, __sym1)); - } Some(Tok::Num(__tok0)) => { let mut __sym1 = &mut Some((__tok0)); let __lookahead = __tokens.next(); __result = try!(__state8(__lookahead, __tokens, __sym1)); } + Some(__tok @ Tok::LParen(..)) => { + let mut __sym1 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state6(__lookahead, __tokens, __sym1)); + } _ => { return Err(__lookahead); } @@ -298,14 +298,14 @@ mod __parse__S { 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!(__state11(__lookahead, __tokens, __sym0, __sym1)); } + __Nonterminal::T(__nt) => { + let __sym1 = &mut Some(__nt); + __result = try!(__state7(__lookahead, __tokens, __sym1)); + } _ => { return Ok((__lookahead, __nt)); } @@ -318,22 +318,22 @@ mod __parse__S { // E = T (*) [")"] // E = T (*) ["-"] // - // "-" -> Reduce(E = T => ActionFn(3);) // ")" -> Reduce(E = T => ActionFn(3);) + // "-" -> Reduce(E = T => ActionFn(3);) // - pub fn __state7>( + pub fn __state7<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(Tok::Minus(..)) => { + Some(Tok::RParen(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__action3(__sym0); return Ok((__lookahead, __Nonterminal::E(__nt))); } - Some(Tok::RParen(..)) => { + Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __nt = super::__action3(__sym0); return Ok((__lookahead, __Nonterminal::E(__nt))); @@ -351,9 +351,9 @@ mod __parse__S { // ")" -> Reduce(T = "Num" => ActionFn(4);) // "-" -> Reduce(T = "Num" => ActionFn(4);) // - pub fn __state8>( + pub fn __state8<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); @@ -380,27 +380,27 @@ mod __parse__S { // T = "(" E (*) ")" [EOF] // T = "(" E (*) ")" ["-"] // - // ")" -> Shift(S13) // "-" -> Shift(S12) + // ")" -> Shift(S13) // - pub fn __state9>( + pub fn __state9<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - Some(__tok @ Tok::RParen(..)) => { - let mut __sym2 = &mut Some(__tok); - let __lookahead = __tokens.next(); - __result = try!(__state13(__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)); } + Some(__tok @ Tok::RParen(..)) => { + let mut __sym2 = &mut Some(__tok); + let __lookahead = __tokens.next(); + __result = try!(__state13(__lookahead, __tokens, __sym0, __sym1, __sym2)); + } _ => { return Err(__lookahead); } @@ -416,27 +416,27 @@ mod __parse__S { // T = (*) "Num" [EOF] // T = (*) "Num" ["-"] // - // "Num" -> Shift(S1) - // "(" -> Shift(S2) + // "(" -> Shift(S1) + // "Num" -> Shift(S5) // // T -> S14 - pub fn __state10>( + pub fn __state10<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __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!(__state1(__lookahead, __tokens, __sym2)); - } Some(__tok @ Tok::LParen(..)) => { let mut __sym2 = &mut Some(__tok); let __lookahead = __tokens.next(); - __result = try!(__state2(__lookahead, __tokens, __sym2)); + __result = try!(__state1(__lookahead, __tokens, __sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut __sym2 = &mut Some((__tok0)); + let __lookahead = __tokens.next(); + __result = try!(__state5(__lookahead, __tokens, __sym2)); } _ => { return Err(__lookahead); @@ -466,9 +466,9 @@ mod __parse__S { // "-" -> Shift(S12) // ")" -> Shift(S15) // - pub fn __state11>( + pub fn __state11<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { @@ -503,9 +503,9 @@ mod __parse__S { // "(" -> Shift(S6) // // T -> S16 - pub fn __state12>( + pub fn __state12<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { @@ -544,26 +544,26 @@ mod __parse__S { // T = "(" E ")" (*) [EOF] // T = "(" E ")" (*) ["-"] // - // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) + // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) // - pub fn __state13>( + pub fn __state13<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __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(..)) => { + None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__action5(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::T(__nt))); } - None => { + Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); @@ -580,26 +580,26 @@ mod __parse__S { // E = E "-" T (*) [EOF] // E = E "-" T (*) ["-"] // - // EOF -> Reduce(E = E, "-", T => ActionFn(2);) // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // EOF -> Reduce(E = E, "-", T => ActionFn(2);) // - pub fn __state14>( + pub fn __state14<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut __result: (Option, __Nonterminal); match __lookahead { - None => { + Some(Tok::Minus(..)) => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); let __nt = super::__action2(__sym0, __sym1, __sym2); return Ok((__lookahead, __Nonterminal::E(__nt))); } - Some(Tok::Minus(..)) => { + None => { let __sym0 = __sym0.take().unwrap(); let __sym1 = __sym1.take().unwrap(); let __sym2 = __sym2.take().unwrap(); @@ -619,9 +619,9 @@ mod __parse__S { // ")" -> Reduce(T = "(", E, ")" => ActionFn(5);) // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) // - pub fn __state15>( + pub fn __state15<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, @@ -655,9 +655,9 @@ mod __parse__S { // "-" -> Reduce(E = E, "-", T => ActionFn(2);) // ")" -> Reduce(E = E, "-", T => ActionFn(2);) // - pub fn __state16>( + pub fn __state16<__TOKENS: Iterator>( mut __lookahead: Option, - __tokens: &mut TOKENS, + __tokens: &mut __TOKENS, __sym0: &mut Option, __sym1: &mut Option, __sym2: &mut Option, diff --git a/lalrpop/src/lr1/ascent.rs b/lalrpop/src/lr1/ascent.rs index e41bded..836acde 100644 --- a/lalrpop/src/lr1/ascent.rs +++ b/lalrpop/src/lr1/ascent.rs @@ -104,9 +104,9 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { fn write_start_fn(&mut self) -> io::Result<()> { let terminal_type = self.types.terminal_enum_type(); rust!(self.out, "#[allow(non_snake_case)]"); - rust!(self.out, "pub fn parse_{}>(", - self.user_start_symbol, terminal_type); - rust!(self.out, "{}tokens: TOKENS)", self.prefix); + rust!(self.out, "pub fn parse_{}<{}TOKENS: IntoIterator>(", + self.user_start_symbol, self.prefix, terminal_type); + rust!(self.out, "{}tokens: {}TOKENS)", self.prefix, self.prefix); rust!(self.out, "-> Result<(Option<{}>, {}), Option<{}>>", terminal_type, self.types.nonterminal_type(self.start_symbol), @@ -149,11 +149,11 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> { // set to true if goto actions are worth generating let mut fallthrough = false; - rust!(self.out, "pub fn {}state{}>(", - self.prefix, this_index.0, terminal_type); + rust!(self.out, "pub fn {}state{}<{}TOKENS: Iterator>(", + self.prefix, this_index.0, self.prefix, terminal_type); rust!(self.out, "mut {}lookahead: Option<{}>,", self.prefix, terminal_type); - rust!(self.out, "{}tokens: &mut TOKENS,", self.prefix); + rust!(self.out, "{}tokens: &mut {}TOKENS,", self.prefix, self.prefix); for i in 0..this_prefix.len() { rust!(self.out, "{}sym{}: &mut Option<{}>,", self.prefix, i, this_prefix[i].ty(&self.types));