mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-16 17:00:53 +00:00
make it possible for tokenizer to generate errors (and thread the
logic through); use traits to be relatively seamless in what we accept
This commit is contained in:
parent
4c39cc7f2b
commit
b08e0cfe17
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -4,13 +4,16 @@ extern crate lalrpop_util as __lalrpop_util;
|
||||
use self::__lalrpop_util::ParseError as __ParseError;
|
||||
#[allow(non_snake_case)]
|
||||
pub fn parse_Items<
|
||||
__TOKENS: IntoIterator<Item=(usize, Tok, usize)>,
|
||||
__ERROR,
|
||||
__TOKEN: __ToTriple<Error=__ERROR>,
|
||||
__TOKENS: IntoIterator<Item=__TOKEN>,
|
||||
>(
|
||||
__tokens: __TOKENS,
|
||||
) -> Result<Vec<(usize, usize)>, __ParseError<usize,Tok>>
|
||||
) -> Result<Vec<(usize, usize)>, __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __tokens = __tokens.into_iter();
|
||||
let __lookahead = __tokens.next();
|
||||
let mut __tokens = __tokens.map(|t| __ToTriple::to_triple(t));
|
||||
let __lookahead = match __tokens.next() { Some(Ok(v)) => Some(v), None => None, Some(Err(e)) => return Err(__ParseError::User { error: e }) };
|
||||
match try!(__parse__Items::__state0(None, __lookahead, &mut __tokens)) {
|
||||
(_, Some(__lookahead), _) => {
|
||||
Err(__ParseError::ExtraToken { token: __lookahead })
|
||||
@ -28,13 +31,14 @@ mod __parse__Items {
|
||||
use util::tok::Tok;
|
||||
extern crate lalrpop_util as __lalrpop_util;
|
||||
use self::__lalrpop_util::ParseError as __ParseError;
|
||||
use super::__ToTriple;
|
||||
|
||||
pub enum __Nonterminal<> {
|
||||
Items(Vec<(usize, usize)>),
|
||||
_40_3c(usize),
|
||||
____Items(Vec<(usize, usize)>),
|
||||
_40_3e(usize),
|
||||
Spanned_3c_22_2b_22_3e((usize, usize)),
|
||||
_40_3e(usize),
|
||||
____Items(Vec<(usize, usize)>),
|
||||
_40_3c(usize),
|
||||
Items(Vec<(usize, usize)>),
|
||||
}
|
||||
|
||||
// State 0
|
||||
@ -52,27 +56,28 @@ mod __parse__Items {
|
||||
// Items = (*) Items "-" ["-"]
|
||||
// __Items = (*) Items [EOF]
|
||||
//
|
||||
// "+" -> Reduce(@< = => Lookahead;)
|
||||
// "-" -> Reduce(@< = => Lookahead;)
|
||||
// "+" -> Reduce(@< = => Lookahead;)
|
||||
// EOF -> Reduce(@< = => Lookahead;)
|
||||
//
|
||||
// Items -> S1
|
||||
// @< -> S2
|
||||
// Items -> S2
|
||||
// @< -> S1
|
||||
pub fn __state0<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __nt = __lookahead.as_ref().map(|o| ::std::clone::Clone::clone(&o.0)).or_else(|| ::std::clone::Clone::clone(&__lookbehind)).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3c(__nt));
|
||||
}
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __nt = __lookahead.as_ref().map(|o| ::std::clone::Clone::clone(&o.0)).or_else(|| ::std::clone::Clone::clone(&__lookbehind)).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3c(__nt));
|
||||
}
|
||||
@ -92,11 +97,11 @@ mod __parse__Items {
|
||||
match __nt {
|
||||
__Nonterminal::Items(__nt) => {
|
||||
let __sym0 = &mut Some(__nt);
|
||||
__result = try!(__state1(__lookbehind, __lookahead, __tokens, __sym0));
|
||||
__result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym0));
|
||||
}
|
||||
__Nonterminal::_40_3c(__nt) => {
|
||||
let __sym0 = &mut Some(__nt);
|
||||
__result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym0));
|
||||
__result = try!(__state1(__lookbehind, __lookahead, __tokens, __sym0));
|
||||
}
|
||||
_ => {
|
||||
return Ok((__lookbehind, __lookahead, __nt));
|
||||
@ -106,6 +111,65 @@ mod __parse__Items {
|
||||
}
|
||||
|
||||
// State 1
|
||||
// @> = (*) [EOF]
|
||||
// @> = (*) ["+"]
|
||||
// @> = (*) ["-"]
|
||||
// Items = @< (*) @> [EOF]
|
||||
// Items = @< (*) @> ["+"]
|
||||
// Items = @< (*) @> ["-"]
|
||||
//
|
||||
// "-" -> Reduce(@> = => Lookbehind;)
|
||||
// "+" -> Reduce(@> = => Lookbehind;)
|
||||
// EOF -> Reduce(@> = => Lookbehind;)
|
||||
//
|
||||
// @> -> S3
|
||||
pub fn __state1<
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<usize>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __nt = ::std::clone::Clone::clone(&__lookbehind).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||
}
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __nt = ::std::clone::Clone::clone(&__lookbehind).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||
}
|
||||
None => {
|
||||
let __nt = ::std::clone::Clone::clone(&__lookbehind).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||
}
|
||||
_ => {
|
||||
return Err(__ParseError::UnrecognizedToken {
|
||||
token: __lookahead,
|
||||
expected: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
while __sym0.is_some() {
|
||||
let (__lookbehind, __lookahead, __nt) = __result;
|
||||
match __nt {
|
||||
__Nonterminal::_40_3e(__nt) => {
|
||||
let __sym1 = &mut Some(__nt);
|
||||
__result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||
}
|
||||
_ => {
|
||||
return Ok((__lookbehind, __lookahead, __nt));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(__result);
|
||||
}
|
||||
|
||||
// State 2
|
||||
// @< = (*) ["+"]
|
||||
// Items = Items (*) Spanned<"+"> [EOF]
|
||||
// Items = Items (*) Spanned<"+"> ["+"]
|
||||
@ -118,28 +182,29 @@ mod __parse__Items {
|
||||
// Spanned<"+"> = (*) @< "+" @> ["-"]
|
||||
// __Items = Items (*) [EOF]
|
||||
//
|
||||
// "-" -> Shift(S4)
|
||||
// "+" -> Reduce(@< = => Lookahead;)
|
||||
// EOF -> Reduce(__Items = Items => Call(ActionFn(0));)
|
||||
// "-" -> Shift(S5)
|
||||
//
|
||||
// @< -> S4
|
||||
// Spanned<"+"> -> S3
|
||||
pub fn __state1<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
// Spanned<"+"> -> S6
|
||||
// @< -> S5
|
||||
pub fn __state2<
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<Vec<(usize, usize)>>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, __tok @ Tok::Minus(..), __loc)) => {
|
||||
let mut __lookbehind = Some(__loc);
|
||||
let mut __sym1 = &mut Some((__tok));
|
||||
let __lookahead = __tokens.next();
|
||||
__result = try!(__state5(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||
let __lookahead = match __tokens.next() { Some(Ok(v)) => Some(v), None => None, Some(Err(e)) => return Err(__ParseError::User { error: e }) };
|
||||
__result = try!(__state4(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||
}
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __nt = __lookahead.as_ref().map(|o| ::std::clone::Clone::clone(&o.0)).or_else(|| ::std::clone::Clone::clone(&__lookbehind)).unwrap_or_default();
|
||||
@ -160,72 +225,14 @@ mod __parse__Items {
|
||||
while __sym0.is_some() {
|
||||
let (__lookbehind, __lookahead, __nt) = __result;
|
||||
match __nt {
|
||||
__Nonterminal::_40_3c(__nt) => {
|
||||
let __sym1 = &mut Some(__nt);
|
||||
__result = try!(__state4(__lookbehind, __lookahead, __tokens, __sym1));
|
||||
}
|
||||
__Nonterminal::Spanned_3c_22_2b_22_3e(__nt) => {
|
||||
let __sym1 = &mut Some(__nt);
|
||||
__result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||
}
|
||||
_ => {
|
||||
return Ok((__lookbehind, __lookahead, __nt));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(__result);
|
||||
}
|
||||
|
||||
// State 2
|
||||
// @> = (*) [EOF]
|
||||
// @> = (*) ["+"]
|
||||
// @> = (*) ["-"]
|
||||
// Items = @< (*) @> [EOF]
|
||||
// Items = @< (*) @> ["+"]
|
||||
// Items = @< (*) @> ["-"]
|
||||
//
|
||||
// "+" -> Reduce(@> = => Lookbehind;)
|
||||
// "-" -> Reduce(@> = => Lookbehind;)
|
||||
// EOF -> Reduce(@> = => Lookbehind;)
|
||||
//
|
||||
// @> -> S6
|
||||
pub fn __state2<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<usize>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __nt = ::std::clone::Clone::clone(&__lookbehind).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||
}
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __nt = ::std::clone::Clone::clone(&__lookbehind).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||
}
|
||||
None => {
|
||||
let __nt = ::std::clone::Clone::clone(&__lookbehind).unwrap_or_default();
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||
}
|
||||
_ => {
|
||||
return Err(__ParseError::UnrecognizedToken {
|
||||
token: __lookahead,
|
||||
expected: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
while __sym0.is_some() {
|
||||
let (__lookbehind, __lookahead, __nt) = __result;
|
||||
match __nt {
|
||||
__Nonterminal::_40_3e(__nt) => {
|
||||
let __sym1 = &mut Some(__nt);
|
||||
__result = try!(__state6(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||
}
|
||||
__Nonterminal::_40_3c(__nt) => {
|
||||
let __sym1 = &mut Some(__nt);
|
||||
__result = try!(__state5(__lookbehind, __lookahead, __tokens, __sym1));
|
||||
}
|
||||
_ => {
|
||||
return Ok((__lookbehind, __lookahead, __nt));
|
||||
}
|
||||
@ -235,42 +242,43 @@ mod __parse__Items {
|
||||
}
|
||||
|
||||
// State 3
|
||||
// Items = Items Spanned<"+"> (*) [EOF]
|
||||
// Items = Items Spanned<"+"> (*) ["+"]
|
||||
// Items = Items Spanned<"+"> (*) ["-"]
|
||||
// Items = @< @> (*) [EOF]
|
||||
// Items = @< @> (*) ["+"]
|
||||
// Items = @< @> (*) ["-"]
|
||||
//
|
||||
// EOF -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||
// "+" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||
// "-" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||
// "+" -> Reduce(Items = @<, @> => Call(ActionFn(1));)
|
||||
// EOF -> Reduce(Items = @<, @> => Call(ActionFn(1));)
|
||||
// "-" -> Reduce(Items = @<, @> => Call(ActionFn(1));)
|
||||
//
|
||||
pub fn __state3<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<Vec<(usize, usize)>>,
|
||||
__sym1: &mut Option<(usize, usize)>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
__sym0: &mut Option<usize>,
|
||||
__sym1: &mut Option<usize>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
None => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action2(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action2(__sym0, __sym1);
|
||||
let __nt = super::__action1(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
None => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action1(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action2(__sym0, __sym1);
|
||||
let __nt = super::__action1(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
_ => {
|
||||
@ -283,27 +291,77 @@ mod __parse__Items {
|
||||
}
|
||||
|
||||
// State 4
|
||||
// Items = Items "-" (*) [EOF]
|
||||
// Items = Items "-" (*) ["+"]
|
||||
// Items = Items "-" (*) ["-"]
|
||||
//
|
||||
// EOF -> Reduce(Items = Items, "-" => Call(ActionFn(3));)
|
||||
// "-" -> Reduce(Items = Items, "-" => Call(ActionFn(3));)
|
||||
// "+" -> Reduce(Items = Items, "-" => Call(ActionFn(3));)
|
||||
//
|
||||
pub fn __state4<
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<Vec<(usize, usize)>>,
|
||||
__sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
None => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action3(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action3(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action3(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(__ParseError::UnrecognizedToken {
|
||||
token: __lookahead,
|
||||
expected: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 5
|
||||
// Spanned<"+"> = @< (*) "+" @> [EOF]
|
||||
// Spanned<"+"> = @< (*) "+" @> ["+"]
|
||||
// Spanned<"+"> = @< (*) "+" @> ["-"]
|
||||
//
|
||||
// "+" -> Shift(S7)
|
||||
//
|
||||
pub fn __state4<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
pub fn __state5<
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<usize>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, __tok @ Tok::Plus(..), __loc)) => {
|
||||
let mut __lookbehind = Some(__loc);
|
||||
let mut __sym1 = &mut Some((__tok));
|
||||
let __lookahead = __tokens.next();
|
||||
let __lookahead = match __tokens.next() { Some(Ok(v)) => Some(v), None => None, Some(Err(e)) => return Err(__ParseError::User { error: e }) };
|
||||
__result = try!(__state7(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||
}
|
||||
_ => {
|
||||
@ -316,91 +374,44 @@ mod __parse__Items {
|
||||
return Ok(__result);
|
||||
}
|
||||
|
||||
// State 5
|
||||
// Items = Items "-" (*) [EOF]
|
||||
// Items = Items "-" (*) ["+"]
|
||||
// Items = Items "-" (*) ["-"]
|
||||
// State 6
|
||||
// Items = Items Spanned<"+"> (*) [EOF]
|
||||
// Items = Items Spanned<"+"> (*) ["+"]
|
||||
// Items = Items Spanned<"+"> (*) ["-"]
|
||||
//
|
||||
// "-" -> Reduce(Items = Items, "-" => Call(ActionFn(3));)
|
||||
// "+" -> Reduce(Items = Items, "-" => Call(ActionFn(3));)
|
||||
// EOF -> Reduce(Items = Items, "-" => Call(ActionFn(3));)
|
||||
// "+" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||
// "-" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||
// EOF -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||
//
|
||||
pub fn __state5<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
pub fn __state6<
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<Vec<(usize, usize)>>,
|
||||
__sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
__sym1: &mut Option<(usize, usize)>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action3(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action3(__sym0, __sym1);
|
||||
let __nt = super::__action2(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action2(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
None => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action3(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(__ParseError::UnrecognizedToken {
|
||||
token: __lookahead,
|
||||
expected: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 6
|
||||
// Items = @< @> (*) [EOF]
|
||||
// Items = @< @> (*) ["+"]
|
||||
// Items = @< @> (*) ["-"]
|
||||
//
|
||||
// "-" -> Reduce(Items = @<, @> => Call(ActionFn(1));)
|
||||
// EOF -> Reduce(Items = @<, @> => Call(ActionFn(1));)
|
||||
// "+" -> Reduce(Items = @<, @> => Call(ActionFn(1));)
|
||||
//
|
||||
pub fn __state6<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<usize>,
|
||||
__sym1: &mut Option<usize>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action1(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
None => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action1(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
Some((_, Tok::Plus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action1(__sym0, __sym1);
|
||||
let __nt = super::__action2(__sym0, __sym1);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||
}
|
||||
_ => {
|
||||
@ -426,14 +437,15 @@ mod __parse__Items {
|
||||
//
|
||||
// @> -> S8
|
||||
pub fn __state7<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<usize>,
|
||||
__sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
@ -476,12 +488,13 @@ mod __parse__Items {
|
||||
// Spanned<"+"> = @< "+" @> (*) ["+"]
|
||||
// Spanned<"+"> = @< "+" @> (*) ["-"]
|
||||
//
|
||||
// "-" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||
// "+" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||
// EOF -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||
// "+" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||
// "-" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||
//
|
||||
pub fn __state8<
|
||||
__TOKENS: Iterator<Item=(usize, Tok, usize)>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<(usize, Tok, usize),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<usize>,
|
||||
__lookahead: Option<(usize, Tok, usize)>,
|
||||
@ -489,11 +502,11 @@ mod __parse__Items {
|
||||
__sym0: &mut Option<usize>,
|
||||
__sym1: &mut Option<Tok>,
|
||||
__sym2: &mut Option<usize>,
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok>>
|
||||
) -> Result<(Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>), __ParseError<usize,Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<usize>, Option<(usize, Tok, usize)>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
None => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __sym2 = __sym2.take().unwrap();
|
||||
@ -507,7 +520,7 @@ mod __parse__Items {
|
||||
let __nt = super::__action4(__sym0, __sym1, __sym2);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Spanned_3c_22_2b_22_3e(__nt)));
|
||||
}
|
||||
None => {
|
||||
Some((_, Tok::Minus(..), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __sym2 = __sym2.take().unwrap();
|
||||
@ -572,3 +585,21 @@ pub fn __action4<
|
||||
{
|
||||
(__0, __1)
|
||||
}
|
||||
|
||||
pub trait __ToTriple {
|
||||
type Error;
|
||||
fn to_triple(value: Self) -> Result<(usize,Tok,usize),Self::Error>;
|
||||
}
|
||||
|
||||
impl __ToTriple for (usize, Tok, usize) {
|
||||
type Error = ();
|
||||
fn to_triple(value: Self) -> Result<(usize,Tok,usize),()> {
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
impl<ERROR> __ToTriple for Result<(usize, Tok, usize),ERROR> {
|
||||
type Error = ERROR;
|
||||
fn to_triple(value: Self) -> Result<(usize,Tok,usize),ERROR> {
|
||||
value
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,14 +4,16 @@ extern crate lalrpop_util as __lalrpop_util;
|
||||
use self::__lalrpop_util::ParseError as __ParseError;
|
||||
#[allow(non_snake_case)]
|
||||
pub fn parse_S<
|
||||
__TOKENS: IntoIterator<Item=Tok>,
|
||||
__ERROR,
|
||||
__TOKEN: __ToTriple<Error=__ERROR>,
|
||||
__TOKENS: IntoIterator<Item=__TOKEN>,
|
||||
>(
|
||||
__tokens: __TOKENS,
|
||||
) -> Result<i32, __ParseError<(),Tok>>
|
||||
) -> Result<i32, __ParseError<(),Tok,__ERROR>>
|
||||
{
|
||||
let mut __tokens = __tokens.into_iter();
|
||||
let mut __tokens = __tokens.map(|t| ((), t, ()));
|
||||
let __lookahead = __tokens.next();
|
||||
let mut __tokens = __tokens.map(|t| __ToTriple::to_triple(t));
|
||||
let __lookahead = match __tokens.next() { Some(Ok(v)) => Some(v), None => None, Some(Err(e)) => return Err(__ParseError::User { error: e }) };
|
||||
match try!(__parse__S::__state0(None, __lookahead, &mut __tokens)) {
|
||||
(_, Some(__lookahead), _) => {
|
||||
Err(__ParseError::ExtraToken { token: __lookahead })
|
||||
@ -29,6 +31,7 @@ mod __parse__S {
|
||||
use super::super::util::tok::Tok;
|
||||
extern crate lalrpop_util as __lalrpop_util;
|
||||
use self::__lalrpop_util::ParseError as __ParseError;
|
||||
use super::__ToTriple;
|
||||
|
||||
pub enum __Nonterminal<> {
|
||||
____S(i32),
|
||||
@ -43,19 +46,20 @@ mod __parse__S {
|
||||
//
|
||||
// S -> S2
|
||||
pub fn __state0<
|
||||
__TOKENS: Iterator<Item=((), Tok, ())>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<((), Tok, ()),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<()>,
|
||||
__lookahead: Option<((), Tok, ())>,
|
||||
__tokens: &mut __TOKENS,
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok>>
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<()>, Option<((), Tok, ())>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, __tok @ Tok::LParen(..), __loc)) => {
|
||||
let mut __lookbehind = Some(__loc);
|
||||
let mut __sym0 = &mut Some((__tok));
|
||||
let __lookahead = __tokens.next();
|
||||
let __lookahead = match __tokens.next() { Some(Ok(v)) => Some(v), None => None, Some(Err(e)) => return Err(__ParseError::User { error: e }) };
|
||||
__result = try!(__state1(__lookbehind, __lookahead, __tokens, __sym0));
|
||||
}
|
||||
_ => {
|
||||
@ -85,20 +89,21 @@ mod __parse__S {
|
||||
// ")" -> Shift(S3)
|
||||
//
|
||||
pub fn __state1<
|
||||
__TOKENS: Iterator<Item=((), Tok, ())>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<((), Tok, ()),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<()>,
|
||||
__lookahead: Option<((), Tok, ())>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<Tok>,
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok>>
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<()>, Option<((), Tok, ())>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
Some((_, __tok @ Tok::RParen(..), __loc)) => {
|
||||
let mut __lookbehind = Some(__loc);
|
||||
let mut __sym1 = &mut Some((__tok));
|
||||
let __lookahead = __tokens.next();
|
||||
let __lookahead = match __tokens.next() { Some(Ok(v)) => Some(v), None => None, Some(Err(e)) => return Err(__ParseError::User { error: e }) };
|
||||
__result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||
}
|
||||
_ => {
|
||||
@ -117,13 +122,14 @@ mod __parse__S {
|
||||
// EOF -> Reduce(__S = S => Call(ActionFn(0));)
|
||||
//
|
||||
pub fn __state2<
|
||||
__TOKENS: Iterator<Item=((), Tok, ())>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<((), Tok, ()),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<()>,
|
||||
__lookahead: Option<((), Tok, ())>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<i32>,
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok>>
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<()>, Option<((), Tok, ())>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
@ -147,14 +153,15 @@ mod __parse__S {
|
||||
// EOF -> Reduce(S = "(", ")" => Call(ActionFn(1));)
|
||||
//
|
||||
pub fn __state3<
|
||||
__TOKENS: Iterator<Item=((), Tok, ())>,
|
||||
__ERROR,
|
||||
__TOKENS: Iterator<Item=Result<((), Tok, ()),__ERROR>>,
|
||||
>(
|
||||
__lookbehind: Option<()>,
|
||||
__lookahead: Option<((), Tok, ())>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<Tok>,
|
||||
__sym1: &mut Option<Tok>,
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok>>
|
||||
) -> Result<(Option<()>, Option<((), Tok, ())>, __Nonterminal<>), __ParseError<(),Tok,__ERROR>>
|
||||
{
|
||||
let mut __result: (Option<()>, Option<((), Tok, ())>, __Nonterminal<>);
|
||||
match __lookahead {
|
||||
@ -190,3 +197,21 @@ pub fn __action1<
|
||||
{
|
||||
super::ZERO
|
||||
}
|
||||
|
||||
pub trait __ToTriple {
|
||||
type Error;
|
||||
fn to_triple(value: Self) -> Result<((),Tok,()),Self::Error>;
|
||||
}
|
||||
|
||||
impl __ToTriple for Tok {
|
||||
type Error = ();
|
||||
fn to_triple(value: Self) -> Result<((),Tok,()),()> {
|
||||
Ok(((), value, ()))
|
||||
}
|
||||
}
|
||||
impl<ERROR> __ToTriple for Result<(Tok),ERROR> {
|
||||
type Error = ERROR;
|
||||
fn to_triple(value: Self) -> Result<((),Tok,()),ERROR> {
|
||||
value.map(|v| ((), v, ()))
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ pub mod tok;
|
||||
pub fn test<R:Debug+Eq,F>(parse_fn: F,
|
||||
input: &str,
|
||||
expected: R)
|
||||
where F: FnOnce(Vec<Tok>) -> Result<R,ParseError<(),Tok>>
|
||||
where F: FnOnce(Vec<Tok>) -> Result<R,ParseError<(),Tok,()>>
|
||||
{
|
||||
// create tokens
|
||||
let tokens = tok::tokenize(input);
|
||||
@ -28,7 +28,7 @@ pub fn test<R:Debug+Eq,F>(parse_fn: F,
|
||||
pub fn test_loc<R:Debug+Eq,F>(parse_fn: F,
|
||||
input: &str,
|
||||
expected: R)
|
||||
where F: FnOnce(Vec<(usize, Tok, usize)>) -> Result<R, ParseError<usize, Tok>>
|
||||
where F: FnOnce(Vec<(usize, Tok, usize)>) -> Result<R, ParseError<usize, Tok, ()>>
|
||||
{
|
||||
// create tokens
|
||||
let tokens = tok::tokenize(input);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ParseError<L,T> {
|
||||
pub enum ParseError<L,T,E> {
|
||||
/// Generated by the parser when it encounters a token (or EOF) it did not
|
||||
/// expect.
|
||||
UnrecognizedToken {
|
||||
@ -46,5 +46,10 @@ pub enum ParseError<L,T> {
|
||||
ErrorObject {
|
||||
error: Box<Error>,
|
||||
},
|
||||
|
||||
/// Custom error type.
|
||||
User {
|
||||
error: E,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -150,6 +150,9 @@ fn emit_recursive_ascent(output_path: &Path, grammar: &r::Grammar) -> io::Result
|
||||
}
|
||||
|
||||
try!(emit_action_code(grammar, &mut rust));
|
||||
|
||||
try!(emit_to_triple_trait(grammar, &mut rust));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -175,3 +178,54 @@ fn emit_action_code<W:Write>(grammar: &r::Grammar,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn emit_to_triple_trait<W:Write>(grammar: &r::Grammar,
|
||||
rust: &mut RustWrite<W>)
|
||||
-> io::Result<()>
|
||||
{
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
let L = grammar.types.terminal_loc_type();
|
||||
let E = grammar.types.terminal_enum_type();
|
||||
|
||||
rust!(rust, "");
|
||||
rust!(rust, "pub trait {}ToTriple {{", grammar.prefix);
|
||||
rust!(rust, "type Error;");
|
||||
rust!(rust, "fn to_triple(value: Self) -> Result<({},{},{}),Self::Error>;", L, E, L);
|
||||
rust!(rust, "}}");
|
||||
|
||||
rust!(rust, "");
|
||||
if grammar.types.opt_terminal_loc_type().is_some() {
|
||||
rust!(rust, "impl {}ToTriple for ({}, {}, {}) {{",
|
||||
grammar.prefix, L, E, L);
|
||||
rust!(rust, "type Error = ();");
|
||||
rust!(rust, "fn to_triple(value: Self) -> Result<({},{},{}),()> {{", L, E, L);
|
||||
rust!(rust, "Ok(value)");
|
||||
rust!(rust, "}}");
|
||||
rust!(rust, "}}");
|
||||
|
||||
rust!(rust, "impl<ERROR> {}ToTriple for Result<({}, {}, {}),ERROR> {{",
|
||||
grammar.prefix, L, E, L);
|
||||
rust!(rust, "type Error = ERROR;");
|
||||
rust!(rust, "fn to_triple(value: Self) -> Result<({},{},{}),ERROR> {{", L, E, L);
|
||||
rust!(rust, "value");
|
||||
rust!(rust, "}}");
|
||||
rust!(rust, "}}");
|
||||
} else {
|
||||
rust!(rust, "impl {}ToTriple for {} {{", grammar.prefix, E);
|
||||
rust!(rust, "type Error = ();");
|
||||
rust!(rust, "fn to_triple(value: Self) -> Result<((),{},()),()> {{", E);
|
||||
rust!(rust, "Ok(((), value, ()))");
|
||||
rust!(rust, "}}");
|
||||
rust!(rust, "}}");
|
||||
|
||||
rust!(rust, "impl<ERROR> {}ToTriple for Result<({}),ERROR> {{", grammar.prefix, E);
|
||||
rust!(rust, "type Error = ERROR;");
|
||||
rust!(rust, "fn to_triple(value: Self) -> Result<((),{},()),ERROR> {{", E);
|
||||
rust!(rust, "value.map(|v| ((), v, ()))");
|
||||
rust!(rust, "}}");
|
||||
rust!(rust, "}}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -84,7 +84,9 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> {
|
||||
}
|
||||
|
||||
fn write_uses(&mut self) -> io::Result<()> {
|
||||
self.out.write_uses("super::", &self.grammar)
|
||||
try!(self.out.write_uses("super::", &self.grammar));
|
||||
rust!(self.out, "use super::{}ToTriple;", self.prefix);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_return_type_defn(&mut self) -> io::Result<()> {
|
||||
@ -108,19 +110,16 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> {
|
||||
// input as `Foo`. An error is reported if the entire input is not
|
||||
// consumed.
|
||||
fn write_start_fn(&mut self) -> io::Result<()> {
|
||||
let triple_type = self.triple_type();
|
||||
let error_type = self.error_type();
|
||||
|
||||
let user_token_type = match self.types.opt_terminal_loc_type() {
|
||||
Some(_) => format!("{}", triple_type),
|
||||
None => format!("{}", self.types.terminal_enum_type())
|
||||
};
|
||||
|
||||
rust!(self.out, "#[allow(non_snake_case)]");
|
||||
try!(self.out.write_pub_fn_header(
|
||||
self.grammar,
|
||||
format!("parse_{}", self.user_start_symbol),
|
||||
vec![format!("{}TOKENS: IntoIterator<Item={}>", self.prefix, user_token_type)],
|
||||
vec![format!("{}ERROR", self.prefix),
|
||||
format!("{}TOKEN: {}ToTriple<Error={}ERROR>",
|
||||
self.prefix, self.prefix, self.prefix),
|
||||
format!("{}TOKENS: IntoIterator<Item={}TOKEN>", self.prefix, self.prefix)],
|
||||
vec![format!("{}tokens: {}TOKENS", self.prefix, self.prefix)],
|
||||
format!("Result<{}, {}>",
|
||||
self.types.nonterminal_type(self.start_symbol),
|
||||
@ -130,13 +129,11 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> {
|
||||
|
||||
// create input iterator, inserting `()` for locations if no location was given
|
||||
rust!(self.out, "let mut {}tokens = {}tokens.into_iter();", self.prefix, self.prefix);
|
||||
match self.types.opt_terminal_loc_type() {
|
||||
Some(_) => { }
|
||||
None => { rust!(self.out, "let mut {}tokens = {}tokens.map(|t| ((), t, ()));",
|
||||
self.prefix, self.prefix); }
|
||||
}
|
||||
rust!(self.out, "let mut {}tokens = {}tokens.map(|t| {}ToTriple::to_triple(t));",
|
||||
self.prefix, self.prefix, self.prefix);
|
||||
|
||||
rust!(self.out, "let {}lookahead = {}tokens.next();", self.prefix, self.prefix);
|
||||
let next_token = self.next_token("tokens");
|
||||
rust!(self.out, "let {}lookahead = {};", self.prefix, next_token);
|
||||
rust!(self.out, "match try!({}parse{}::{}state0({}None, {}lookahead, &mut {}tokens)) {{",
|
||||
self.prefix, self.start_symbol, self.prefix,
|
||||
self.grammar.user_parameter_refs(), self.prefix, self.prefix);
|
||||
@ -199,7 +196,9 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> {
|
||||
try!(self.out.write_pub_fn_header(
|
||||
self.grammar,
|
||||
format!("{}state{}", self.prefix, this_index.0),
|
||||
vec![format!("{}TOKENS: Iterator<Item={}>", self.prefix, triple_type)],
|
||||
vec![format!("{}ERROR", self.prefix),
|
||||
format!("{}TOKENS: Iterator<Item=Result<{},{}ERROR>>",
|
||||
self.prefix, triple_type, self.prefix)],
|
||||
base_args.into_iter().chain(sym_args).collect(),
|
||||
format!("Result<(Option<{}>, Option<{}>, {}Nonterminal<{}>), {}>",
|
||||
loc_type,
|
||||
@ -231,8 +230,8 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> {
|
||||
}
|
||||
|
||||
// "shift" the lookahead onto the "stack" by taking its address
|
||||
rust!(self.out, "let {}lookahead = {}tokens.next();",
|
||||
self.prefix, self.prefix);
|
||||
let next_token = self.next_token("tokens");
|
||||
rust!(self.out, "let {}lookahead = {};", self.prefix, next_token);
|
||||
|
||||
// transition to the new state
|
||||
let transition =
|
||||
@ -457,10 +456,19 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> {
|
||||
}
|
||||
|
||||
fn error_type(&mut self) -> String {
|
||||
format!("{}ParseError<{},{}>",
|
||||
format!("{}ParseError<{},{},{}ERROR>",
|
||||
self.prefix,
|
||||
self.types.terminal_loc_type(),
|
||||
self.types.terminal_enum_type())
|
||||
self.types.terminal_enum_type(),
|
||||
self.prefix)
|
||||
}
|
||||
|
||||
fn next_token(&mut self, tokens: &str) -> String {
|
||||
format!("match {}{}.next() {{ \
|
||||
Some(Ok(v)) => Some(v), \
|
||||
None => None, \
|
||||
Some(Err(e)) => return Err({}ParseError::User {{ error: e }}) }}",
|
||||
self.prefix, tokens, self.prefix)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user