mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-04-24 18:52:16 +00:00
move the action code back into the parent module so that super::
resolves correctly (as I originally intended, but forgot) and add a test
This commit is contained in:
parent
0ec6824eeb
commit
ae37f374cc
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -22,11 +22,11 @@ mod __parse__Items {
|
|||||||
use util::tok::Tok;
|
use util::tok::Tok;
|
||||||
|
|
||||||
pub enum __Nonterminal<> {
|
pub enum __Nonterminal<> {
|
||||||
____Items(Vec<(Option<usize>, Option<usize>)>),
|
|
||||||
Items(Vec<(Option<usize>, Option<usize>)>),
|
Items(Vec<(Option<usize>, Option<usize>)>),
|
||||||
_40_3e(::std::option::Option<usize>),
|
_40_3e(::std::option::Option<usize>),
|
||||||
Spanned_3c_22_2b_22_3e((Option<usize>, Option<usize>)),
|
|
||||||
_40_3c(::std::option::Option<usize>),
|
_40_3c(::std::option::Option<usize>),
|
||||||
|
____Items(Vec<(Option<usize>, Option<usize>)>),
|
||||||
|
Spanned_3c_22_2b_22_3e((Option<usize>, Option<usize>)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// State 0
|
// State 0
|
||||||
@ -41,9 +41,9 @@ mod __parse__Items {
|
|||||||
// Items = (*) Items "-" ["-"]
|
// Items = (*) Items "-" ["-"]
|
||||||
// __Items = (*) Items [EOF]
|
// __Items = (*) Items [EOF]
|
||||||
//
|
//
|
||||||
|
// "-" -> Reduce(Items = => Call(ActionFn(1));)
|
||||||
// "+" -> Reduce(Items = => Call(ActionFn(1));)
|
// "+" -> Reduce(Items = => Call(ActionFn(1));)
|
||||||
// EOF -> Reduce(Items = => Call(ActionFn(1));)
|
// EOF -> Reduce(Items = => Call(ActionFn(1));)
|
||||||
// "-" -> Reduce(Items = => Call(ActionFn(1));)
|
|
||||||
//
|
//
|
||||||
// Items -> S1
|
// Items -> S1
|
||||||
pub fn __state0<
|
pub fn __state0<
|
||||||
@ -56,16 +56,16 @@ mod __parse__Items {
|
|||||||
{
|
{
|
||||||
let mut __result: (Option<usize>, Option<(usize,Tok,usize)>, __Nonterminal<>);
|
let mut __result: (Option<usize>, Option<(usize,Tok,usize)>, __Nonterminal<>);
|
||||||
match __lookahead {
|
match __lookahead {
|
||||||
|
Some((_, Tok::Minus(..), _)) => {
|
||||||
|
let __nt = super::__action1();
|
||||||
|
__result = (__lookbehind, __lookahead, __Nonterminal::Items(__nt));
|
||||||
|
}
|
||||||
Some((_, Tok::Plus(..), _)) => {
|
Some((_, Tok::Plus(..), _)) => {
|
||||||
let __nt = super::__actions::__action1();
|
let __nt = super::__action1();
|
||||||
__result = (__lookbehind, __lookahead, __Nonterminal::Items(__nt));
|
__result = (__lookbehind, __lookahead, __Nonterminal::Items(__nt));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let __nt = super::__actions::__action1();
|
let __nt = super::__action1();
|
||||||
__result = (__lookbehind, __lookahead, __Nonterminal::Items(__nt));
|
|
||||||
}
|
|
||||||
Some((_, Tok::Minus(..), _)) => {
|
|
||||||
let __nt = super::__actions::__action1();
|
|
||||||
__result = (__lookbehind, __lookahead, __Nonterminal::Items(__nt));
|
__result = (__lookbehind, __lookahead, __Nonterminal::Items(__nt));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -99,12 +99,12 @@ mod __parse__Items {
|
|||||||
// Spanned<"+"> = (*) @< "+" @> ["-"]
|
// Spanned<"+"> = (*) @< "+" @> ["-"]
|
||||||
// __Items = Items (*) [EOF]
|
// __Items = Items (*) [EOF]
|
||||||
//
|
//
|
||||||
|
// "+" -> Reduce(@< = => Lookahead;)
|
||||||
// EOF -> Reduce(__Items = Items => Call(ActionFn(0));)
|
// EOF -> Reduce(__Items = Items => Call(ActionFn(0));)
|
||||||
// "-" -> Shift(S2)
|
// "-" -> Shift(S2)
|
||||||
// "+" -> Reduce(@< = => Lookahead;)
|
|
||||||
//
|
//
|
||||||
// @< -> S3
|
|
||||||
// Spanned<"+"> -> S4
|
// Spanned<"+"> -> S4
|
||||||
|
// @< -> S3
|
||||||
pub fn __state1<
|
pub fn __state1<
|
||||||
__TOKENS: Iterator<Item=(usize,Tok,usize)>,
|
__TOKENS: Iterator<Item=(usize,Tok,usize)>,
|
||||||
>(
|
>(
|
||||||
@ -122,15 +122,15 @@ mod __parse__Items {
|
|||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
__result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||||
}
|
}
|
||||||
None => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action0(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::____Items(__nt)));
|
|
||||||
}
|
|
||||||
Some((_, Tok::Plus(..), _)) => {
|
Some((_, Tok::Plus(..), _)) => {
|
||||||
let __nt = __lookahead.as_ref().map(|o| ::std::clone::Clone::clone(&o.0));
|
let __nt = __lookahead.as_ref().map(|o| ::std::clone::Clone::clone(&o.0));
|
||||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3c(__nt));
|
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3c(__nt));
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action0(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::____Items(__nt)));
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(__lookahead);
|
return Err(__lookahead);
|
||||||
}
|
}
|
||||||
@ -138,14 +138,14 @@ mod __parse__Items {
|
|||||||
while __sym0.is_some() {
|
while __sym0.is_some() {
|
||||||
let (__lookbehind, __lookahead, __nt) = __result;
|
let (__lookbehind, __lookahead, __nt) = __result;
|
||||||
match __nt {
|
match __nt {
|
||||||
__Nonterminal::_40_3c(__nt) => {
|
|
||||||
let __sym1 = &mut Some(__nt);
|
|
||||||
__result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym1));
|
|
||||||
}
|
|
||||||
__Nonterminal::Spanned_3c_22_2b_22_3e(__nt) => {
|
__Nonterminal::Spanned_3c_22_2b_22_3e(__nt) => {
|
||||||
let __sym1 = &mut Some(__nt);
|
let __sym1 = &mut Some(__nt);
|
||||||
__result = try!(__state4(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
__result = try!(__state4(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||||
}
|
}
|
||||||
|
__Nonterminal::_40_3c(__nt) => {
|
||||||
|
let __sym1 = &mut Some(__nt);
|
||||||
|
__result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym1));
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Ok((__lookbehind, __lookahead, __nt));
|
return Ok((__lookbehind, __lookahead, __nt));
|
||||||
}
|
}
|
||||||
@ -178,19 +178,19 @@ mod __parse__Items {
|
|||||||
Some((_, Tok::Minus(..), _)) => {
|
Some((_, Tok::Minus(..), _)) => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __nt = super::__actions::__action3(__sym0, __sym1);
|
let __nt = super::__action3(__sym0, __sym1);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||||
}
|
}
|
||||||
Some((_, Tok::Plus(..), _)) => {
|
Some((_, Tok::Plus(..), _)) => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __nt = super::__actions::__action3(__sym0, __sym1);
|
let __nt = super::__action3(__sym0, __sym1);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __nt = super::__actions::__action3(__sym0, __sym1);
|
let __nt = super::__action3(__sym0, __sym1);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -236,8 +236,8 @@ mod __parse__Items {
|
|||||||
// Items = Items Spanned<"+"> (*) ["-"]
|
// Items = Items Spanned<"+"> (*) ["-"]
|
||||||
//
|
//
|
||||||
// EOF -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
// EOF -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||||
// "+" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
|
||||||
// "-" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
// "-" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||||
|
// "+" -> Reduce(Items = Items, Spanned<"+"> => Call(ActionFn(2));)
|
||||||
//
|
//
|
||||||
pub fn __state4<
|
pub fn __state4<
|
||||||
__TOKENS: Iterator<Item=(usize,Tok,usize)>,
|
__TOKENS: Iterator<Item=(usize,Tok,usize)>,
|
||||||
@ -254,19 +254,19 @@ mod __parse__Items {
|
|||||||
None => {
|
None => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __nt = super::__actions::__action2(__sym0, __sym1);
|
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::__actions::__action2(__sym0, __sym1);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||||
}
|
}
|
||||||
Some((_, Tok::Minus(..), _)) => {
|
Some((_, Tok::Minus(..), _)) => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __nt = super::__actions::__action2(__sym0, __sym1);
|
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);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::Items(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -283,9 +283,9 @@ mod __parse__Items {
|
|||||||
// Spanned<"+"> = @< "+" (*) @> ["+"]
|
// Spanned<"+"> = @< "+" (*) @> ["+"]
|
||||||
// Spanned<"+"> = @< "+" (*) @> ["-"]
|
// Spanned<"+"> = @< "+" (*) @> ["-"]
|
||||||
//
|
//
|
||||||
// "-" -> Reduce(@> = => Lookbehind;)
|
|
||||||
// "+" -> Reduce(@> = => Lookbehind;)
|
|
||||||
// EOF -> Reduce(@> = => Lookbehind;)
|
// EOF -> Reduce(@> = => Lookbehind;)
|
||||||
|
// "+" -> Reduce(@> = => Lookbehind;)
|
||||||
|
// "-" -> Reduce(@> = => Lookbehind;)
|
||||||
//
|
//
|
||||||
// @> -> S6
|
// @> -> S6
|
||||||
pub fn __state5<
|
pub fn __state5<
|
||||||
@ -300,7 +300,7 @@ mod __parse__Items {
|
|||||||
{
|
{
|
||||||
let mut __result: (Option<usize>, Option<(usize,Tok,usize)>, __Nonterminal<>);
|
let mut __result: (Option<usize>, Option<(usize,Tok,usize)>, __Nonterminal<>);
|
||||||
match __lookahead {
|
match __lookahead {
|
||||||
Some((_, Tok::Minus(..), _)) => {
|
None => {
|
||||||
let __nt = ::std::clone::Clone::clone(&__lookbehind);
|
let __nt = ::std::clone::Clone::clone(&__lookbehind);
|
||||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||||
}
|
}
|
||||||
@ -308,7 +308,7 @@ mod __parse__Items {
|
|||||||
let __nt = ::std::clone::Clone::clone(&__lookbehind);
|
let __nt = ::std::clone::Clone::clone(&__lookbehind);
|
||||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||||
}
|
}
|
||||||
None => {
|
Some((_, Tok::Minus(..), _)) => {
|
||||||
let __nt = ::std::clone::Clone::clone(&__lookbehind);
|
let __nt = ::std::clone::Clone::clone(&__lookbehind);
|
||||||
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
__result = (__lookbehind, __lookahead, __Nonterminal::_40_3e(__nt));
|
||||||
}
|
}
|
||||||
@ -336,9 +336,9 @@ mod __parse__Items {
|
|||||||
// Spanned<"+"> = @< "+" @> (*) ["+"]
|
// Spanned<"+"> = @< "+" @> (*) ["+"]
|
||||||
// Spanned<"+"> = @< "+" @> (*) ["-"]
|
// Spanned<"+"> = @< "+" @> (*) ["-"]
|
||||||
//
|
//
|
||||||
|
// "-" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||||
// "+" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
// "+" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||||
// EOF -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
// EOF -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
||||||
// "-" -> Reduce(Spanned<"+"> = @<, "+", @> => Call(ActionFn(4));)
|
|
||||||
//
|
//
|
||||||
pub fn __state6<
|
pub fn __state6<
|
||||||
__TOKENS: Iterator<Item=(usize,Tok,usize)>,
|
__TOKENS: Iterator<Item=(usize,Tok,usize)>,
|
||||||
@ -353,25 +353,25 @@ mod __parse__Items {
|
|||||||
{
|
{
|
||||||
let mut __result: (Option<usize>, Option<(usize,Tok,usize)>, __Nonterminal<>);
|
let mut __result: (Option<usize>, Option<(usize,Tok,usize)>, __Nonterminal<>);
|
||||||
match __lookahead {
|
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((__lookbehind, __lookahead, __Nonterminal::Spanned_3c_22_2b_22_3e(__nt)));
|
||||||
|
}
|
||||||
Some((_, Tok::Plus(..), _)) => {
|
Some((_, Tok::Plus(..), _)) => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action4(__sym0, __sym1, __sym2);
|
let __nt = super::__action4(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Spanned_3c_22_2b_22_3e(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::Spanned_3c_22_2b_22_3e(__nt)));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action4(__sym0, __sym1, __sym2);
|
let __nt = super::__action4(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Spanned_3c_22_2b_22_3e(__nt)));
|
|
||||||
}
|
|
||||||
Some((_, Tok::Minus(..), _)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __sym1 = __sym1.take().unwrap();
|
|
||||||
let __sym2 = __sym2.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action4(__sym0, __sym1, __sym2);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Spanned_3c_22_2b_22_3e(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::Spanned_3c_22_2b_22_3e(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -381,54 +381,49 @@ mod __parse__Items {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod __actions {
|
pub fn __action0<
|
||||||
use util::tok::Tok;
|
>(
|
||||||
|
__0: Vec<(Option<usize>, Option<usize>)>,
|
||||||
|
) -> Vec<(Option<usize>, Option<usize>)>
|
||||||
|
{
|
||||||
|
(__0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn __action1<
|
||||||
|
>(
|
||||||
|
) -> Vec<(Option<usize>, Option<usize>)>
|
||||||
|
{
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn __action0<
|
pub fn __action2<
|
||||||
>(
|
>(
|
||||||
__0: Vec<(Option<usize>, Option<usize>)>,
|
v: Vec<(Option<usize>, Option<usize>)>,
|
||||||
) -> Vec<(Option<usize>, Option<usize>)>
|
e: (Option<usize>, Option<usize>),
|
||||||
|
) -> Vec<(Option<usize>, Option<usize>)>
|
||||||
|
{
|
||||||
{
|
{
|
||||||
(__0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn __action1<
|
|
||||||
>(
|
|
||||||
) -> Vec<(Option<usize>, Option<usize>)>
|
|
||||||
{
|
|
||||||
vec![]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn __action2<
|
|
||||||
>(
|
|
||||||
v: Vec<(Option<usize>, Option<usize>)>,
|
|
||||||
e: (Option<usize>, Option<usize>),
|
|
||||||
) -> Vec<(Option<usize>, Option<usize>)>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
let mut v = v;
|
let mut v = v;
|
||||||
v.push(e);
|
v.push(e);
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn __action3<
|
pub fn __action3<
|
||||||
>(
|
>(
|
||||||
v: Vec<(Option<usize>, Option<usize>)>,
|
v: Vec<(Option<usize>, Option<usize>)>,
|
||||||
_: Tok,
|
_: Tok,
|
||||||
) -> Vec<(Option<usize>, Option<usize>)>
|
) -> Vec<(Option<usize>, Option<usize>)>
|
||||||
{
|
{
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn __action4<
|
pub fn __action4<
|
||||||
>(
|
>(
|
||||||
__0: ::std::option::Option<usize>,
|
__0: ::std::option::Option<usize>,
|
||||||
_: Tok,
|
_: Tok,
|
||||||
__1: ::std::option::Option<usize>,
|
__1: ::std::option::Option<usize>,
|
||||||
) -> (Option<usize>, Option<usize>)
|
) -> (Option<usize>, Option<usize>)
|
||||||
{
|
{
|
||||||
(__0, __1)
|
(__0, __1)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@ mod loc;
|
|||||||
mod sub;
|
mod sub;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
/// This constant is here so that some of the generator parsers can
|
||||||
|
/// refer to it in order to test `super::` handling in action code.
|
||||||
|
const ZERO: i32 = 0;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn expr_test1() {
|
fn expr_test1() {
|
||||||
util::test(|v| expr::parse_Expr(1, v), "22 - 3", 22 - 3);
|
util::test(|v| expr::parse_Expr(1, v), "22 - 3", 22 - 3);
|
||||||
|
@ -13,10 +13,10 @@ extern token {
|
|||||||
|
|
||||||
pub S = E;
|
pub S = E;
|
||||||
|
|
||||||
E = {
|
E: i32 = {
|
||||||
<l:E> "-" <r:T> => l-r;
|
<l:E> "-" <r:T> => l - r;
|
||||||
|
|
||||||
T;
|
<t:T> => t - super::ZERO;
|
||||||
};
|
};
|
||||||
|
|
||||||
T = {
|
T = {
|
||||||
|
@ -22,10 +22,10 @@ mod __parse__S {
|
|||||||
use util::tok::Tok;
|
use util::tok::Tok;
|
||||||
|
|
||||||
pub enum __Nonterminal<> {
|
pub enum __Nonterminal<> {
|
||||||
E(i32),
|
____S(i32),
|
||||||
S(i32),
|
S(i32),
|
||||||
T(i32),
|
T(i32),
|
||||||
____S(i32),
|
E(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
// State 0
|
// State 0
|
||||||
@ -40,12 +40,12 @@ mod __parse__S {
|
|||||||
// T = (*) "Num" ["-"]
|
// T = (*) "Num" ["-"]
|
||||||
// __S = (*) S [EOF]
|
// __S = (*) S [EOF]
|
||||||
//
|
//
|
||||||
// "Num" -> Shift(S2)
|
// "Num" -> Shift(S5)
|
||||||
// "(" -> Shift(S4)
|
// "(" -> Shift(S4)
|
||||||
//
|
//
|
||||||
// S -> S3
|
// S -> S2
|
||||||
// E -> S1
|
// T -> S1
|
||||||
// T -> S5
|
// E -> S3
|
||||||
pub fn __state0<
|
pub fn __state0<
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
>(
|
>(
|
||||||
@ -60,7 +60,7 @@ mod __parse__S {
|
|||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym0 = &mut Some((__tok0));
|
let mut __sym0 = &mut Some((__tok0));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym0));
|
__result = try!(__state5(__lookbehind, __lookahead, __tokens, __sym0));
|
||||||
}
|
}
|
||||||
Some(__tok @ Tok::LParen(..)) => {
|
Some(__tok @ Tok::LParen(..)) => {
|
||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
@ -77,15 +77,15 @@ mod __parse__S {
|
|||||||
match __nt {
|
match __nt {
|
||||||
__Nonterminal::S(__nt) => {
|
__Nonterminal::S(__nt) => {
|
||||||
let __sym0 = &mut Some(__nt);
|
let __sym0 = &mut Some(__nt);
|
||||||
__result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym0));
|
__result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym0));
|
||||||
}
|
|
||||||
__Nonterminal::E(__nt) => {
|
|
||||||
let __sym0 = &mut Some(__nt);
|
|
||||||
__result = try!(__state1(__lookbehind, __lookahead, __tokens, __sym0));
|
|
||||||
}
|
}
|
||||||
__Nonterminal::T(__nt) => {
|
__Nonterminal::T(__nt) => {
|
||||||
let __sym0 = &mut Some(__nt);
|
let __sym0 = &mut Some(__nt);
|
||||||
__result = try!(__state5(__lookbehind, __lookahead, __tokens, __sym0));
|
__result = try!(__state1(__lookbehind, __lookahead, __tokens, __sym0));
|
||||||
|
}
|
||||||
|
__Nonterminal::E(__nt) => {
|
||||||
|
let __sym0 = &mut Some(__nt);
|
||||||
|
__result = try!(__state3(__lookbehind, __lookahead, __tokens, __sym0));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Ok((__lookbehind, __lookahead, __nt));
|
return Ok((__lookbehind, __lookahead, __nt));
|
||||||
@ -95,14 +95,75 @@ mod __parse__S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// State 1
|
// State 1
|
||||||
|
// E = T (*) [EOF]
|
||||||
|
// E = T (*) ["-"]
|
||||||
|
//
|
||||||
|
// "-" -> Reduce(E = T => Call(ActionFn(3));)
|
||||||
|
// EOF -> Reduce(E = T => Call(ActionFn(3));)
|
||||||
|
//
|
||||||
|
pub fn __state1<
|
||||||
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
|
>(
|
||||||
|
__lookbehind: Option<()>,
|
||||||
|
__lookahead: Option<Tok>,
|
||||||
|
__tokens: &mut __TOKENS,
|
||||||
|
__sym0: &mut Option<i32>,
|
||||||
|
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
||||||
|
{
|
||||||
|
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
||||||
|
match __lookahead {
|
||||||
|
Some(Tok::Minus(..)) => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action3(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action3(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(__lookahead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// State 2
|
||||||
|
// __S = S (*) [EOF]
|
||||||
|
//
|
||||||
|
// EOF -> Reduce(__S = S => Call(ActionFn(0));)
|
||||||
|
//
|
||||||
|
pub fn __state2<
|
||||||
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
|
>(
|
||||||
|
__lookbehind: Option<()>,
|
||||||
|
__lookahead: Option<Tok>,
|
||||||
|
__tokens: &mut __TOKENS,
|
||||||
|
__sym0: &mut Option<i32>,
|
||||||
|
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
||||||
|
{
|
||||||
|
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
||||||
|
match __lookahead {
|
||||||
|
None => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action0(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::____S(__nt)));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(__lookahead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// State 3
|
||||||
// E = E (*) "-" T [EOF]
|
// E = E (*) "-" T [EOF]
|
||||||
// E = E (*) "-" T ["-"]
|
// E = E (*) "-" T ["-"]
|
||||||
// S = E (*) [EOF]
|
// S = E (*) [EOF]
|
||||||
//
|
//
|
||||||
// "-" -> Shift(S6)
|
|
||||||
// EOF -> Reduce(S = E => Call(ActionFn(1));)
|
// EOF -> Reduce(S = E => Call(ActionFn(1));)
|
||||||
|
// "-" -> Shift(S6)
|
||||||
//
|
//
|
||||||
pub fn __state1<
|
pub fn __state3<
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
>(
|
>(
|
||||||
__lookbehind: Option<()>,
|
__lookbehind: Option<()>,
|
||||||
@ -121,7 +182,7 @@ mod __parse__S {
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __nt = super::__actions::__action1(__sym0);
|
let __nt = super::__action1(__sym0);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::S(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::S(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -131,67 +192,6 @@ mod __parse__S {
|
|||||||
return Ok(__result);
|
return Ok(__result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// State 2
|
|
||||||
// T = "Num" (*) [EOF]
|
|
||||||
// T = "Num" (*) ["-"]
|
|
||||||
//
|
|
||||||
// "-" -> Reduce(T = "Num" => Call(ActionFn(4));)
|
|
||||||
// EOF -> Reduce(T = "Num" => Call(ActionFn(4));)
|
|
||||||
//
|
|
||||||
pub fn __state2<
|
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
|
||||||
>(
|
|
||||||
__lookbehind: Option<()>,
|
|
||||||
__lookahead: Option<Tok>,
|
|
||||||
__tokens: &mut __TOKENS,
|
|
||||||
__sym0: &mut Option<i32>,
|
|
||||||
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
|
||||||
{
|
|
||||||
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
|
||||||
match __lookahead {
|
|
||||||
Some(Tok::Minus(..)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action4(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action4(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(__lookahead);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// State 3
|
|
||||||
// __S = S (*) [EOF]
|
|
||||||
//
|
|
||||||
// EOF -> Reduce(__S = S => Call(ActionFn(0));)
|
|
||||||
//
|
|
||||||
pub fn __state3<
|
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
|
||||||
>(
|
|
||||||
__lookbehind: Option<()>,
|
|
||||||
__lookahead: Option<Tok>,
|
|
||||||
__tokens: &mut __TOKENS,
|
|
||||||
__sym0: &mut Option<i32>,
|
|
||||||
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
|
||||||
{
|
|
||||||
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
|
||||||
match __lookahead {
|
|
||||||
None => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action0(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::____S(__nt)));
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(__lookahead);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// State 4
|
// State 4
|
||||||
// E = (*) E "-" T [")"]
|
// E = (*) E "-" T [")"]
|
||||||
// E = (*) E "-" T ["-"]
|
// E = (*) E "-" T ["-"]
|
||||||
@ -204,11 +204,11 @@ mod __parse__S {
|
|||||||
// T = (*) "Num" [")"]
|
// T = (*) "Num" [")"]
|
||||||
// T = (*) "Num" ["-"]
|
// T = (*) "Num" ["-"]
|
||||||
//
|
//
|
||||||
// "Num" -> Shift(S9)
|
// "Num" -> Shift(S10)
|
||||||
// "(" -> Shift(S10)
|
// "(" -> Shift(S9)
|
||||||
//
|
//
|
||||||
// E -> S7
|
// E -> S8
|
||||||
// T -> S8
|
// T -> S7
|
||||||
pub fn __state4<
|
pub fn __state4<
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
>(
|
>(
|
||||||
@ -224,13 +224,13 @@ mod __parse__S {
|
|||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym1 = &mut Some((__tok0));
|
let mut __sym1 = &mut Some((__tok0));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym1));
|
__result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym1));
|
||||||
}
|
}
|
||||||
Some(__tok @ Tok::LParen(..)) => {
|
Some(__tok @ Tok::LParen(..)) => {
|
||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym1 = &mut Some((__tok));
|
let mut __sym1 = &mut Some((__tok));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym1));
|
__result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym1));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(__lookahead);
|
return Err(__lookahead);
|
||||||
@ -241,11 +241,11 @@ mod __parse__S {
|
|||||||
match __nt {
|
match __nt {
|
||||||
__Nonterminal::E(__nt) => {
|
__Nonterminal::E(__nt) => {
|
||||||
let __sym1 = &mut Some(__nt);
|
let __sym1 = &mut Some(__nt);
|
||||||
__result = try!(__state7(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
__result = try!(__state8(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||||
}
|
}
|
||||||
__Nonterminal::T(__nt) => {
|
__Nonterminal::T(__nt) => {
|
||||||
let __sym1 = &mut Some(__nt);
|
let __sym1 = &mut Some(__nt);
|
||||||
__result = try!(__state8(__lookbehind, __lookahead, __tokens, __sym1));
|
__result = try!(__state7(__lookbehind, __lookahead, __tokens, __sym1));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Ok((__lookbehind, __lookahead, __nt));
|
return Ok((__lookbehind, __lookahead, __nt));
|
||||||
@ -256,11 +256,11 @@ mod __parse__S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// State 5
|
// State 5
|
||||||
// E = T (*) [EOF]
|
// T = "Num" (*) [EOF]
|
||||||
// E = T (*) ["-"]
|
// T = "Num" (*) ["-"]
|
||||||
//
|
//
|
||||||
// "-" -> Reduce(E = T => Call(ActionFn(3));)
|
// EOF -> Reduce(T = "Num" => Call(ActionFn(4));)
|
||||||
// EOF -> Reduce(E = T => Call(ActionFn(3));)
|
// "-" -> Reduce(T = "Num" => Call(ActionFn(4));)
|
||||||
//
|
//
|
||||||
pub fn __state5<
|
pub fn __state5<
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
@ -273,15 +273,15 @@ mod __parse__S {
|
|||||||
{
|
{
|
||||||
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
||||||
match __lookahead {
|
match __lookahead {
|
||||||
Some(Tok::Minus(..)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action3(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
|
||||||
}
|
|
||||||
None => {
|
None => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __nt = super::__actions::__action3(__sym0);
|
let __nt = super::__action4(__sym0);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
|
}
|
||||||
|
Some(Tok::Minus(..)) => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action4(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(__lookahead);
|
return Err(__lookahead);
|
||||||
@ -298,7 +298,7 @@ mod __parse__S {
|
|||||||
// T = (*) "Num" ["-"]
|
// T = (*) "Num" ["-"]
|
||||||
//
|
//
|
||||||
// "(" -> Shift(S4)
|
// "(" -> Shift(S4)
|
||||||
// "Num" -> Shift(S2)
|
// "Num" -> Shift(S5)
|
||||||
//
|
//
|
||||||
// T -> S11
|
// T -> S11
|
||||||
pub fn __state6<
|
pub fn __state6<
|
||||||
@ -323,7 +323,7 @@ mod __parse__S {
|
|||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym2 = &mut Some((__tok0));
|
let mut __sym2 = &mut Some((__tok0));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state2(__lookbehind, __lookahead, __tokens, __sym2));
|
__result = try!(__state5(__lookbehind, __lookahead, __tokens, __sym2));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(__lookahead);
|
return Err(__lookahead);
|
||||||
@ -345,6 +345,40 @@ mod __parse__S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// State 7
|
// State 7
|
||||||
|
// E = T (*) [")"]
|
||||||
|
// E = T (*) ["-"]
|
||||||
|
//
|
||||||
|
// "-" -> Reduce(E = T => Call(ActionFn(3));)
|
||||||
|
// ")" -> Reduce(E = T => Call(ActionFn(3));)
|
||||||
|
//
|
||||||
|
pub fn __state7<
|
||||||
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
|
>(
|
||||||
|
__lookbehind: Option<()>,
|
||||||
|
__lookahead: Option<Tok>,
|
||||||
|
__tokens: &mut __TOKENS,
|
||||||
|
__sym0: &mut Option<i32>,
|
||||||
|
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
||||||
|
{
|
||||||
|
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
||||||
|
match __lookahead {
|
||||||
|
Some(Tok::Minus(..)) => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action3(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
||||||
|
}
|
||||||
|
Some(Tok::RParen(..)) => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action3(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(__lookahead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// State 8
|
||||||
// E = E (*) "-" T [")"]
|
// E = E (*) "-" T [")"]
|
||||||
// E = E (*) "-" T ["-"]
|
// E = E (*) "-" T ["-"]
|
||||||
// T = "(" E (*) ")" [EOF]
|
// T = "(" E (*) ")" [EOF]
|
||||||
@ -353,7 +387,7 @@ mod __parse__S {
|
|||||||
// "-" -> Shift(S12)
|
// "-" -> Shift(S12)
|
||||||
// ")" -> Shift(S13)
|
// ")" -> Shift(S13)
|
||||||
//
|
//
|
||||||
pub fn __state7<
|
pub fn __state8<
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
>(
|
>(
|
||||||
__lookbehind: Option<()>,
|
__lookbehind: Option<()>,
|
||||||
@ -384,75 +418,7 @@ mod __parse__S {
|
|||||||
return Ok(__result);
|
return Ok(__result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// State 8
|
|
||||||
// E = T (*) [")"]
|
|
||||||
// E = T (*) ["-"]
|
|
||||||
//
|
|
||||||
// "-" -> Reduce(E = T => Call(ActionFn(3));)
|
|
||||||
// ")" -> Reduce(E = T => Call(ActionFn(3));)
|
|
||||||
//
|
|
||||||
pub fn __state8<
|
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
|
||||||
>(
|
|
||||||
__lookbehind: Option<()>,
|
|
||||||
__lookahead: Option<Tok>,
|
|
||||||
__tokens: &mut __TOKENS,
|
|
||||||
__sym0: &mut Option<i32>,
|
|
||||||
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
|
||||||
{
|
|
||||||
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
|
||||||
match __lookahead {
|
|
||||||
Some(Tok::Minus(..)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action3(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
|
||||||
}
|
|
||||||
Some(Tok::RParen(..)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action3(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(__lookahead);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// State 9
|
// State 9
|
||||||
// T = "Num" (*) [")"]
|
|
||||||
// T = "Num" (*) ["-"]
|
|
||||||
//
|
|
||||||
// ")" -> Reduce(T = "Num" => Call(ActionFn(4));)
|
|
||||||
// "-" -> Reduce(T = "Num" => Call(ActionFn(4));)
|
|
||||||
//
|
|
||||||
pub fn __state9<
|
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
|
||||||
>(
|
|
||||||
__lookbehind: Option<()>,
|
|
||||||
__lookahead: Option<Tok>,
|
|
||||||
__tokens: &mut __TOKENS,
|
|
||||||
__sym0: &mut Option<i32>,
|
|
||||||
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
|
||||||
{
|
|
||||||
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
|
||||||
match __lookahead {
|
|
||||||
Some(Tok::RParen(..)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action4(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
|
||||||
}
|
|
||||||
Some(Tok::Minus(..)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action4(__sym0);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(__lookahead);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// State 10
|
|
||||||
// E = (*) E "-" T [")"]
|
// E = (*) E "-" T [")"]
|
||||||
// E = (*) E "-" T ["-"]
|
// E = (*) E "-" T ["-"]
|
||||||
// E = (*) T [")"]
|
// E = (*) T [")"]
|
||||||
@ -464,12 +430,12 @@ mod __parse__S {
|
|||||||
// T = (*) "Num" [")"]
|
// T = (*) "Num" [")"]
|
||||||
// T = (*) "Num" ["-"]
|
// T = (*) "Num" ["-"]
|
||||||
//
|
//
|
||||||
// "(" -> Shift(S10)
|
// "(" -> Shift(S9)
|
||||||
// "Num" -> Shift(S9)
|
// "Num" -> Shift(S10)
|
||||||
//
|
//
|
||||||
// T -> S8
|
|
||||||
// E -> S14
|
// E -> S14
|
||||||
pub fn __state10<
|
// T -> S7
|
||||||
|
pub fn __state9<
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
>(
|
>(
|
||||||
__lookbehind: Option<()>,
|
__lookbehind: Option<()>,
|
||||||
@ -484,13 +450,13 @@ mod __parse__S {
|
|||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym1 = &mut Some((__tok));
|
let mut __sym1 = &mut Some((__tok));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym1));
|
__result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym1));
|
||||||
}
|
}
|
||||||
Some(Tok::Num(__tok0)) => {
|
Some(Tok::Num(__tok0)) => {
|
||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym1 = &mut Some((__tok0));
|
let mut __sym1 = &mut Some((__tok0));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym1));
|
__result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym1));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(__lookahead);
|
return Err(__lookahead);
|
||||||
@ -499,14 +465,14 @@ mod __parse__S {
|
|||||||
while __sym0.is_some() {
|
while __sym0.is_some() {
|
||||||
let (__lookbehind, __lookahead, __nt) = __result;
|
let (__lookbehind, __lookahead, __nt) = __result;
|
||||||
match __nt {
|
match __nt {
|
||||||
__Nonterminal::T(__nt) => {
|
|
||||||
let __sym1 = &mut Some(__nt);
|
|
||||||
__result = try!(__state8(__lookbehind, __lookahead, __tokens, __sym1));
|
|
||||||
}
|
|
||||||
__Nonterminal::E(__nt) => {
|
__Nonterminal::E(__nt) => {
|
||||||
let __sym1 = &mut Some(__nt);
|
let __sym1 = &mut Some(__nt);
|
||||||
__result = try!(__state14(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
__result = try!(__state14(__lookbehind, __lookahead, __tokens, __sym0, __sym1));
|
||||||
}
|
}
|
||||||
|
__Nonterminal::T(__nt) => {
|
||||||
|
let __sym1 = &mut Some(__nt);
|
||||||
|
__result = try!(__state7(__lookbehind, __lookahead, __tokens, __sym1));
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Ok((__lookbehind, __lookahead, __nt));
|
return Ok((__lookbehind, __lookahead, __nt));
|
||||||
}
|
}
|
||||||
@ -515,6 +481,40 @@ mod __parse__S {
|
|||||||
return Ok(__result);
|
return Ok(__result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// State 10
|
||||||
|
// T = "Num" (*) [")"]
|
||||||
|
// T = "Num" (*) ["-"]
|
||||||
|
//
|
||||||
|
// "-" -> Reduce(T = "Num" => Call(ActionFn(4));)
|
||||||
|
// ")" -> Reduce(T = "Num" => Call(ActionFn(4));)
|
||||||
|
//
|
||||||
|
pub fn __state10<
|
||||||
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
|
>(
|
||||||
|
__lookbehind: Option<()>,
|
||||||
|
__lookahead: Option<Tok>,
|
||||||
|
__tokens: &mut __TOKENS,
|
||||||
|
__sym0: &mut Option<i32>,
|
||||||
|
) -> Result<(Option<()>, Option<Tok>, __Nonterminal<>), Option<Tok>>
|
||||||
|
{
|
||||||
|
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
||||||
|
match __lookahead {
|
||||||
|
Some(Tok::Minus(..)) => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action4(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
|
}
|
||||||
|
Some(Tok::RParen(..)) => {
|
||||||
|
let __sym0 = __sym0.take().unwrap();
|
||||||
|
let __nt = super::__action4(__sym0);
|
||||||
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(__lookahead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// State 11
|
// State 11
|
||||||
// E = E "-" T (*) [EOF]
|
// E = E "-" T (*) [EOF]
|
||||||
// E = E "-" T (*) ["-"]
|
// E = E "-" T (*) ["-"]
|
||||||
@ -539,14 +539,14 @@ mod __parse__S {
|
|||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action2(__sym0, __sym1, __sym2);
|
let __nt = super::__action2(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action2(__sym0, __sym1, __sym2);
|
let __nt = super::__action2(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -563,8 +563,8 @@ mod __parse__S {
|
|||||||
// T = (*) "Num" [")"]
|
// T = (*) "Num" [")"]
|
||||||
// T = (*) "Num" ["-"]
|
// T = (*) "Num" ["-"]
|
||||||
//
|
//
|
||||||
// "Num" -> Shift(S9)
|
// "Num" -> Shift(S10)
|
||||||
// "(" -> Shift(S10)
|
// "(" -> Shift(S9)
|
||||||
//
|
//
|
||||||
// T -> S15
|
// T -> S15
|
||||||
pub fn __state12<
|
pub fn __state12<
|
||||||
@ -583,13 +583,13 @@ mod __parse__S {
|
|||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym2 = &mut Some((__tok0));
|
let mut __sym2 = &mut Some((__tok0));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym2));
|
__result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym2));
|
||||||
}
|
}
|
||||||
Some(__tok @ Tok::LParen(..)) => {
|
Some(__tok @ Tok::LParen(..)) => {
|
||||||
let mut __lookbehind = None;
|
let mut __lookbehind = None;
|
||||||
let mut __sym2 = &mut Some((__tok));
|
let mut __sym2 = &mut Some((__tok));
|
||||||
let __lookahead = __tokens.next();
|
let __lookahead = __tokens.next();
|
||||||
__result = try!(__state10(__lookbehind, __lookahead, __tokens, __sym2));
|
__result = try!(__state9(__lookbehind, __lookahead, __tokens, __sym2));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(__lookahead);
|
return Err(__lookahead);
|
||||||
@ -634,14 +634,14 @@ mod __parse__S {
|
|||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action5(__sym0, __sym1, __sym2);
|
let __nt = super::__action5(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action5(__sym0, __sym1, __sym2);
|
let __nt = super::__action5(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -694,8 +694,8 @@ mod __parse__S {
|
|||||||
// E = E "-" T (*) [")"]
|
// E = E "-" T (*) [")"]
|
||||||
// E = E "-" T (*) ["-"]
|
// E = E "-" T (*) ["-"]
|
||||||
//
|
//
|
||||||
// "-" -> Reduce(E = E, "-", T => Call(ActionFn(2));)
|
|
||||||
// ")" -> Reduce(E = E, "-", T => Call(ActionFn(2));)
|
// ")" -> Reduce(E = E, "-", T => Call(ActionFn(2));)
|
||||||
|
// "-" -> Reduce(E = E, "-", T => Call(ActionFn(2));)
|
||||||
//
|
//
|
||||||
pub fn __state15<
|
pub fn __state15<
|
||||||
__TOKENS: Iterator<Item=Tok>,
|
__TOKENS: Iterator<Item=Tok>,
|
||||||
@ -710,18 +710,18 @@ mod __parse__S {
|
|||||||
{
|
{
|
||||||
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
let mut __result: (Option<()>, Option<Tok>, __Nonterminal<>);
|
||||||
match __lookahead {
|
match __lookahead {
|
||||||
Some(Tok::Minus(..)) => {
|
|
||||||
let __sym0 = __sym0.take().unwrap();
|
|
||||||
let __sym1 = __sym1.take().unwrap();
|
|
||||||
let __sym2 = __sym2.take().unwrap();
|
|
||||||
let __nt = super::__actions::__action2(__sym0, __sym1, __sym2);
|
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
|
||||||
}
|
|
||||||
Some(Tok::RParen(..)) => {
|
Some(Tok::RParen(..)) => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action2(__sym0, __sym1, __sym2);
|
let __nt = super::__action2(__sym0, __sym1, __sym2);
|
||||||
|
return Ok((__lookbehind, __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((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::E(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -754,14 +754,14 @@ mod __parse__S {
|
|||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action5(__sym0, __sym1, __sym2);
|
let __nt = super::__action5(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
}
|
}
|
||||||
Some(Tok::RParen(..)) => {
|
Some(Tok::RParen(..)) => {
|
||||||
let __sym0 = __sym0.take().unwrap();
|
let __sym0 = __sym0.take().unwrap();
|
||||||
let __sym1 = __sym1.take().unwrap();
|
let __sym1 = __sym1.take().unwrap();
|
||||||
let __sym2 = __sym2.take().unwrap();
|
let __sym2 = __sym2.take().unwrap();
|
||||||
let __nt = super::__actions::__action5(__sym0, __sym1, __sym2);
|
let __nt = super::__action5(__sym0, __sym1, __sym2);
|
||||||
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
return Ok((__lookbehind, __lookahead, __Nonterminal::T(__nt)));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -771,59 +771,54 @@ mod __parse__S {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod __actions {
|
pub fn __action0<
|
||||||
use util::tok::Tok;
|
>(
|
||||||
|
__0: i32,
|
||||||
|
) -> i32
|
||||||
pub fn __action0<
|
{
|
||||||
>(
|
(__0)
|
||||||
__0: i32,
|
}
|
||||||
) -> i32
|
|
||||||
{
|
pub fn __action1<
|
||||||
(__0)
|
>(
|
||||||
}
|
__0: i32,
|
||||||
|
) -> i32
|
||||||
pub fn __action1<
|
{
|
||||||
>(
|
(__0)
|
||||||
__0: i32,
|
}
|
||||||
) -> i32
|
|
||||||
{
|
pub fn __action2<
|
||||||
(__0)
|
>(
|
||||||
}
|
l: i32,
|
||||||
|
_: Tok,
|
||||||
pub fn __action2<
|
r: i32,
|
||||||
>(
|
) -> i32
|
||||||
l: i32,
|
{
|
||||||
_: Tok,
|
l - r
|
||||||
r: i32,
|
}
|
||||||
) -> i32
|
|
||||||
{
|
pub fn __action3<
|
||||||
l-r
|
>(
|
||||||
}
|
t: i32,
|
||||||
|
) -> i32
|
||||||
pub fn __action3<
|
{
|
||||||
>(
|
t - super::ZERO
|
||||||
__0: i32,
|
}
|
||||||
) -> i32
|
|
||||||
{
|
pub fn __action4<
|
||||||
(__0)
|
>(
|
||||||
}
|
__0: i32,
|
||||||
|
) -> i32
|
||||||
pub fn __action4<
|
{
|
||||||
>(
|
(__0)
|
||||||
__0: i32,
|
}
|
||||||
) -> i32
|
|
||||||
{
|
pub fn __action5<
|
||||||
(__0)
|
>(
|
||||||
}
|
_: Tok,
|
||||||
|
__0: i32,
|
||||||
pub fn __action5<
|
_: Tok,
|
||||||
>(
|
) -> i32
|
||||||
_: Tok,
|
{
|
||||||
__0: i32,
|
(__0)
|
||||||
_: Tok,
|
|
||||||
) -> i32
|
|
||||||
{
|
|
||||||
(__0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -95,12 +95,32 @@ fn emit_uses<W:Write>(grammar: &r::Grammar,
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_action_code<W:Write>(grammar: &r::Grammar,
|
fn emit_recursive_ascent(output_path: &Path, grammar: &r::Grammar) -> io::Result<()>
|
||||||
rust: &mut RustWrite<W>)
|
|
||||||
-> io::Result<()>
|
|
||||||
{
|
{
|
||||||
rust!(rust, "");
|
let output_file = try!(fs::File::create(output_path));
|
||||||
rust!(rust, "mod {}actions {{", grammar.prefix);
|
let mut rust = RustWrite::new(output_file);
|
||||||
|
|
||||||
|
// We generate a module structure like this:
|
||||||
|
//
|
||||||
|
// ```
|
||||||
|
// mod <output-file> {
|
||||||
|
// // For each public symbol:
|
||||||
|
// pub fn parse_XYZ();
|
||||||
|
// mod __XYZ { ... }
|
||||||
|
//
|
||||||
|
// // For each bit of action code:
|
||||||
|
// <action-code>
|
||||||
|
// }
|
||||||
|
// ```
|
||||||
|
//
|
||||||
|
// Note that the action code goes in the outer module. This is
|
||||||
|
// intentional because it means that the foo.lalrpop file serves
|
||||||
|
// as a module in the rust hierarchy, so if the action code
|
||||||
|
// includes things like `super::` it will resolve in the natural
|
||||||
|
// way.
|
||||||
|
|
||||||
|
// often some of the uses are not used here
|
||||||
|
rust!(rust, "#![allow(unused_imports)]");
|
||||||
|
|
||||||
// we always thread the parameters through to the action code,
|
// we always thread the parameters through to the action code,
|
||||||
// even if they are not used, and hence we need to disable the
|
// even if they are not used, and hence we need to disable the
|
||||||
@ -109,35 +129,6 @@ fn emit_action_code<W:Write>(grammar: &r::Grammar,
|
|||||||
rust!(rust, "#![allow(unused_variables)]");
|
rust!(rust, "#![allow(unused_variables)]");
|
||||||
}
|
}
|
||||||
|
|
||||||
try!(emit_uses(grammar, rust));
|
|
||||||
for (i, defn) in grammar.action_fn_defns.iter().enumerate() {
|
|
||||||
rust!(rust, "");
|
|
||||||
try!(rust.write_pub_fn_header(
|
|
||||||
grammar,
|
|
||||||
format!("{}action{}", grammar.prefix, i),
|
|
||||||
vec![],
|
|
||||||
defn.arg_patterns.iter()
|
|
||||||
.zip(defn.arg_types.iter())
|
|
||||||
.map(|(p, t)| format!("{}: {}", p, t))
|
|
||||||
.collect(),
|
|
||||||
format!("{}", defn.ret_type),
|
|
||||||
vec![]));
|
|
||||||
rust!(rust, "{{");
|
|
||||||
rust!(rust, "{}", defn.code);
|
|
||||||
rust!(rust, "}}");
|
|
||||||
}
|
|
||||||
rust!(rust, "}}");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn emit_recursive_ascent(output_path: &Path, grammar: &r::Grammar) -> io::Result<()>
|
|
||||||
{
|
|
||||||
let output_file = try!(fs::File::create(output_path));
|
|
||||||
let mut rust = RustWrite::new(output_file);
|
|
||||||
|
|
||||||
// often some of the uses are not used here
|
|
||||||
rust!(rust, "#![allow(unused_imports)]");
|
|
||||||
|
|
||||||
try!(emit_uses(grammar, &mut rust));
|
try!(emit_uses(grammar, &mut rust));
|
||||||
|
|
||||||
if grammar.start_nonterminals.is_empty() {
|
if grammar.start_nonterminals.is_empty() {
|
||||||
@ -165,3 +156,27 @@ fn emit_recursive_ascent(output_path: &Path, grammar: &r::Grammar) -> io::Result
|
|||||||
try!(emit_action_code(grammar, &mut rust));
|
try!(emit_action_code(grammar, &mut rust));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn emit_action_code<W:Write>(grammar: &r::Grammar,
|
||||||
|
rust: &mut RustWrite<W>)
|
||||||
|
-> io::Result<()>
|
||||||
|
{
|
||||||
|
for (i, defn) in grammar.action_fn_defns.iter().enumerate() {
|
||||||
|
rust!(rust, "");
|
||||||
|
try!(rust.write_pub_fn_header(
|
||||||
|
grammar,
|
||||||
|
format!("{}action{}", grammar.prefix, i),
|
||||||
|
vec![],
|
||||||
|
defn.arg_patterns.iter()
|
||||||
|
.zip(defn.arg_types.iter())
|
||||||
|
.map(|(p, t)| format!("{}: {}", p, t))
|
||||||
|
.collect(),
|
||||||
|
format!("{}", defn.ret_type),
|
||||||
|
vec![]));
|
||||||
|
rust!(rust, "{{");
|
||||||
|
rust!(rust, "{}", defn.code);
|
||||||
|
rust!(rust, "}}");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -239,8 +239,7 @@ impl<'ascent,'grammar,W:Write> RecursiveAscent<'ascent,'grammar,W> {
|
|||||||
// invoke the action code
|
// invoke the action code
|
||||||
match production.action {
|
match production.action {
|
||||||
ActionKind::Call(action_fn) => {
|
ActionKind::Call(action_fn) => {
|
||||||
rust!(self.out, "let {}nt = super::{}actions::{}action{}({}{});",
|
rust!(self.out, "let {}nt = super::{}action{}({}{});",
|
||||||
self.prefix,
|
|
||||||
self.prefix,
|
self.prefix,
|
||||||
self.prefix,
|
self.prefix,
|
||||||
action_fn.index(),
|
action_fn.index(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user