From 4cf8bd92f28884cefb5d3453c000e0a2a9b02539 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 12 Jul 2015 09:09:33 -0400 Subject: [PATCH] update tests to just write `grammar;` instead of `grammar { }`, avoiding pointless rightward drift --- lalrpop-test/src/expr.lalrpop | 58 +- lalrpop-test/src/expr.rs | 2052 ++++++++++++++++----------------- lalrpop-test/src/sub.lalrpop | 45 +- lalrpop-test/src/sub.rs | 566 ++++----- lalrpop/src/parser/mod.rs | 2 +- lalrpop/src/parser/test.rs | 29 +- 6 files changed, 1376 insertions(+), 1376 deletions(-) diff --git a/lalrpop-test/src/expr.lalrpop b/lalrpop-test/src/expr.lalrpop index 7c64ee7..55b46e1 100644 --- a/lalrpop-test/src/expr.lalrpop +++ b/lalrpop-test/src/expr.lalrpop @@ -1,32 +1,32 @@ -grammar { - use util::tok::Tok; +grammar; - extern token { - enum Tok { - "(" => Tok::LParen(..), - ")" => Tok::RParen(..), - "-" => Tok::Minus(..), - "+" => Tok::Plus(..), - "*" => Tok::Times(..), - "/" => Tok::Div(..), - "Num" => Tok::Num() - } +use util::tok::Tok; + +extern token { + enum Tok { + "(" => Tok::LParen(..), + ")" => Tok::RParen(..), + "-" => Tok::Minus(..), + "+" => Tok::Plus(..), + "*" => Tok::Times(..), + "/" => Tok::Div(..), + "Num" => Tok::Num() } - - pub Expr = { - "-" => l - r; - "+" => l + r; - Factor; - }; - - Factor = { - "*" => l * r; - "/" => l / r; - Term; - }; - - Term = { - <"Num">; - "(" ")"; - }; } + +pub Expr = { + "-" => l - r; + "+" => l + r; + Factor; +}; + +Factor = { + "*" => l * r; + "/" => l / r; + Term; +}; + +Term = { + <"Num">; + "(" ")"; +}; diff --git a/lalrpop-test/src/expr.rs b/lalrpop-test/src/expr.rs index fb424e6..03f2f8a 100644 --- a/lalrpop-test/src/expr.rs +++ b/lalrpop-test/src/expr.rs @@ -19,10 +19,10 @@ mod __parse__Expr { use util::tok::Tok; pub enum __Nonterminal { + Factor(i32), + Expr(i32), __Expr(i32), Term(i32), - Expr(i32), - Factor(i32), } // State 0 @@ -63,11 +63,11 @@ mod __parse__Expr { // __Expr = (*) Expr [EOF] // // "Num" -> Shift(S2) - // "(" -> Shift(S4) + // "(" -> Shift(S3) // - // Expr -> S1 - // Term -> S3 - // Factor -> S5 + // Factor -> S1 + // Expr -> S4 + // Term -> S5 pub fn __state0>( mut lookahead: Option, tokens: &mut TOKENS, @@ -82,7 +82,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym0 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state4(lookahead, tokens, sym0)); + result = try!(__state3(lookahead, tokens, sym0)); } _ => { return Err(lookahead); @@ -91,15 +91,15 @@ mod __parse__Expr { loop { let (lookahead, nt) = result; match nt { - __Nonterminal::Expr(nt) => { + __Nonterminal::Factor(nt) => { let sym0 = &mut Some(nt); result = try!(__state1(lookahead, tokens, sym0)); } - __Nonterminal::Term(nt) => { + __Nonterminal::Expr(nt) => { let sym0 = &mut Some(nt); - result = try!(__state3(lookahead, tokens, sym0)); + result = try!(__state4(lookahead, tokens, sym0)); } - __Nonterminal::Factor(nt) => { + __Nonterminal::Term(nt) => { let sym0 = &mut Some(nt); result = try!(__state5(lookahead, tokens, sym0)); } @@ -111,17 +111,25 @@ mod __parse__Expr { } // State 1 - // Expr = Expr (*) "+" Factor [EOF] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [EOF] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // __Expr = Expr (*) [EOF] + // Expr = Factor (*) [EOF] + // Expr = Factor (*) ["+"] + // Expr = Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // EOF -> Reduce(__Expr = Expr => ActionFn(0);) - // "-" -> Shift(S7) - // "+" -> Shift(S6) + // "-" -> Reduce(Expr = Factor => ActionFn(3);) + // EOF -> Reduce(Expr = Factor => ActionFn(3);) + // "/" -> Shift(S6) + // "*" -> Shift(S7) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) // pub fn __state1>( mut lookahead: Option, @@ -130,20 +138,30 @@ mod __parse__Expr { ) -> 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!(__state7(lookahead, tokens, sym0, sym1)); - } - Some(__tok @ Tok::Plus(..)) => { + Some(__tok @ Tok::Div(..)) => { let mut sym1 = &mut Some(__tok); let lookahead = tokens.next(); result = try!(__state6(lookahead, tokens, sym0, sym1)); } + Some(__tok @ Tok::Times(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(lookahead, tokens, sym0, sym1)); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } None => { let sym0 = sym0.take().unwrap(); - let nt = super::__action0(sym0); - return Ok((lookahead, __Nonterminal::__Expr(nt))); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::Expr(nt))); } _ => { return Err(lookahead); @@ -159,11 +177,11 @@ mod __parse__Expr { // Term = "Num" (*) ["-"] // Term = "Num" (*) ["/"] // - // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) // "+" -> Reduce(Term = "Num" => ActionFn(7);) // EOF -> Reduce(Term = "Num" => ActionFn(7);) - // "-" -> Reduce(Term = "Num" => ActionFn(7);) // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // "*" -> Reduce(Term = "Num" => ActionFn(7);) // pub fn __state2>( mut lookahead: Option, @@ -172,7 +190,7 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Times(..)) => { + Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); let nt = super::__action7(sym0); return Ok((lookahead, __Nonterminal::Term(nt))); @@ -187,12 +205,12 @@ mod __parse__Expr { let nt = super::__action7(sym0); return Ok((lookahead, __Nonterminal::Term(nt))); } - Some(Tok::Minus(..)) => { + Some(Tok::Div(..)) => { let sym0 = sym0.take().unwrap(); let nt = super::__action7(sym0); return Ok((lookahead, __Nonterminal::Term(nt))); } - Some(Tok::Div(..)) => { + Some(Tok::Times(..)) => { let sym0 = sym0.take().unwrap(); let nt = super::__action7(sym0); return Ok((lookahead, __Nonterminal::Term(nt))); @@ -204,57 +222,6 @@ mod __parse__Expr { } // State 3 - // Factor = Term (*) [EOF] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] - // - // "+" -> Reduce(Factor = Term => ActionFn(6);) - // "*" -> Reduce(Factor = Term => ActionFn(6);) - // "-" -> Reduce(Factor = Term => ActionFn(6);) - // "/" -> Reduce(Factor = Term => ActionFn(6);) - // EOF -> Reduce(Factor = Term => ActionFn(6);) - // - pub fn __state3>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - None => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 4 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -295,13 +262,13 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S11) - // "(" -> Shift(S12) + // "Num" -> Shift(S10) + // "(" -> Shift(S8) // - // Factor -> S10 - // Term -> S9 - // Expr -> S8 - pub fn __state4>( + // Expr -> S9 + // Factor -> S11 + // Term -> S12 + pub fn __state3>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -311,12 +278,12 @@ mod __parse__Expr { Some(Tok::Num(__tok0)) => { let mut sym1 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state11(lookahead, tokens, sym1)); + result = try!(__state10(lookahead, tokens, sym1)); } Some(__tok @ Tok::LParen(..)) => { let mut sym1 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state12(lookahead, tokens, sym1)); + result = try!(__state8(lookahead, tokens, sym1)); } _ => { return Err(lookahead); @@ -325,17 +292,17 @@ mod __parse__Expr { while sym0.is_some() { let (lookahead, nt) = result; match nt { + __Nonterminal::Expr(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state9(lookahead, tokens, sym0, sym1)); + } __Nonterminal::Factor(nt) => { let sym1 = &mut Some(nt); - result = try!(__state10(lookahead, tokens, sym1)); + result = try!(__state11(lookahead, tokens, sym1)); } __Nonterminal::Term(nt) => { let sym1 = &mut Some(nt); - result = try!(__state9(lookahead, tokens, sym1)); - } - __Nonterminal::Expr(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state8(lookahead, tokens, sym0, sym1)); + result = try!(__state12(lookahead, tokens, sym1)); } _ => { return Ok((lookahead, nt)); @@ -345,58 +312,40 @@ mod __parse__Expr { return Ok(result); } - // State 5 - // Expr = Factor (*) [EOF] - // Expr = Factor (*) ["+"] - // Expr = Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] + // 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(S13) - // "+" -> Reduce(Expr = Factor => ActionFn(3);) - // "-" -> Reduce(Expr = Factor => ActionFn(3);) - // EOF -> Reduce(Expr = Factor => ActionFn(3);) - // "*" -> Shift(S14) + // EOF -> Reduce(__Expr = Expr => ActionFn(0);) + // "+" -> Shift(S13) + // "-" -> Shift(S14) // - pub fn __state5>( + pub fn __state4>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::Div(..)) => { + Some(__tok @ Tok::Plus(..)) => { let mut sym1 = &mut Some(__tok); let lookahead = tokens.next(); result = try!(__state13(lookahead, tokens, sym0, sym1)); } - Some(__tok @ Tok::Times(..)) => { + Some(__tok @ Tok::Minus(..)) => { let mut sym1 = &mut Some(__tok); let lookahead = tokens.next(); result = try!(__state14(lookahead, tokens, sym0, sym1)); } - 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))); - } None => { let sym0 = sym0.take().unwrap(); - let nt = super::__action3(sym0); - return Ok((lookahead, __Nonterminal::Expr(nt))); + let nt = super::__action0(sym0); + return Ok((lookahead, __Nonterminal::__Expr(nt))); } _ => { return Err(lookahead); @@ -405,25 +354,63 @@ mod __parse__Expr { return Ok(result); } + // State 5 + // Factor = Term (*) [EOF] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "/" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // EOF -> Reduce(Factor = Term => ActionFn(6);) + // "+" -> Reduce(Factor = Term => ActionFn(6);) + // + pub fn __state5>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__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::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + None => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + _ => { + return Err(lookahead); + } + } + } + // 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 ["/"] + // Factor = Factor "/" (*) Term [EOF] + // Factor = Factor "/" (*) Term ["*"] + // Factor = Factor "/" (*) Term ["+"] + // Factor = Factor "/" (*) Term ["-"] + // Factor = Factor "/" (*) Term ["/"] // Term = (*) "(" Expr ")" [EOF] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -436,10 +423,9 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // // "Num" -> Shift(S2) - // "(" -> Shift(S4) + // "(" -> Shift(S3) // - // Term -> S3 - // Factor -> S15 + // Term -> S15 pub fn __state6>( mut lookahead: Option, tokens: &mut TOKENS, @@ -456,7 +442,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state4(lookahead, tokens, sym2)); + result = try!(__state3(lookahead, tokens, sym2)); } _ => { return Err(lookahead); @@ -466,10 +452,6 @@ mod __parse__Expr { let (lookahead, nt) = result; match nt { __Nonterminal::Term(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state3(lookahead, tokens, sym2)); - } - __Nonterminal::Factor(nt) => { let sym2 = &mut Some(nt); result = try!(__state15(lookahead, tokens, sym0, sym1, sym2)); } @@ -482,24 +464,11 @@ mod __parse__Expr { } // State 7 - // Expr = Expr "-" (*) Factor [EOF] - // Expr = Expr "-" (*) Factor ["+"] - // Expr = Expr "-" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] + // Factor = Factor "*" (*) Term [EOF] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] // Term = (*) "(" Expr ")" [EOF] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -511,11 +480,10 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S4) + // "(" -> Shift(S3) // "Num" -> Shift(S2) // - // Term -> S3 - // Factor -> S16 + // Term -> S16 pub fn __state7>( mut lookahead: Option, tokens: &mut TOKENS, @@ -527,7 +495,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state4(lookahead, tokens, sym2)); + result = try!(__state3(lookahead, tokens, sym2)); } Some(Tok::Num(__tok0)) => { let mut sym2 = &mut Some((__tok0)); @@ -542,10 +510,6 @@ mod __parse__Expr { let (lookahead, nt) = result; match nt { __Nonterminal::Term(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state3(lookahead, tokens, sym2)); - } - __Nonterminal::Factor(nt) => { let sym2 = &mut Some(nt); result = try!(__state16(lookahead, tokens, sym0, sym1, sym2)); } @@ -558,215 +522,6 @@ mod __parse__Expr { } // State 8 - // 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(S18) - // "+" -> Shift(S19) - // "-" -> Shift(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 @ Tok::RParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state18(lookahead, tokens, sym0, sym1, sym2)); - } - Some(__tok @ Tok::Plus(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state19(lookahead, tokens, sym1, sym2)); - } - Some(__tok @ Tok::Minus(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state17(lookahead, tokens, sym1, sym2)); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - - // State 9 - // Factor = Term (*) [")"] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] - // - // ")" -> Reduce(Factor = Term => ActionFn(6);) - // "+" -> Reduce(Factor = Term => ActionFn(6);) - // "*" -> Reduce(Factor = Term => ActionFn(6);) - // "/" -> Reduce(Factor = Term => ActionFn(6);) - // "-" -> Reduce(Factor = Term => ActionFn(6);) - // - pub fn __state9>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 10 - // Expr = Factor (*) [")"] - // Expr = Factor (*) ["+"] - // Expr = Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // "/" -> Shift(S20) - // "+" -> Reduce(Expr = Factor => ActionFn(3);) - // "-" -> Reduce(Expr = Factor => ActionFn(3);) - // ")" -> Reduce(Expr = Factor => ActionFn(3);) - // "*" -> Shift(S21) - // - pub fn __state10>( - 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!(__state21(lookahead, tokens, sym0, sym1)); - } - 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))); - } - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action3(sym0); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - - // State 11 - // Term = "Num" (*) [")"] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] - // - // "*" -> Reduce(Term = "Num" => ActionFn(7);) - // "-" -> Reduce(Term = "Num" => ActionFn(7);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // ")" -> Reduce(Term = "Num" => ActionFn(7);) - // "+" -> Reduce(Term = "Num" => ActionFn(7);) - // - pub fn __state11>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__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::RParen(..)) => { - 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))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 12 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -807,28 +562,28 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S12) - // "Num" -> Shift(S11) + // "Num" -> Shift(S10) + // "(" -> Shift(S8) // - // Term -> S9 - // Factor -> S10 - // Expr -> S22 - pub fn __state12>( + // Expr -> S17 + // Term -> S12 + // Factor -> S11 + pub fn __state8>( mut lookahead: Option, 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!(__state12(lookahead, tokens, sym1)); - } Some(Tok::Num(__tok0)) => { let mut sym1 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state11(lookahead, tokens, sym1)); + result = try!(__state10(lookahead, tokens, sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state8(lookahead, tokens, sym1)); } _ => { return Err(lookahead); @@ -837,17 +592,17 @@ mod __parse__Expr { while sym0.is_some() { let (lookahead, nt) = result; match nt { + __Nonterminal::Expr(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state17(lookahead, tokens, sym0, sym1)); + } __Nonterminal::Term(nt) => { let sym1 = &mut Some(nt); - result = try!(__state9(lookahead, tokens, sym1)); + result = try!(__state12(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!(__state22(lookahead, tokens, sym0, sym1)); + result = try!(__state11(lookahead, tokens, sym1)); } _ => { return Ok((lookahead, nt)); @@ -857,12 +612,234 @@ mod __parse__Expr { 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(S18) + // "+" -> Shift(S19) + // ")" -> Shift(S20) + // + 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 @ Tok::Minus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state18(lookahead, tokens, sym1, sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state19(lookahead, tokens, sym1, sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state20(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 10 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // ")" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // + pub fn __state10>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__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); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + Some(Tok::RParen(..)) => { + 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 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);) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S22) + // "/" -> Shift(S21) + // + 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::Times(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state22(lookahead, tokens, sym0, sym1)); + } + Some(__tok @ Tok::Div(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state21(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::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 12 + // Factor = Term (*) [")"] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // ")" -> Reduce(Factor = Term => ActionFn(6);) + // "/" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // "+" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) + // + pub fn __state12>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + _ => { + return Err(lookahead); + } + } + } + // State 13 - // Factor = Factor "/" (*) Term [EOF] - // Factor = Factor "/" (*) Term ["*"] - // Factor = Factor "/" (*) Term ["+"] - // Factor = Factor "/" (*) Term ["-"] - // Factor = Factor "/" (*) Term ["/"] + // Expr = Expr "+" (*) Factor [EOF] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] // Term = (*) "(" Expr ")" [EOF] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -875,9 +852,10 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // // "Num" -> Shift(S2) - // "(" -> Shift(S4) + // "(" -> Shift(S3) // - // Term -> S23 + // Term -> S5 + // Factor -> S23 pub fn __state13>( mut lookahead: Option, tokens: &mut TOKENS, @@ -894,7 +872,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state4(lookahead, tokens, sym2)); + result = try!(__state3(lookahead, tokens, sym2)); } _ => { return Err(lookahead); @@ -904,6 +882,10 @@ mod __parse__Expr { 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!(__state23(lookahead, tokens, sym0, sym1, sym2)); } @@ -916,11 +898,24 @@ mod __parse__Expr { } // State 14 - // Factor = Factor "*" (*) Term [EOF] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] + // Expr = Expr "-" (*) Factor [EOF] + // Expr = Expr "-" (*) Factor ["+"] + // Expr = Expr "-" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] // Term = (*) "(" Expr ")" [EOF] // Term = (*) "(" Expr ")" ["*"] // Term = (*) "(" Expr ")" ["+"] @@ -932,10 +927,11 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S4) + // "(" -> Shift(S3) // "Num" -> Shift(S2) // - // Term -> S24 + // Term -> S5 + // Factor -> S24 pub fn __state14>( mut lookahead: Option, tokens: &mut TOKENS, @@ -947,7 +943,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state4(lookahead, tokens, sym2)); + result = try!(__state3(lookahead, tokens, sym2)); } Some(Tok::Num(__tok0)) => { let mut sym2 = &mut Some((__tok0)); @@ -962,6 +958,10 @@ mod __parse__Expr { 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!(__state24(lookahead, tokens, sym0, sym1, sym2)); } @@ -974,25 +974,17 @@ 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 ["/"] + // Factor = Factor "/" Term (*) [EOF] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] // - // "*" -> Shift(S14) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "/" -> Shift(S13) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // EOF -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) // pub fn __state15>( mut lookahead: Option, @@ -1003,64 +995,59 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state14(lookahead, tokens, sym2, sym3)); - } - Some(__tok @ Tok::Div(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state13(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::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))); + 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::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(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::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); } _ => { return Err(lookahead); } } - return Ok(result); } // State 16 - // Expr = Expr "-" Factor (*) [EOF] - // Expr = Expr "-" Factor (*) ["+"] - // Expr = Expr "-" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] + // Factor = Factor "*" Term (*) [EOF] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] // - // "/" -> Shift(S13) - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "*" -> Shift(S14) - // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // EOF -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // pub fn __state16>( mut lookahead: Option, @@ -1071,36 +1058,86 @@ mod __parse__Expr { ) -> 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!(__state13(lookahead, tokens, sym2, sym3)); - } - Some(__tok @ Tok::Times(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state14(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))); - } 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))); + 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::__action1(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(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))); + } + 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 17 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [")"] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // "-" -> Shift(S18) + // ")" -> Shift(S25) + // "+" -> Shift(S19) + // + pub fn __state17>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state18(lookahead, tokens, sym1, sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state25(lookahead, tokens, sym0, sym1, sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state19(lookahead, tokens, sym1, sym2)); } _ => { return Err(lookahead); @@ -1109,7 +1146,7 @@ mod __parse__Expr { return Ok(result); } - // State 17 + // State 18 // Expr = Expr "-" (*) Factor [")"] // Expr = Expr "-" (*) Factor ["+"] // Expr = Expr "-" (*) Factor ["-"] @@ -1139,12 +1176,12 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S12) - // "Num" -> Shift(S11) + // "Num" -> Shift(S10) + // "(" -> Shift(S8) // - // Factor -> S25 - // Term -> S9 - pub fn __state17>( + // Factor -> S26 + // Term -> S12 + pub fn __state18>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -1152,15 +1189,15 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state12(lookahead, tokens, sym2)); - } Some(Tok::Num(__tok0)) => { let mut sym2 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state11(lookahead, tokens, sym2)); + result = try!(__state10(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); @@ -1171,11 +1208,11 @@ mod __parse__Expr { match nt { __Nonterminal::Factor(nt) => { let sym2 = &mut Some(nt); - result = try!(__state25(lookahead, tokens, sym0, sym1, sym2)); + result = try!(__state26(lookahead, tokens, sym0, sym1, sym2)); } __Nonterminal::Term(nt) => { let sym2 = &mut Some(nt); - result = try!(__state9(lookahead, tokens, sym2)); + result = try!(__state12(lookahead, tokens, sym2)); } _ => { return Ok((lookahead, nt)); @@ -1185,69 +1222,6 @@ mod __parse__Expr { return Ok(result); } - // State 18 - // Term = "(" Expr ")" (*) [EOF] - // Term = "(" Expr ")" (*) ["*"] - // Term = "(" Expr ")" (*) ["+"] - // Term = "(" Expr ")" (*) ["-"] - // Term = "(" Expr ")" (*) ["/"] - // - // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // - pub fn __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::__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))); - } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action8(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - Some(Tok::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 19 // Expr = Expr "+" (*) Factor [")"] // Expr = Expr "+" (*) Factor ["+"] @@ -1278,11 +1252,11 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S11) - // "(" -> Shift(S12) + // "(" -> Shift(S8) + // "Num" -> Shift(S10) // - // Term -> S9 - // Factor -> S26 + // Term -> S12 + // Factor -> S27 pub fn __state19>( mut lookahead: Option, tokens: &mut TOKENS, @@ -1291,15 +1265,15 @@ mod __parse__Expr { ) -> 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!(__state11(lookahead, tokens, sym2)); - } Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state12(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!(__state10(lookahead, tokens, sym2)); } _ => { return Err(lookahead); @@ -1310,11 +1284,11 @@ mod __parse__Expr { match nt { __Nonterminal::Term(nt) => { let sym2 = &mut Some(nt); - result = try!(__state9(lookahead, tokens, sym2)); + result = try!(__state12(lookahead, tokens, sym2)); } __Nonterminal::Factor(nt) => { let sym2 = &mut Some(nt); - result = try!(__state26(lookahead, tokens, sym0, sym1, sym2)); + result = try!(__state27(lookahead, tokens, sym0, sym1, sym2)); } _ => { return Ok((lookahead, nt)); @@ -1325,6 +1299,69 @@ mod __parse__Expr { } // State 20 + // Term = "(" Expr ")" (*) [EOF] + // Term = "(" Expr ")" (*) ["*"] + // Term = "(" Expr ")" (*) ["+"] + // Term = "(" Expr ")" (*) ["-"] + // Term = "(" Expr ")" (*) ["/"] + // + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // + pub fn __state20>( + 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::__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::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::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 21 // Factor = Factor "/" (*) Term [")"] // Factor = Factor "/" (*) Term ["*"] // Factor = Factor "/" (*) Term ["+"] @@ -1341,66 +1378,8 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S11) - // "(" -> Shift(S12) - // - // Term -> S27 - 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::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state11(lookahead, tokens, sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); - 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!(__state27(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); - } - - // State 21 - // Factor = Factor "*" (*) Term [")"] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "(" -> Shift(S12) - // "Num" -> Shift(S11) + // "(" -> Shift(S8) + // "Num" -> Shift(S10) // // Term -> S28 pub fn __state21>( @@ -1414,12 +1393,12 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state12(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!(__state11(lookahead, tokens, sym2)); + result = try!(__state10(lookahead, tokens, sym2)); } _ => { return Err(lookahead); @@ -1441,64 +1420,83 @@ mod __parse__Expr { } // State 22 - // Expr = Expr (*) "+" Factor [")"] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [")"] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // Term = "(" Expr (*) ")" [")"] - // Term = "(" Expr (*) ")" ["*"] - // Term = "(" Expr (*) ")" ["+"] - // Term = "(" Expr (*) ")" ["-"] - // Term = "(" Expr (*) ")" ["/"] + // 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(S19) - // "-" -> Shift(S17) - // ")" -> Shift(S29) + // "(" -> Shift(S8) + // "Num" -> Shift(S10) // + // Term -> S29 pub fn __state22>( mut lookahead: Option, tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, + 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!(__state19(lookahead, tokens, sym1, sym2)); + result = try!(__state8(lookahead, tokens, sym2)); } - Some(__tok @ Tok::Minus(..)) => { - let mut sym2 = &mut Some(__tok); + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state17(lookahead, tokens, sym1, sym2)); - } - Some(__tok @ Tok::RParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state29(lookahead, tokens, sym0, sym1, sym2)); + result = try!(__state10(lookahead, tokens, sym2)); } _ => { return Err(lookahead); } } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::Term(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state29(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } return Ok(result); } // State 23 - // Factor = Factor "/" Term (*) [EOF] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] + // Expr = Expr "+" Factor (*) [EOF] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // EOF -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Shift(S6) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S7) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // pub fn __state23>( mut lookahead: Option, @@ -1509,59 +1507,64 @@ mod __parse__Expr { ) -> 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 @ Tok::Div(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state6(lookahead, tokens, sym2, sym3)); } - None => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::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 @ Tok::Times(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(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::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); + 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 24 - // Factor = Factor "*" Term (*) [EOF] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] + // Expr = Expr "-" Factor (*) [EOF] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // EOF -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Shift(S7) + // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S6) // pub fn __state24>( mut lookahead: Option, @@ -1572,310 +1575,45 @@ mod __parse__Expr { ) -> 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::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); + Some(__tok @ Tok::Times(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(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::__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 @ Tok::Div(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state6(lookahead, tokens, sym2, sym3)); } 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))); + 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::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); + let nt = super::__action1(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action1(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); } _ => { return Err(lookahead); } } + return Ok(result); } // State 25 - // Expr = Expr "-" Factor (*) [")"] - // Expr = Expr "-" Factor (*) ["+"] - // Expr = Expr "-" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S20) - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "*" -> Shift(S21) - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // - pub fn __state25>( - 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!(__state20(lookahead, tokens, sym2, sym3)); - } - Some(__tok @ Tok::Times(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state21(lookahead, tokens, sym2, sym3)); - } - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action1(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action1(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - 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))); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - - // State 26 - // Expr = Expr "+" Factor (*) [")"] - // Expr = Expr "+" Factor (*) ["+"] - // Expr = Expr "+" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [")"] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [")"] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "/" -> Shift(S20) - // "*" -> Shift(S21) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // - 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 @ 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!(__state21(lookahead, tokens, sym2, sym3)); - } - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__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))); - } - 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); - } - } - return Ok(result); - } - - // State 27 - // Factor = Factor "/" Term (*) [")"] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] - // - // ")" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // - pub fn __state27>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__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::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))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 28 - // Factor = Factor "*" Term (*) [")"] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] - // - // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // - pub fn __state28>( - 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::__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::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))); - } - 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 29 // Term = "(" Expr ")" (*) [")"] // Term = "(" Expr ")" (*) ["*"] // Term = "(" Expr ")" (*) ["+"] @@ -1884,11 +1622,11 @@ mod __parse__Expr { // // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // - pub fn __state29>( + pub fn __state25>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -1911,13 +1649,6 @@ mod __parse__Expr { let nt = super::__action8(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Term(nt))); } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action8(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Term(nt))); - } Some(Tok::RParen(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); @@ -1932,6 +1663,275 @@ mod __parse__Expr { 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 26 + // Expr = Expr "-" Factor (*) [")"] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S21) + // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "*" -> Shift(S22) + // + 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 @ Tok::Div(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state21(lookahead, tokens, sym2, sym3)); + } + Some(__tok @ Tok::Times(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state22(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))); + } + Some(Tok::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action1(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 27 + // Expr = Expr "+" Factor (*) [")"] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [")"] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [")"] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] + // + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "*" -> Shift(S22) + // "/" -> Shift(S21) + // + pub fn __state27>( + 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!(__state22(lookahead, tokens, sym2, sym3)); + } + Some(__tok @ Tok::Div(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state21(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))); + } + Some(Tok::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 28 + // Factor = Factor "/" Term (*) [")"] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // ")" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // + pub fn __state28>( + 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::__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::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::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); + } + } + } + + // State 29 + // Factor = Factor "*" Term (*) [")"] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // + pub fn __state29>( + 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::__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::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))); + } + 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); } diff --git a/lalrpop-test/src/sub.lalrpop b/lalrpop-test/src/sub.lalrpop index 65011c7..8668d7a 100644 --- a/lalrpop-test/src/sub.lalrpop +++ b/lalrpop-test/src/sub.lalrpop @@ -1,25 +1,26 @@ -grammar { - use util::tok::Tok; +grammar; - extern token { - enum Tok { - "(" => Tok::LParen(..), - ")" => Tok::RParen(..), - "-" => Tok::Minus(..), - "Num" => Tok::Num(), - } +use util::tok::Tok; + +extern token { + enum Tok { + "(" => Tok::LParen(..), + ")" => Tok::RParen(..), + "-" => Tok::Minus(..), + "Num" => Tok::Num(), } - - pub S = E; - - E = { - "-" => l-r; - - T; - }; - - T = { - <"Num">; - "(" ")"; - }; } + +pub S = E; + +E = { + "-" => l-r; + + T; +}; + +T = { + <"Num">; + "(" ")"; +}; + diff --git a/lalrpop-test/src/sub.rs b/lalrpop-test/src/sub.rs index 54bcd19..99ad843 100644 --- a/lalrpop-test/src/sub.rs +++ b/lalrpop-test/src/sub.rs @@ -19,10 +19,10 @@ mod __parse__S { use util::tok::Tok; pub enum __Nonterminal { + __S(i32), + E(i32), S(i32), T(i32), - E(i32), - __S(i32), } // State 0 @@ -37,27 +37,27 @@ mod __parse__S { // T = (*) "Num" ["-"] // __S = (*) S [EOF] // - // "Num" -> Shift(S3) - // "(" -> Shift(S2) + // "(" -> Shift(S5) + // "Num" -> Shift(S4) // + // E -> S2 + // S -> S3 // T -> S1 - // S -> S4 - // E -> S5 pub fn __state0>( mut lookahead: Option, 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!(__state3(lookahead, tokens, sym0)); - } Some(__tok @ Tok::LParen(..)) => { let mut sym0 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state2(lookahead, tokens, sym0)); + result = try!(__state5(lookahead, tokens, sym0)); + } + Some(Tok::Num(__tok0)) => { + let mut sym0 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state4(lookahead, tokens, sym0)); } _ => { return Err(lookahead); @@ -66,17 +66,17 @@ mod __parse__S { loop { let (lookahead, nt) = result; match nt { - __Nonterminal::T(nt) => { + __Nonterminal::E(nt) => { let sym0 = &mut Some(nt); - result = try!(__state1(lookahead, tokens, sym0)); + result = try!(__state2(lookahead, tokens, sym0)); } __Nonterminal::S(nt) => { let sym0 = &mut Some(nt); - result = try!(__state4(lookahead, tokens, sym0)); + result = try!(__state3(lookahead, tokens, sym0)); } - __Nonterminal::E(nt) => { + __Nonterminal::T(nt) => { let sym0 = &mut Some(nt); - result = try!(__state5(lookahead, tokens, sym0)); + result = try!(__state1(lookahead, tokens, sym0)); } _ => { return Ok((lookahead, nt)); @@ -89,8 +89,8 @@ mod __parse__S { // E = T (*) [EOF] // E = T (*) ["-"] // - // EOF -> Reduce(E = T => ActionFn(3);) // "-" -> Reduce(E = T => ActionFn(3);) + // EOF -> Reduce(E = T => ActionFn(3);) // pub fn __state1>( mut lookahead: Option, @@ -99,12 +99,12 @@ mod __parse__S { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - None => { + Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); let nt = super::__action3(sym0); return Ok((lookahead, __Nonterminal::E(nt))); } - Some(Tok::Minus(..)) => { + None => { let sym0 = sym0.take().unwrap(); let nt = super::__action3(sym0); return Ok((lookahead, __Nonterminal::E(nt))); @@ -116,98 +116,43 @@ mod __parse__S { } // State 2 - // E = (*) E "-" T [")"] - // E = (*) E "-" T ["-"] - // E = (*) T [")"] - // E = (*) T ["-"] - // T = (*) "(" E ")" [")"] - // T = (*) "(" E ")" ["-"] - // T = "(" (*) E ")" [EOF] - // T = "(" (*) E ")" ["-"] - // T = (*) "Num" [")"] - // T = (*) "Num" ["-"] + // E = E (*) "-" T [EOF] + // E = E (*) "-" T ["-"] + // S = E (*) [EOF] // - // "(" -> Shift(S7) - // "Num" -> Shift(S8) + // "-" -> Shift(S6) + // EOF -> Reduce(S = E => ActionFn(1);) // - // E -> S6 - // T -> S9 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::LParen(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state7(lookahead, tokens, sym1)); - } - Some(Tok::Num(__tok0)) => { - let mut sym1 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state8(lookahead, tokens, sym1)); - } - _ => { - return Err(lookahead); - } - } - while sym0.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::E(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state6(lookahead, tokens, sym0, sym1)); - } - __Nonterminal::T(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state9(lookahead, tokens, sym1)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); - } - - // State 3 - // T = "Num" (*) [EOF] - // T = "Num" (*) ["-"] - // - // "-" -> Reduce(T = "Num" => ActionFn(4);) - // EOF -> Reduce(T = "Num" => ActionFn(4);) - // - 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::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); + Some(__tok @ Tok::Minus(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state6(lookahead, tokens, sym0, sym1)); } None => { let sym0 = sym0.take().unwrap(); - let nt = super::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); + let nt = super::__action1(sym0); + return Ok((lookahead, __Nonterminal::S(nt))); } _ => { return Err(lookahead); } } + return Ok(result); } - // State 4 + // State 3 // __S = S (*) [EOF] // // EOF -> Reduce(__S = S => ActionFn(0);) // - pub fn __state4>( + pub fn __state3>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -225,69 +170,139 @@ mod __parse__S { } } - // State 5 - // E = E (*) "-" T [EOF] - // E = E (*) "-" T ["-"] - // S = E (*) [EOF] + // State 4 + // T = "Num" (*) [EOF] + // T = "Num" (*) ["-"] // - // EOF -> Reduce(S = E => ActionFn(1);) - // "-" -> Shift(S10) + // EOF -> Reduce(T = "Num" => ActionFn(4);) + // "-" -> Reduce(T = "Num" => ActionFn(4);) // - pub fn __state5>( + pub fn __state4>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym0, sym1)); - } None => { let sym0 = sym0.take().unwrap(); - let nt = super::__action1(sym0); - return Ok((lookahead, __Nonterminal::S(nt))); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); } _ => { return Err(lookahead); } } + } + + // State 5 + // E = (*) E "-" T [")"] + // E = (*) E "-" T ["-"] + // E = (*) T [")"] + // E = (*) T ["-"] + // T = (*) "(" E ")" [")"] + // T = (*) "(" E ")" ["-"] + // T = "(" (*) E ")" [EOF] + // T = "(" (*) E ")" ["-"] + // T = (*) "Num" [")"] + // T = (*) "Num" ["-"] + // + // "Num" -> Shift(S10) + // "(" -> Shift(S7) + // + // E -> S8 + // T -> S9 + pub fn __state5>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Num(__tok0)) => { + let mut sym1 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state10(lookahead, tokens, sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(lookahead, tokens, sym1)); + } + _ => { + return Err(lookahead); + } + } + while sym0.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::E(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state8(lookahead, tokens, sym0, sym1)); + } + __Nonterminal::T(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state9(lookahead, tokens, sym1)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } return Ok(result); } // State 6 - // E = E (*) "-" T [")"] - // E = E (*) "-" T ["-"] - // T = "(" E (*) ")" [EOF] - // T = "(" E (*) ")" ["-"] + // E = E "-" (*) T [EOF] + // E = E "-" (*) T ["-"] + // T = (*) "(" E ")" [EOF] + // T = (*) "(" E ")" ["-"] + // T = (*) "Num" [EOF] + // T = (*) "Num" ["-"] // - // "-" -> Shift(S11) - // ")" -> Shift(S12) + // "(" -> Shift(S5) + // "Num" -> Shift(S4) // + // T -> S11 pub fn __state6>( mut lookahead: Option, tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, + sym0: &mut Option, + sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::Minus(..)) => { + Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state11(lookahead, tokens, sym1, sym2)); + result = try!(__state5(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!(__state12(lookahead, tokens, sym0, sym1, sym2)); + result = try!(__state4(lookahead, tokens, sym2)); } _ => { return Err(lookahead); } } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::T(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state11(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } return Ok(result); } @@ -303,11 +318,11 @@ mod __parse__S { // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "Num" -> Shift(S8) // "(" -> Shift(S7) + // "Num" -> Shift(S10) // - // E -> S13 // T -> S9 + // E -> S12 pub fn __state7>( mut lookahead: Option, tokens: &mut TOKENS, @@ -315,16 +330,16 @@ mod __parse__S { ) -> 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!(__state7(lookahead, tokens, sym1)); } + Some(Tok::Num(__tok0)) => { + let mut sym1 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state10(lookahead, tokens, sym1)); + } _ => { return Err(lookahead); } @@ -332,14 +347,14 @@ mod __parse__S { while sym0.is_some() { let (lookahead, nt) = result; match nt { - __Nonterminal::E(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state13(lookahead, tokens, sym0, sym1)); - } __Nonterminal::T(nt) => { let sym1 = &mut Some(nt); result = try!(__state9(lookahead, tokens, sym1)); } + __Nonterminal::E(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state12(lookahead, tokens, sym0, sym1)); + } _ => { return Ok((lookahead, nt)); } @@ -349,33 +364,37 @@ mod __parse__S { } // State 8 - // T = "Num" (*) [")"] - // T = "Num" (*) ["-"] + // E = E (*) "-" T [")"] + // E = E (*) "-" T ["-"] + // T = "(" E (*) ")" [EOF] + // T = "(" E (*) ")" ["-"] // - // ")" -> Reduce(T = "Num" => ActionFn(4);) - // "-" -> Reduce(T = "Num" => ActionFn(4);) + // "-" -> Shift(S13) + // ")" -> Shift(S14) // pub fn __state8>( mut lookahead: Option, tokens: &mut TOKENS, - sym0: &mut Option, + sym0: &mut Option, + sym1: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); + Some(__tok @ Tok::Minus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state13(lookahead, tokens, sym1, sym2)); } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); + Some(__tok @ Tok::RParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state14(lookahead, tokens, sym0, sym1, sym2)); } _ => { return Err(lookahead); } } + return Ok(result); } // State 9 @@ -409,116 +428,48 @@ mod __parse__S { } // State 10 - // E = E "-" (*) T [EOF] - // E = E "-" (*) T ["-"] - // T = (*) "(" E ")" [EOF] - // T = (*) "(" E ")" ["-"] - // T = (*) "Num" [EOF] - // T = (*) "Num" ["-"] + // T = "Num" (*) [")"] + // T = "Num" (*) ["-"] // - // "(" -> Shift(S2) - // "Num" -> Shift(S3) + // ")" -> Reduce(T = "Num" => ActionFn(4);) + // "-" -> Reduce(T = "Num" => ActionFn(4);) // - // T -> S14 pub fn __state10>( 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!(__state2(lookahead, tokens, sym2)); + Some(Tok::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); } - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state3(lookahead, tokens, sym2)); + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); } _ => { return Err(lookahead); } } - while sym1.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::T(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state14(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); } // State 11 - // E = E "-" (*) T [")"] - // E = E "-" (*) T ["-"] - // T = (*) "(" E ")" [")"] - // T = (*) "(" E ")" ["-"] - // T = (*) "Num" [")"] - // T = (*) "Num" ["-"] + // E = E "-" T (*) [EOF] + // E = E "-" T (*) ["-"] // - // "(" -> Shift(S7) - // "Num" -> Shift(S8) + // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // EOF -> Reduce(E = E, "-", T => ActionFn(2);) // - // T -> S15 pub fn __state11>( 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!(__state7(lookahead, tokens, sym2)); - } - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state8(lookahead, tokens, sym2)); - } - _ => { - return Err(lookahead); - } - } - while sym1.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::T(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state15(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); - } - - // State 12 - // T = "(" E ")" (*) [EOF] - // T = "(" E ")" (*) ["-"] - // - // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) - // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) - // - pub fn __state12>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - sym2: &mut Option, + sym2: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { @@ -526,15 +477,15 @@ mod __parse__S { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::T(nt))); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::E(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::T(nt))); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::E(nt))); } _ => { return Err(lookahead); @@ -542,16 +493,16 @@ mod __parse__S { } } - // State 13 + // State 12 // E = E (*) "-" T [")"] // E = E (*) "-" T ["-"] // T = "(" E (*) ")" [")"] // T = "(" E (*) ")" ["-"] // - // "-" -> Shift(S11) - // ")" -> Shift(S16) + // "-" -> Shift(S13) + // ")" -> Shift(S15) // - pub fn __state13>( + pub fn __state12>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -562,12 +513,12 @@ mod __parse__S { Some(__tok @ Tok::Minus(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state11(lookahead, tokens, sym1, sym2)); + result = try!(__state13(lookahead, tokens, sym1, sym2)); } Some(__tok @ Tok::RParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state16(lookahead, tokens, sym0, sym1, sym2)); + result = try!(__state15(lookahead, tokens, sym0, sym1, sym2)); } _ => { return Err(lookahead); @@ -576,19 +527,68 @@ mod __parse__S { return Ok(result); } - // State 14 - // E = E "-" T (*) [EOF] - // E = E "-" T (*) ["-"] + // State 13 + // E = E "-" (*) T [")"] + // E = E "-" (*) T ["-"] + // T = (*) "(" E ")" [")"] + // T = (*) "(" E ")" ["-"] + // T = (*) "Num" [")"] + // T = (*) "Num" ["-"] // - // EOF -> Reduce(E = E, "-", T => ActionFn(2);) - // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // "Num" -> Shift(S10) + // "(" -> Shift(S7) // - pub fn __state14>( + // T -> S16 + pub fn __state13>( 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::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state10(lookahead, tokens, sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(lookahead, tokens, sym2)); + } + _ => { + return Err(lookahead); + } + } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::T(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state16(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } + return Ok(result); + } + + // State 14 + // T = "(" E ")" (*) [EOF] + // T = "(" E ")" (*) ["-"] + // + // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) + // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // + pub fn __state14>( + 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 { @@ -596,15 +596,15 @@ mod __parse__S { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); - let nt = super::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::E(nt))); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::T(nt))); } Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); - let nt = super::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::E(nt))); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::T(nt))); } _ => { return Err(lookahead); @@ -613,49 +613,13 @@ mod __parse__S { } // State 15 - // E = E "-" T (*) [")"] - // E = E "-" T (*) ["-"] - // - // "-" -> Reduce(E = E, "-", T => ActionFn(2);) - // ")" -> Reduce(E = E, "-", T => ActionFn(2);) - // - pub fn __state15>( - 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::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::E(nt))); - } - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::E(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 16 // T = "(" E ")" (*) [")"] // T = "(" E ")" (*) ["-"] // // ")" -> Reduce(T = "(", E, ")" => ActionFn(5);) // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) // - pub fn __state16>( + pub fn __state15>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -683,6 +647,42 @@ mod __parse__S { } } } + + // State 16 + // E = E "-" T (*) [")"] + // E = E "-" T (*) ["-"] + // + // ")" -> Reduce(E = E, "-", T => ActionFn(2);) + // "-" -> Reduce(E = E, "-", T => ActionFn(2);) + // + 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::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::E(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::E(nt))); + } + _ => { + return Err(lookahead); + } + } + } } fn __action0( __0: i32, diff --git a/lalrpop/src/parser/mod.rs b/lalrpop/src/parser/mod.rs index 99bfb2d..eb6a4a1 100644 --- a/lalrpop/src/parser/mod.rs +++ b/lalrpop/src/parser/mod.rs @@ -23,7 +23,7 @@ rusty_peg! { - "{" "}") => { + ";" ) => { Grammar { span: Span(lo, hi), type_parameters: tps.unwrap_or(vec![]), parameters: parameters.unwrap_or(vec![]), diff --git a/lalrpop/src/parser/test.rs b/lalrpop/src/parser/test.rs index 825c344..c7ef1ba 100644 --- a/lalrpop/src/parser/test.rs +++ b/lalrpop/src/parser/test.rs @@ -21,29 +21,28 @@ fn type_ref_special_case_for_id() { #[test] fn empty_grammar() { - super::parse_grammar(r#"grammar { }"#).unwrap(); + super::parse_grammar(r#"grammar;"#).unwrap(); } #[test] fn grammar_param1() { - super::parse_grammar(r#"grammar(x: T) { }"#).unwrap(); + super::parse_grammar(r#"grammar(x: T);"#).unwrap(); } #[test] fn grammar_param2() { super::parse_grammar( - r#"grammar<'a,T>(x: T, y: Vec) where T: Copy, for<'a> &'a T: Baz { }"# + r#"grammar<'a,T>(x: T, y: Vec) where T: Copy, for<'a> &'a T: Baz;"# ).unwrap(); } #[test] fn use_decls() { - super::parse_grammar("grammar { + super::parse_grammar("grammar; use std::io; use std::io::{self, a, b}; use std::baz::*; - use std::this as that; -}").unwrap(); + use std::this as that;").unwrap(); } #[test] @@ -58,50 +57,50 @@ fn symbol() { #[test] fn nonterminal0() { - super::parse_grammar(r#"grammar { Expr = Alt; }"#).unwrap(); + super::parse_grammar(r#"grammar; Expr = Alt;"#).unwrap(); } #[test] fn paren() { - super::parse_grammar(r#"grammar { Expr = (Alt); }"#).unwrap(); + super::parse_grammar(r#"grammar; Expr = (Alt);"#).unwrap(); } #[test] fn paren_with_plus() { - super::parse_grammar(r#"grammar { Expr = (Alt)+; }"#).unwrap(); + super::parse_grammar(r#"grammar; Expr = (Alt)+;"#).unwrap(); } #[test] fn paren_with_plus_and_anon() { - super::parse_grammar(r#"grammar { Expr = ()+; }"#).unwrap(); + super::parse_grammar(r#"grammar; Expr = ()+;"#).unwrap(); } #[test] fn named_choice() { - super::parse_grammar(r#"grammar { Expr = ; }"#).unwrap(); + super::parse_grammar(r#"grammar; Expr = ;"#).unwrap(); } #[test] fn named_choice_plus() { - super::parse_grammar(r#"grammar { Expr = ; }"#).unwrap(); + super::parse_grammar(r#"grammar; Expr = ;"#).unwrap(); } #[test] fn token_expr() { - super::parse_grammar(r#"grammar { extern token { enum Expr { "foo" => Bar } } }"#).unwrap(); + super::parse_grammar(r#"grammar; extern token { enum Expr { "foo" => Bar } }"#).unwrap(); } #[test] fn map1() { super::parse_grammar( - r#"grammar { Expr = => { { foo } }; }"#).unwrap(); + r#"grammar; Expr = => { { foo } };"#).unwrap(); } #[test] #[allow(non_snake_case)] fn mapN() { super::parse_grammar( - r#"grammar { Expr = { Bar => { Baz }; X => { Y }; }; }"#).unwrap(); + r#"grammar; Expr = { Bar => { Baz }; X => { Y }; };"#).unwrap(); } #[test]