mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-18 18:00:50 +00:00
fix error reporting in terms of spans etc (no automated tests for this, boo)
This commit is contained in:
parent
1b46191fdc
commit
8fc9b609a4
File diff suppressed because it is too large
Load Diff
@ -20,9 +20,9 @@ mod __parse__S {
|
||||
|
||||
pub enum __Nonterminal {
|
||||
E(i32),
|
||||
T(i32),
|
||||
S(i32),
|
||||
__S(i32),
|
||||
T(i32),
|
||||
}
|
||||
|
||||
// State 0
|
||||
@ -37,12 +37,12 @@ mod __parse__S {
|
||||
// T = (*) "Num" ["-"]
|
||||
// __S = (*) S [EOF]
|
||||
//
|
||||
// "Num" -> Shift(S1)
|
||||
// "(" -> Shift(S5)
|
||||
// "Num" -> Shift(S4)
|
||||
// "(" -> Shift(S2)
|
||||
//
|
||||
// T -> S3
|
||||
// S -> S2
|
||||
// E -> S4
|
||||
// T -> S1
|
||||
// S -> S5
|
||||
// E -> S3
|
||||
pub fn __state0<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
@ -52,12 +52,12 @@ mod __parse__S {
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let sym0 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state1(lookahead, tokens, sym0));
|
||||
result = try!(__state4(lookahead, tokens, sym0));
|
||||
}
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym0 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state5(lookahead, tokens, sym0));
|
||||
result = try!(__state2(lookahead, tokens, sym0));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
@ -68,15 +68,15 @@ mod __parse__S {
|
||||
match nt {
|
||||
__Nonterminal::T(nt) => {
|
||||
let sym0 = &mut Some(nt);
|
||||
result = try!(__state3(lookahead, tokens, sym0));
|
||||
result = try!(__state1(lookahead, tokens, sym0));
|
||||
}
|
||||
__Nonterminal::S(nt) => {
|
||||
let sym0 = &mut Some(nt);
|
||||
result = try!(__state2(lookahead, tokens, sym0));
|
||||
result = try!(__state5(lookahead, tokens, sym0));
|
||||
}
|
||||
__Nonterminal::E(nt) => {
|
||||
let sym0 = &mut Some(nt);
|
||||
result = try!(__state4(lookahead, tokens, sym0));
|
||||
result = try!(__state3(lookahead, tokens, sym0));
|
||||
}
|
||||
_ => {
|
||||
return Ok((lookahead, nt));
|
||||
@ -86,25 +86,144 @@ mod __parse__S {
|
||||
}
|
||||
|
||||
// State 1
|
||||
// T = "Num" (*) [EOF]
|
||||
// T = "Num" (*) ["-"]
|
||||
// E = T (*) [EOF]
|
||||
// E = T (*) ["-"]
|
||||
//
|
||||
// EOF -> Reduce(T = "Num" => ActionFn(4);)
|
||||
// "-" -> Reduce(T = "Num" => ActionFn(4);)
|
||||
// EOF -> Reduce(E = T => ActionFn(3);)
|
||||
// "-" -> Reduce(E = T => ActionFn(3);)
|
||||
//
|
||||
pub fn __state1<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
None => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
Some(Tok::Minus(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 2
|
||||
// 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(S7)
|
||||
// "(" -> Shift(S6)
|
||||
//
|
||||
// T -> S9
|
||||
// E -> S8
|
||||
pub fn __state2<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let sym1 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state7(lookahead, tokens, sym1));
|
||||
}
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym1 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state6(lookahead, tokens, sym1));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
while sym0.is_some() {
|
||||
let (lookahead, nt) = result;
|
||||
match nt {
|
||||
__Nonterminal::T(nt) => {
|
||||
let sym1 = &mut Some(nt);
|
||||
result = try!(__state9(lookahead, tokens, sym1));
|
||||
}
|
||||
__Nonterminal::E(nt) => {
|
||||
let sym1 = &mut Some(nt);
|
||||
result = try!(__state8(lookahead, tokens, sym0, sym1));
|
||||
}
|
||||
_ => {
|
||||
return Ok((lookahead, nt));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 3
|
||||
// E = E (*) "-" T [EOF]
|
||||
// E = E (*) "-" T ["-"]
|
||||
// S = E (*) [EOF]
|
||||
//
|
||||
// EOF -> Reduce(S = E => ActionFn(1);)
|
||||
// "-" -> Shift(S10)
|
||||
//
|
||||
pub fn __state3<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::Minus(..)) => {
|
||||
let 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)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 4
|
||||
// T = "Num" (*) [EOF]
|
||||
// T = "Num" (*) ["-"]
|
||||
//
|
||||
// "-" -> Reduce(T = "Num" => ActionFn(4);)
|
||||
// EOF -> Reduce(T = "Num" => ActionFn(4);)
|
||||
//
|
||||
pub fn __state4<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(Tok::Minus(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action4(sym0);
|
||||
return Ok((lookahead, __Nonterminal::T(nt)));
|
||||
}
|
||||
Some(Tok::Minus(..)) => {
|
||||
None => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action4(sym0);
|
||||
return Ok((lookahead, __Nonterminal::T(nt)));
|
||||
@ -115,12 +234,12 @@ mod __parse__S {
|
||||
}
|
||||
}
|
||||
|
||||
// State 2
|
||||
// State 5
|
||||
// __S = S (*) [EOF]
|
||||
//
|
||||
// EOF -> Reduce(__S = S => ActionFn(0);)
|
||||
//
|
||||
pub fn __state2<TOKENS: Iterator<Item=Tok>>(
|
||||
pub fn __state5<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
@ -138,235 +257,7 @@ mod __parse__S {
|
||||
}
|
||||
}
|
||||
|
||||
// State 3
|
||||
// E = T (*) [EOF]
|
||||
// E = T (*) ["-"]
|
||||
//
|
||||
// EOF -> Reduce(E = T => ActionFn(3);)
|
||||
// "-" -> Reduce(E = T => ActionFn(3);)
|
||||
//
|
||||
pub fn __state3<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
None => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
Some(Tok::Minus(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 4
|
||||
// E = E (*) "-" T [EOF]
|
||||
// E = E (*) "-" T ["-"]
|
||||
// S = E (*) [EOF]
|
||||
//
|
||||
// "-" -> Shift(S6)
|
||||
// EOF -> Reduce(S = E => ActionFn(1);)
|
||||
//
|
||||
pub fn __state4<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::Minus(..)) => {
|
||||
let sym1 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state6(lookahead, tokens, sym0, sym1));
|
||||
}
|
||||
None => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action1(sym0);
|
||||
return Ok((lookahead, __Nonterminal::S(nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// 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" ["-"]
|
||||
//
|
||||
// "(" -> Shift(S9)
|
||||
// "Num" -> Shift(S8)
|
||||
//
|
||||
// T -> S7
|
||||
// E -> S10
|
||||
pub fn __state5<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym1 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state9(lookahead, tokens, sym1));
|
||||
}
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let sym1 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state8(lookahead, tokens, sym1));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
while sym0.is_some() {
|
||||
let (lookahead, nt) = result;
|
||||
match nt {
|
||||
__Nonterminal::T(nt) => {
|
||||
let sym1 = &mut Some(nt);
|
||||
result = try!(__state7(lookahead, tokens, sym1));
|
||||
}
|
||||
__Nonterminal::E(nt) => {
|
||||
let sym1 = &mut Some(nt);
|
||||
result = try!(__state10(lookahead, tokens, sym0, sym1));
|
||||
}
|
||||
_ => {
|
||||
return Ok((lookahead, nt));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 6
|
||||
// E = E "-" (*) T [EOF]
|
||||
// E = E "-" (*) T ["-"]
|
||||
// T = (*) "(" E ")" [EOF]
|
||||
// T = (*) "(" E ")" ["-"]
|
||||
// T = (*) "Num" [EOF]
|
||||
// T = (*) "Num" ["-"]
|
||||
//
|
||||
// "Num" -> Shift(S1)
|
||||
// "(" -> Shift(S5)
|
||||
//
|
||||
// T -> S11
|
||||
pub fn __state6<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state1(lookahead, tokens, sym2));
|
||||
}
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state5(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);
|
||||
}
|
||||
|
||||
// State 7
|
||||
// E = T (*) [")"]
|
||||
// E = T (*) ["-"]
|
||||
//
|
||||
// ")" -> Reduce(E = T => ActionFn(3);)
|
||||
// "-" -> Reduce(E = T => ActionFn(3);)
|
||||
//
|
||||
pub fn __state7<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(Tok::RParen(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
Some(Tok::Minus(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 8
|
||||
// T = "Num" (*) [")"]
|
||||
// T = "Num" (*) ["-"]
|
||||
//
|
||||
// ")" -> Reduce(T = "Num" => ActionFn(4);)
|
||||
// "-" -> Reduce(T = "Num" => ActionFn(4);)
|
||||
//
|
||||
pub fn __state8<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(Tok::RParen(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action4(sym0);
|
||||
return Ok((lookahead, __Nonterminal::T(nt)));
|
||||
}
|
||||
Some(Tok::Minus(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action4(sym0);
|
||||
return Ok((lookahead, __Nonterminal::T(nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 9
|
||||
// E = (*) E "-" T [")"]
|
||||
// E = (*) E "-" T ["-"]
|
||||
// E = (*) T [")"]
|
||||
@ -378,12 +269,12 @@ mod __parse__S {
|
||||
// T = (*) "Num" [")"]
|
||||
// T = (*) "Num" ["-"]
|
||||
//
|
||||
// "Num" -> Shift(S8)
|
||||
// "(" -> Shift(S9)
|
||||
// "Num" -> Shift(S7)
|
||||
// "(" -> Shift(S6)
|
||||
//
|
||||
// E -> S12
|
||||
// T -> S7
|
||||
pub fn __state9<TOKENS: Iterator<Item=Tok>>(
|
||||
// E -> S11
|
||||
// T -> S9
|
||||
pub fn __state6<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
@ -393,12 +284,12 @@ mod __parse__S {
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let sym1 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state8(lookahead, tokens, sym1));
|
||||
result = try!(__state7(lookahead, tokens, sym1));
|
||||
}
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym1 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state9(lookahead, tokens, sym1));
|
||||
result = try!(__state6(lookahead, tokens, sym1));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
@ -409,11 +300,11 @@ mod __parse__S {
|
||||
match nt {
|
||||
__Nonterminal::E(nt) => {
|
||||
let sym1 = &mut Some(nt);
|
||||
result = try!(__state12(lookahead, tokens, sym0, sym1));
|
||||
result = try!(__state11(lookahead, tokens, sym0, sym1));
|
||||
}
|
||||
__Nonterminal::T(nt) => {
|
||||
let sym1 = &mut Some(nt);
|
||||
result = try!(__state7(lookahead, tokens, sym1));
|
||||
result = try!(__state9(lookahead, tokens, sym1));
|
||||
}
|
||||
_ => {
|
||||
return Ok((lookahead, nt));
|
||||
@ -423,16 +314,46 @@ mod __parse__S {
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 10
|
||||
// State 7
|
||||
// T = "Num" (*) [")"]
|
||||
// T = "Num" (*) ["-"]
|
||||
//
|
||||
// ")" -> Reduce(T = "Num" => ActionFn(4);)
|
||||
// "-" -> Reduce(T = "Num" => ActionFn(4);)
|
||||
//
|
||||
pub fn __state7<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(Tok::RParen(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action4(sym0);
|
||||
return Ok((lookahead, __Nonterminal::T(nt)));
|
||||
}
|
||||
Some(Tok::Minus(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action4(sym0);
|
||||
return Ok((lookahead, __Nonterminal::T(nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 8
|
||||
// E = E (*) "-" T [")"]
|
||||
// E = E (*) "-" T ["-"]
|
||||
// T = "(" E (*) ")" [EOF]
|
||||
// T = "(" E (*) ")" ["-"]
|
||||
//
|
||||
// "-" -> Shift(S13)
|
||||
// ")" -> Shift(S14)
|
||||
// ")" -> Shift(S12)
|
||||
//
|
||||
pub fn __state10<TOKENS: Iterator<Item=Tok>>(
|
||||
pub fn __state8<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
@ -448,7 +369,7 @@ mod __parse__S {
|
||||
Some(tok @ Tok::RParen(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state14(lookahead, tokens, sym0, sym1, sym2));
|
||||
result = try!(__state12(lookahead, tokens, sym0, sym1, sym2));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
@ -457,34 +378,28 @@ mod __parse__S {
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 11
|
||||
// E = E "-" T (*) [EOF]
|
||||
// E = E "-" T (*) ["-"]
|
||||
// State 9
|
||||
// E = T (*) [")"]
|
||||
// E = T (*) ["-"]
|
||||
//
|
||||
// EOF -> Reduce(E = E, "-", T => ActionFn(2);)
|
||||
// "-" -> Reduce(E = E, "-", T => ActionFn(2);)
|
||||
// "-" -> Reduce(E = T => ActionFn(3);)
|
||||
// ")" -> Reduce(E = T => ActionFn(3);)
|
||||
//
|
||||
pub fn __state11<TOKENS: Iterator<Item=Tok>>(
|
||||
pub fn __state9<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
sym1: &mut Option<Tok>,
|
||||
sym2: &mut Option<i32>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
None => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let sym1 = sym1.take().unwrap();
|
||||
let sym2 = sym2.take().unwrap();
|
||||
let nt = super::__action2(sym0, sym1, sym2);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
Some(Tok::Minus(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let sym1 = sym1.take().unwrap();
|
||||
let sym2 = sym2.take().unwrap();
|
||||
let nt = super::__action2(sym0, sym1, sym2);
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
Some(Tok::RParen(..)) => {
|
||||
let sym0 = sym0.take().unwrap();
|
||||
let nt = super::__action3(sym0);
|
||||
return Ok((lookahead, __Nonterminal::E(nt)));
|
||||
}
|
||||
_ => {
|
||||
@ -493,7 +408,56 @@ mod __parse__S {
|
||||
}
|
||||
}
|
||||
|
||||
// State 12
|
||||
// State 10
|
||||
// E = E "-" (*) T [EOF]
|
||||
// E = E "-" (*) T ["-"]
|
||||
// T = (*) "(" E ")" [EOF]
|
||||
// T = (*) "(" E ")" ["-"]
|
||||
// T = (*) "Num" [EOF]
|
||||
// T = (*) "Num" ["-"]
|
||||
//
|
||||
// "Num" -> Shift(S4)
|
||||
// "(" -> Shift(S2)
|
||||
//
|
||||
// T -> S14
|
||||
pub fn __state10<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state4(lookahead, tokens, sym2));
|
||||
}
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state2(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!(__state14(lookahead, tokens, sym0, sym1, sym2));
|
||||
}
|
||||
_ => {
|
||||
return Ok((lookahead, nt));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 11
|
||||
// E = E (*) "-" T [")"]
|
||||
// E = E (*) "-" T ["-"]
|
||||
// T = "(" E (*) ")" [")"]
|
||||
@ -502,7 +466,7 @@ mod __parse__S {
|
||||
// "-" -> Shift(S13)
|
||||
// ")" -> Shift(S15)
|
||||
//
|
||||
pub fn __state12<TOKENS: Iterator<Item=Tok>>(
|
||||
pub fn __state11<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
@ -527,63 +491,14 @@ mod __parse__S {
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 13
|
||||
// E = E "-" (*) T [")"]
|
||||
// E = E "-" (*) T ["-"]
|
||||
// T = (*) "(" E ")" [")"]
|
||||
// T = (*) "(" E ")" ["-"]
|
||||
// T = (*) "Num" [")"]
|
||||
// T = (*) "Num" ["-"]
|
||||
//
|
||||
// "(" -> Shift(S9)
|
||||
// "Num" -> Shift(S8)
|
||||
//
|
||||
// T -> S16
|
||||
pub fn __state13<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state9(lookahead, tokens, sym2));
|
||||
}
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state8(lookahead, tokens, sym2));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
while sym1.is_some() {
|
||||
let (lookahead, nt) = result;
|
||||
match nt {
|
||||
__Nonterminal::T(nt) => {
|
||||
let sym2 = &mut Some(nt);
|
||||
result = try!(__state16(lookahead, tokens, sym0, sym1, sym2));
|
||||
}
|
||||
_ => {
|
||||
return Ok((lookahead, nt));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// State 14
|
||||
// State 12
|
||||
// T = "(" E ")" (*) [EOF]
|
||||
// T = "(" E ")" (*) ["-"]
|
||||
//
|
||||
// "-" -> Reduce(T = "(", E, ")" => ActionFn(5);)
|
||||
// EOF -> Reduce(T = "(", E, ")" => ActionFn(5);)
|
||||
//
|
||||
pub fn __state14<TOKENS: Iterator<Item=Tok>>(
|
||||
pub fn __state12<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<Tok>,
|
||||
@ -612,6 +527,91 @@ mod __parse__S {
|
||||
}
|
||||
}
|
||||
|
||||
// State 13
|
||||
// E = E "-" (*) T [")"]
|
||||
// E = E "-" (*) T ["-"]
|
||||
// T = (*) "(" E ")" [")"]
|
||||
// T = (*) "(" E ")" ["-"]
|
||||
// T = (*) "Num" [")"]
|
||||
// T = (*) "Num" ["-"]
|
||||
//
|
||||
// "(" -> Shift(S6)
|
||||
// "Num" -> Shift(S7)
|
||||
//
|
||||
// T -> S16
|
||||
pub fn __state13<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __Nonterminal);
|
||||
match lookahead {
|
||||
Some(tok @ Tok::LParen(..)) => {
|
||||
let sym2 = &mut Some(tok);
|
||||
let lookahead = tokens.next();
|
||||
result = try!(__state6(lookahead, tokens, sym2));
|
||||
}
|
||||
Some(tok @ Tok::Num(..)) => {
|
||||
let 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
|
||||
// E = E "-" T (*) [EOF]
|
||||
// E = E "-" T (*) ["-"]
|
||||
//
|
||||
// "-" -> Reduce(E = E, "-", T => ActionFn(2);)
|
||||
// EOF -> Reduce(E = E, "-", T => ActionFn(2);)
|
||||
//
|
||||
pub fn __state14<TOKENS: Iterator<Item=Tok>>(
|
||||
mut lookahead: Option<Tok>,
|
||||
tokens: &mut TOKENS,
|
||||
sym0: &mut Option<i32>,
|
||||
sym1: &mut Option<Tok>,
|
||||
sym2: &mut Option<i32>,
|
||||
) -> Result<(Option<Tok>, __Nonterminal), Option<Tok>> {
|
||||
let mut result: (Option<Tok>, __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)));
|
||||
}
|
||||
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::E(nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(lookahead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 15
|
||||
// T = "(" E ")" (*) [")"]
|
||||
// T = "(" E ")" (*) ["-"]
|
||||
|
@ -1,4 +1,5 @@
|
||||
use grammar::parse_tree as pt;
|
||||
use std::fmt::{Display, Formatter, Error};
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use std::io::{self, Read, Write};
|
||||
@ -18,12 +19,16 @@ impl FileText {
|
||||
}
|
||||
|
||||
fn new(path: PathBuf, input_str: String) -> FileText {
|
||||
let newline_indices: Vec<usize> =
|
||||
input_str.as_bytes().iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, &b)| b == ('\n' as u8))
|
||||
.map(|(i, _)| i + 1) // store the first character in the line
|
||||
.collect();
|
||||
let newline_indices: Vec<usize> = {
|
||||
let input_indices =
|
||||
input_str.as_bytes().iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, &b)| b == ('\n' as u8))
|
||||
.map(|(i, _)| i + 1); // index of first char in the line
|
||||
Some(0).into_iter()
|
||||
.chain(input_indices)
|
||||
.collect()
|
||||
};
|
||||
|
||||
FileText { path: path, input_str: input_str, newlines: newline_indices }
|
||||
}
|
||||
@ -65,7 +70,7 @@ impl FileText {
|
||||
&self.input_str[start_offset..]
|
||||
} else {
|
||||
let end_offset = self.newlines[line_num + 1];
|
||||
&self.input_str[start_offset..end_offset]
|
||||
&self.input_str[start_offset..end_offset-1]
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,24 +87,38 @@ impl FileText {
|
||||
try!(writeln!(out, " {}", text));
|
||||
|
||||
if end_col - start_col <= 1 {
|
||||
try!(writeln!(out, " {0:1$}^", "", start_col));
|
||||
try!(writeln!(out, " {}^", Repeat(' ', start_col)));
|
||||
} else {
|
||||
let width = end_col - start_col;
|
||||
try!(writeln!(out, " {0:1$}|{0:-2$}|",
|
||||
"", start_col, width.saturating_sub(2)));
|
||||
try!(writeln!(out, " {}~{}~",
|
||||
Repeat(' ', start_col),
|
||||
Repeat('~', width.saturating_sub(2))));
|
||||
}
|
||||
} else {
|
||||
// span is across many lines, find the maximal width of any of those
|
||||
let line_strs: Vec<_> = (start_line..end_line+1).map(|i| self.line_text(i)).collect();
|
||||
let max_len = line_strs.iter().map(|l| l.len()).max().unwrap();
|
||||
try!(writeln!(out, " {0:1$}|{0:-2$}-+", "", start_col, max_len - start_col));
|
||||
try!(writeln!(out, " {}{}~+",
|
||||
Repeat(' ', start_col),
|
||||
Repeat('~', max_len - start_col)));
|
||||
for line in &line_strs[..line_strs.len()-1] {
|
||||
try!(writeln!(out, "| {0:<1$} |", line, max_len));
|
||||
}
|
||||
try!(writeln!(out, "| {}", line_strs[line_strs.len()-1]));
|
||||
try!(writeln!(out, "+-{0:-1$}", "", end_col));
|
||||
try!(writeln!(out, "+~{}", Repeat('~', end_col)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct Repeat(char, usize);
|
||||
|
||||
impl Display for Repeat {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||
for _ in 0..self.1 {
|
||||
try!(write!(fmt, "{}", self.0));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ grammar {
|
||||
fn expr_grammar1() {
|
||||
let grammar = normalized_grammar(r#"
|
||||
grammar {
|
||||
token Tok where { };
|
||||
token Tok where { "-" => "Sub" };
|
||||
|
||||
S: () =
|
||||
E => ();
|
||||
|
@ -25,6 +25,11 @@ macro_rules! return_err {
|
||||
}
|
||||
|
||||
pub fn normalize(grammar: pt::Grammar) -> NormResult<r::Grammar> {
|
||||
try!(validate::validate(&grammar));
|
||||
normalize_without_validating(grammar)
|
||||
}
|
||||
|
||||
pub fn normalize_without_validating(grammar: pt::Grammar) -> NormResult<r::Grammar> {
|
||||
let grammar = try!(macro_expand::expand_macros(grammar));
|
||||
let types = try!(tyinfer::infer_types(&grammar));
|
||||
lower::lower(grammar, types)
|
||||
|
@ -4,7 +4,7 @@ use super::norm_util::{self, AlternativeAction, Symbols};
|
||||
use std::collections::{HashMap};
|
||||
use grammar::parse_tree::{Alternative, Grammar, GrammarItem,
|
||||
NonterminalData, NonterminalString,
|
||||
Span, Symbol, SymbolKind, TypeRef};
|
||||
Span, SymbolKind, TypeRef};
|
||||
use grammar::repr::{Types, TypeRepr};
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -45,12 +45,13 @@ struct Validator<'grammar> {
|
||||
conversions: Set<TerminalString>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
enum Def {
|
||||
TopLevel(usize), // argument is the number of macro arguments
|
||||
MacroArg
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ScopeChain<'scope> {
|
||||
previous: Option<&'scope ScopeChain<'scope>>,
|
||||
nonterminals: Map<NonterminalString, Def>,
|
||||
@ -194,10 +195,10 @@ impl<'grammar> Validator<'grammar> {
|
||||
}
|
||||
}
|
||||
SymbolKind::Repeat(ref repeat) => {
|
||||
self.validate_symbol(scope, &repeat.symbol);
|
||||
try!(self.validate_symbol(scope, &repeat.symbol));
|
||||
}
|
||||
SymbolKind::Choose(ref sym) | SymbolKind::Name(_, ref sym) => {
|
||||
self.validate_symbol(scope, sym);
|
||||
try!(self.validate_symbol(scope, sym));
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +236,7 @@ impl<'grammar> Validator<'grammar> {
|
||||
nt: NonterminalString)
|
||||
-> NormResult<Def> {
|
||||
match scope.def(nt) {
|
||||
Some(arity) => Ok(arity),
|
||||
Some(def) => Ok(def),
|
||||
None => return_err!(span, "no definition found for nonterminal `{}`", nt)
|
||||
}
|
||||
}
|
||||
|
@ -45,3 +45,10 @@ fn repeated_macro_arg() {
|
||||
"multiple macro arguments declared with the name `Y`",
|
||||
r#"grammar { >>>X<Y,Y> <<<= "foo"; }"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_nonterminal_two() {
|
||||
check_err(
|
||||
"no definition found for nonterminal `Expr`",
|
||||
r#"grammar { Term = { n:"Num" => n.as_num(); "A" ~>>>Expr <<<"B"; }; }"#);
|
||||
}
|
||||
|
@ -46,5 +46,5 @@ pub fn compare<D:Debug,E:Debug>(actual: D, expected: E) {
|
||||
}
|
||||
|
||||
pub fn normalized_grammar(s: &str) -> r::Grammar {
|
||||
::normalize::normalize(::parser::parse_grammar(s).unwrap()).unwrap()
|
||||
::normalize::normalize_without_validating(::parser::parse_grammar(s).unwrap()).unwrap()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user