mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-16 17:00:53 +00:00
patch up the macro expansion test case now that * and ? are inlined
This commit is contained in:
parent
f125c75926
commit
63c9c2efc9
File diff suppressed because it is too large
Load Diff
@ -40,22 +40,24 @@ mod __parse__Expr {
|
||||
pub enum __Nonterminal<'input> {
|
||||
Expr(Vec<&'input str>),
|
||||
Other_2a(::std::vec::Vec<&'input str>),
|
||||
Other_2b(::std::vec::Vec<&'input str>),
|
||||
____Expr(Vec<&'input str>),
|
||||
}
|
||||
|
||||
// State 0
|
||||
// Expr = (*) Other* [EOF]
|
||||
// Other* = (*) [EOF]
|
||||
// Other* = (*) [Other]
|
||||
// Other* = (*) Other* Other [EOF]
|
||||
// Other* = (*) Other* Other [Other]
|
||||
// Expr = (*) [EOF]
|
||||
// Expr = (*) Other+ [EOF]
|
||||
// Other+ = (*) Other+ Other [EOF]
|
||||
// Other+ = (*) Other+ Other [Other]
|
||||
// Other+ = (*) Other [EOF]
|
||||
// Other+ = (*) Other [Other]
|
||||
// __Expr = (*) Expr [EOF]
|
||||
//
|
||||
// EOF -> Reduce(Other* = => ActionFn(2);)
|
||||
// Other -> Reduce(Other* = => ActionFn(2);)
|
||||
// EOF -> Reduce(Expr = => ActionFn(6);)
|
||||
// Other -> Shift(S3)
|
||||
//
|
||||
// Expr -> S1
|
||||
// Other* -> S2
|
||||
// Other+ -> S2
|
||||
pub fn __state0<
|
||||
'input,
|
||||
__TOKENS: Iterator<Item=Result<((), LtTok<'input>, ()),()>>,
|
||||
@ -67,10 +69,14 @@ mod __parse__Expr {
|
||||
{
|
||||
let mut __result: (Option<()>, Option<((), LtTok<'input>, ())>, __Nonterminal<'input>);
|
||||
match __lookahead {
|
||||
None |
|
||||
Some((_, LtTok::Other(_), _)) => {
|
||||
let __nt = super::__action2(&__lookbehind, &__lookahead);
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::Other_2a(__nt));
|
||||
Some((_, LtTok::Other(__tok0), __loc)) => {
|
||||
let mut __lookbehind = Some(__loc);
|
||||
let mut __sym0 = &mut Some((__tok0));
|
||||
__result = try!(__state3(__lookbehind, __tokens, __sym0));
|
||||
}
|
||||
None => {
|
||||
let __nt = super::__action6(&__lookbehind, &__lookahead);
|
||||
__result = (__lookbehind, __lookahead, __Nonterminal::Expr(__nt));
|
||||
}
|
||||
_ => {
|
||||
return Err(__ParseError::UnrecognizedToken {
|
||||
@ -86,7 +92,7 @@ mod __parse__Expr {
|
||||
let __sym0 = &mut Some(__nt);
|
||||
__result = try!(__state1(__lookbehind, __tokens, __lookahead, __sym0));
|
||||
}
|
||||
__Nonterminal::Other_2a(__nt) => {
|
||||
__Nonterminal::Other_2b(__nt) => {
|
||||
let __sym0 = &mut Some(__nt);
|
||||
__result = try!(__state2(__lookbehind, __tokens, __lookahead, __sym0));
|
||||
}
|
||||
@ -129,12 +135,12 @@ mod __parse__Expr {
|
||||
}
|
||||
|
||||
// State 2
|
||||
// Expr = Other* (*) [EOF]
|
||||
// Other* = Other* (*) Other [EOF]
|
||||
// Other* = Other* (*) Other [Other]
|
||||
// Expr = Other+ (*) [EOF]
|
||||
// Other+ = Other+ (*) Other [EOF]
|
||||
// Other+ = Other+ (*) Other [Other]
|
||||
//
|
||||
// EOF -> Reduce(Expr = Other* => ActionFn(1);)
|
||||
// Other -> Shift(S3)
|
||||
// EOF -> Reduce(Expr = Other+ => ActionFn(7);)
|
||||
// Other -> Shift(S4)
|
||||
//
|
||||
pub fn __state2<
|
||||
'input,
|
||||
@ -151,11 +157,11 @@ mod __parse__Expr {
|
||||
Some((_, LtTok::Other(__tok0), __loc)) => {
|
||||
let mut __lookbehind = Some(__loc);
|
||||
let mut __sym1 = &mut Some((__tok0));
|
||||
__result = try!(__state3(__lookbehind, __tokens, __sym0, __sym1));
|
||||
__result = try!(__state4(__lookbehind, __tokens, __sym0, __sym1));
|
||||
}
|
||||
None => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __nt = super::__action1(__sym0, &__lookbehind, &__lookahead);
|
||||
let __nt = super::__action7(__sym0, &__lookbehind, &__lookahead);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt)));
|
||||
}
|
||||
_ => {
|
||||
@ -169,15 +175,53 @@ mod __parse__Expr {
|
||||
}
|
||||
|
||||
// State 3
|
||||
// Other* = Other* Other (*) [EOF]
|
||||
// Other* = Other* Other (*) [Other]
|
||||
// Other+ = Other (*) [EOF]
|
||||
// Other+ = Other (*) [Other]
|
||||
//
|
||||
// EOF -> Reduce(Other* = Other*, Other => ActionFn(3);)
|
||||
// Other -> Reduce(Other* = Other*, Other => ActionFn(3);)
|
||||
// EOF -> Reduce(Other+ = Other => ActionFn(4);)
|
||||
// Other -> Reduce(Other+ = Other => ActionFn(4);)
|
||||
//
|
||||
pub fn __state3<
|
||||
'input,
|
||||
__TOKENS: Iterator<Item=Result<((), LtTok<'input>, ()),()>>,
|
||||
>(
|
||||
__lookbehind: Option<()>,
|
||||
__tokens: &mut __TOKENS,
|
||||
__sym0: &mut Option<&'input str>,
|
||||
) -> Result<(Option<()>, Option<((), LtTok<'input>, ())>, __Nonterminal<'input>), __ParseError<(),LtTok<'input>,()>>
|
||||
{
|
||||
let mut __result: (Option<()>, Option<((), LtTok<'input>, ())>, __Nonterminal<'input>);
|
||||
let __lookahead = match __tokens.next() {
|
||||
Some(Ok(v)) => Some(v),
|
||||
None => None,
|
||||
Some(Err(e)) => return Err(__ParseError::User { error: e }),
|
||||
};
|
||||
match __lookahead {
|
||||
None |
|
||||
Some((_, LtTok::Other(_), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __nt = super::__action4(__sym0, &__lookbehind, &__lookahead);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Other_2b(__nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(__ParseError::UnrecognizedToken {
|
||||
token: __lookahead,
|
||||
expected: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// State 4
|
||||
// Other+ = Other+ Other (*) [EOF]
|
||||
// Other+ = Other+ Other (*) [Other]
|
||||
//
|
||||
// EOF -> Reduce(Other+ = Other+, Other => ActionFn(5);)
|
||||
// Other -> Reduce(Other+ = Other+, Other => ActionFn(5);)
|
||||
//
|
||||
pub fn __state4<
|
||||
'input,
|
||||
__TOKENS: Iterator<Item=Result<((), LtTok<'input>, ()),()>>,
|
||||
>(
|
||||
__lookbehind: Option<()>,
|
||||
__tokens: &mut __TOKENS,
|
||||
@ -196,8 +240,8 @@ mod __parse__Expr {
|
||||
Some((_, LtTok::Other(_), _)) => {
|
||||
let __sym0 = __sym0.take().unwrap();
|
||||
let __sym1 = __sym1.take().unwrap();
|
||||
let __nt = super::__action3(__sym0, __sym1, &__lookbehind, &__lookahead);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Other_2a(__nt)));
|
||||
let __nt = super::__action5(__sym0, __sym1, &__lookbehind, &__lookahead);
|
||||
return Ok((__lookbehind, __lookahead, __Nonterminal::Other_2b(__nt)));
|
||||
}
|
||||
_ => {
|
||||
return Err(__ParseError::UnrecognizedToken {
|
||||
@ -244,6 +288,28 @@ pub fn __action2<
|
||||
|
||||
pub fn __action3<
|
||||
'input,
|
||||
>(
|
||||
v: ::std::vec::Vec<&'input str>,
|
||||
__lookbehind: &Option<()>,
|
||||
__lookahead: &Option<((), LtTok<'input>, ())>,
|
||||
) -> ::std::vec::Vec<&'input str>
|
||||
{
|
||||
v
|
||||
}
|
||||
|
||||
pub fn __action4<
|
||||
'input,
|
||||
>(
|
||||
__0: &'input str,
|
||||
__lookbehind: &Option<()>,
|
||||
__lookahead: &Option<((), LtTok<'input>, ())>,
|
||||
) -> ::std::vec::Vec<&'input str>
|
||||
{
|
||||
vec![__0]
|
||||
}
|
||||
|
||||
pub fn __action5<
|
||||
'input,
|
||||
>(
|
||||
v: ::std::vec::Vec<&'input str>,
|
||||
e: &'input str,
|
||||
@ -254,6 +320,44 @@ pub fn __action3<
|
||||
{ let mut v = v; v.push(e); v }
|
||||
}
|
||||
|
||||
pub fn __action6<
|
||||
'input,
|
||||
>(
|
||||
__lookbehind: &Option<()>,
|
||||
__lookahead: &Option<((), LtTok<'input>, ())>,
|
||||
) -> Vec<&'input str>
|
||||
{
|
||||
let __temp0 = __action2(
|
||||
__lookbehind,
|
||||
__lookahead,
|
||||
);
|
||||
__action1(
|
||||
__temp0,
|
||||
__lookbehind,
|
||||
__lookahead,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn __action7<
|
||||
'input,
|
||||
>(
|
||||
__0: ::std::vec::Vec<&'input str>,
|
||||
__lookbehind: &Option<()>,
|
||||
__lookahead: &Option<((), LtTok<'input>, ())>,
|
||||
) -> Vec<&'input str>
|
||||
{
|
||||
let __temp0 = __action3(
|
||||
__0,
|
||||
__lookbehind,
|
||||
__lookahead,
|
||||
);
|
||||
__action1(
|
||||
__temp0,
|
||||
__lookbehind,
|
||||
__lookahead,
|
||||
)
|
||||
}
|
||||
|
||||
pub trait __ToTriple<'input, > {
|
||||
type Error;
|
||||
fn to_triple(value: Self) -> Result<((),LtTok<'input>,()),Self::Error>;
|
||||
|
@ -362,10 +362,7 @@ impl MacroExpander {
|
||||
public: false,
|
||||
span: span,
|
||||
name: name,
|
||||
annotations: vec![Annotation {
|
||||
id_span: span,
|
||||
id: intern(INLINE),
|
||||
}],
|
||||
annotations: inline(span),
|
||||
args: vec![],
|
||||
type_decl: Some(ty_ref),
|
||||
alternatives: vec![Alternative { span: span,
|
||||
@ -390,11 +387,16 @@ impl MacroExpander {
|
||||
let path = Path::vec();
|
||||
let ty_ref = TypeRef::Nominal { path: path, types: vec![base_symbol_ty] };
|
||||
|
||||
let plus_repeat = Box::new(RepeatSymbol {
|
||||
op: RepeatOp::Plus,
|
||||
symbol: repeat.symbol.clone()
|
||||
});
|
||||
|
||||
Ok(GrammarItem::Nonterminal(NonterminalData {
|
||||
public: false,
|
||||
span: span,
|
||||
name: name,
|
||||
annotations: vec![],
|
||||
annotations: inline(span),
|
||||
args: vec![],
|
||||
type_decl: Some(ty_ref),
|
||||
alternatives: vec![
|
||||
@ -406,7 +408,7 @@ impl MacroExpander {
|
||||
action: action("vec![]")
|
||||
},
|
||||
|
||||
// X* = <v:X+> <e:X>
|
||||
// X* = <v:X+>
|
||||
Alternative {
|
||||
span: span,
|
||||
expr: ExprSymbol {
|
||||
@ -417,15 +419,10 @@ impl MacroExpander {
|
||||
v,
|
||||
Box::new(
|
||||
Symbol::new(span,
|
||||
SymbolKind::Nonterminal(name))))),
|
||||
Symbol::new(
|
||||
span,
|
||||
SymbolKind::Name(
|
||||
e,
|
||||
Box::new(repeat.symbol.clone())))]
|
||||
SymbolKind::Repeat(plus_repeat)))))],
|
||||
},
|
||||
condition: None,
|
||||
action: action("{ let mut v = v; v.push(e); v }")
|
||||
action: action("v"),
|
||||
}],
|
||||
}))
|
||||
}
|
||||
@ -477,7 +474,7 @@ impl MacroExpander {
|
||||
public: false,
|
||||
span: span,
|
||||
name: name,
|
||||
annotations: vec![],
|
||||
annotations: inline(span),
|
||||
args: vec![],
|
||||
type_decl: Some(ty_ref),
|
||||
alternatives: vec![
|
||||
@ -531,3 +528,10 @@ fn maybe_tuple(v: Vec<TypeRef>) -> TypeRef {
|
||||
fn action(s: &str) -> Option<ActionKind> {
|
||||
Some(ActionKind::User(s.to_string()))
|
||||
}
|
||||
|
||||
fn inline(span: Span) -> Vec<Annotation> {
|
||||
vec![Annotation {
|
||||
id_span: span,
|
||||
id: intern(INLINE),
|
||||
}]
|
||||
}
|
||||
|
@ -23,18 +23,27 @@ grammar;
|
||||
`Comma<"Id">`: Vec<#"Id"#> =
|
||||
<v:`(<"Id"> ",")*`> <e:`"Id"?`> => v.into_iter().chain(e.into_iter()).collect();
|
||||
|
||||
#[inline]
|
||||
`"Id"?`: ::std::option::Option<#"Id"#> = {
|
||||
"Id" => Some(<>),
|
||||
=> None
|
||||
};
|
||||
|
||||
#[inline]
|
||||
`(<"Id"> ",")*`: ::std::vec::Vec<#`(<"Id"> ",")`#> = {
|
||||
=> vec![],
|
||||
<v:`(<"Id"> ",")*`> <e:`(<"Id"> ",")`> => { let mut v = v; v.push(e); v }
|
||||
<v:`(<"Id"> ",")+`> => v,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
`(<"Id"> ",")`: #"Id"# = <"Id"> "," => (<>);
|
||||
`(<"Id"> ",")`: #"Id"# = {
|
||||
<"Id"> "," => (<>),
|
||||
};
|
||||
|
||||
`(<"Id"> ",")+`: ::std::vec::Vec<#`(<"Id"> ",")`#> = {
|
||||
`(<"Id"> ",")` => vec![<>],
|
||||
<v:`(<"Id"> ",")+`> <e:`(<"Id"> ",")`> => { let mut v = v; v.push(e); v },
|
||||
};
|
||||
"##).unwrap();
|
||||
|
||||
compare(actual, expected);
|
||||
|
Loading…
x
Reference in New Issue
Block a user