patch up the macro expansion test case now that * and ? are inlined

This commit is contained in:
Niko Matsakis 2015-10-25 07:04:27 -04:00
parent f125c75926
commit 63c9c2efc9
4 changed files with 1437 additions and 824 deletions

File diff suppressed because it is too large Load Diff

View File

@ -40,22 +40,24 @@ mod __parse__Expr {
pub enum __Nonterminal<'input> { pub enum __Nonterminal<'input> {
Expr(Vec<&'input str>), Expr(Vec<&'input str>),
Other_2a(::std::vec::Vec<&'input str>), Other_2a(::std::vec::Vec<&'input str>),
Other_2b(::std::vec::Vec<&'input str>),
____Expr(Vec<&'input str>), ____Expr(Vec<&'input str>),
} }
// State 0 // State 0
// Expr = (*) Other* [EOF] // Expr = (*) [EOF]
// Other* = (*) [EOF] // Expr = (*) Other+ [EOF]
// Other* = (*) [Other] // Other+ = (*) Other+ Other [EOF]
// Other* = (*) Other* Other [EOF] // Other+ = (*) Other+ Other [Other]
// Other* = (*) Other* Other [Other] // Other+ = (*) Other [EOF]
// Other+ = (*) Other [Other]
// __Expr = (*) Expr [EOF] // __Expr = (*) Expr [EOF]
// //
// EOF -> Reduce(Other* = => ActionFn(2);) // EOF -> Reduce(Expr = => ActionFn(6);)
// Other -> Reduce(Other* = => ActionFn(2);) // Other -> Shift(S3)
// //
// Expr -> S1 // Expr -> S1
// Other* -> S2 // Other+ -> S2
pub fn __state0< pub fn __state0<
'input, 'input,
__TOKENS: Iterator<Item=Result<((), LtTok<'input>, ()),()>>, __TOKENS: Iterator<Item=Result<((), LtTok<'input>, ()),()>>,
@ -67,10 +69,14 @@ mod __parse__Expr {
{ {
let mut __result: (Option<()>, Option<((), LtTok<'input>, ())>, __Nonterminal<'input>); let mut __result: (Option<()>, Option<((), LtTok<'input>, ())>, __Nonterminal<'input>);
match __lookahead { match __lookahead {
None | Some((_, LtTok::Other(__tok0), __loc)) => {
Some((_, LtTok::Other(_), _)) => { let mut __lookbehind = Some(__loc);
let __nt = super::__action2(&__lookbehind, &__lookahead); let mut __sym0 = &mut Some((__tok0));
__result = (__lookbehind, __lookahead, __Nonterminal::Other_2a(__nt)); __result = try!(__state3(__lookbehind, __tokens, __sym0));
}
None => {
let __nt = super::__action6(&__lookbehind, &__lookahead);
__result = (__lookbehind, __lookahead, __Nonterminal::Expr(__nt));
} }
_ => { _ => {
return Err(__ParseError::UnrecognizedToken { return Err(__ParseError::UnrecognizedToken {
@ -86,7 +92,7 @@ mod __parse__Expr {
let __sym0 = &mut Some(__nt); let __sym0 = &mut Some(__nt);
__result = try!(__state1(__lookbehind, __tokens, __lookahead, __sym0)); __result = try!(__state1(__lookbehind, __tokens, __lookahead, __sym0));
} }
__Nonterminal::Other_2a(__nt) => { __Nonterminal::Other_2b(__nt) => {
let __sym0 = &mut Some(__nt); let __sym0 = &mut Some(__nt);
__result = try!(__state2(__lookbehind, __tokens, __lookahead, __sym0)); __result = try!(__state2(__lookbehind, __tokens, __lookahead, __sym0));
} }
@ -129,12 +135,12 @@ mod __parse__Expr {
} }
// State 2 // State 2
// Expr = Other* (*) [EOF] // Expr = Other+ (*) [EOF]
// Other* = Other* (*) Other [EOF] // Other+ = Other+ (*) Other [EOF]
// Other* = Other* (*) Other [Other] // Other+ = Other+ (*) Other [Other]
// //
// EOF -> Reduce(Expr = Other* => ActionFn(1);) // EOF -> Reduce(Expr = Other+ => ActionFn(7);)
// Other -> Shift(S3) // Other -> Shift(S4)
// //
pub fn __state2< pub fn __state2<
'input, 'input,
@ -151,11 +157,11 @@ mod __parse__Expr {
Some((_, LtTok::Other(__tok0), __loc)) => { Some((_, LtTok::Other(__tok0), __loc)) => {
let mut __lookbehind = Some(__loc); let mut __lookbehind = Some(__loc);
let mut __sym1 = &mut Some((__tok0)); let mut __sym1 = &mut Some((__tok0));
__result = try!(__state3(__lookbehind, __tokens, __sym0, __sym1)); __result = try!(__state4(__lookbehind, __tokens, __sym0, __sym1));
} }
None => { None => {
let __sym0 = __sym0.take().unwrap(); 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))); return Ok((__lookbehind, __lookahead, __Nonterminal::Expr(__nt)));
} }
_ => { _ => {
@ -169,15 +175,53 @@ mod __parse__Expr {
} }
// State 3 // State 3
// Other* = Other* Other (*) [EOF] // Other+ = Other (*) [EOF]
// Other* = Other* Other (*) [Other] // Other+ = Other (*) [Other]
// //
// EOF -> Reduce(Other* = Other*, Other => ActionFn(3);) // EOF -> Reduce(Other+ = Other => ActionFn(4);)
// Other -> Reduce(Other* = Other*, Other => ActionFn(3);) // Other -> Reduce(Other+ = Other => ActionFn(4);)
// //
pub fn __state3< pub fn __state3<
'input, 'input,
__TOKENS: Iterator<Item=Result<((), LtTok<'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<()>, __lookbehind: Option<()>,
__tokens: &mut __TOKENS, __tokens: &mut __TOKENS,
@ -196,8 +240,8 @@ mod __parse__Expr {
Some((_, LtTok::Other(_), _)) => { Some((_, LtTok::Other(_), _)) => {
let __sym0 = __sym0.take().unwrap(); let __sym0 = __sym0.take().unwrap();
let __sym1 = __sym1.take().unwrap(); let __sym1 = __sym1.take().unwrap();
let __nt = super::__action3(__sym0, __sym1, &__lookbehind, &__lookahead); let __nt = super::__action5(__sym0, __sym1, &__lookbehind, &__lookahead);
return Ok((__lookbehind, __lookahead, __Nonterminal::Other_2a(__nt))); return Ok((__lookbehind, __lookahead, __Nonterminal::Other_2b(__nt)));
} }
_ => { _ => {
return Err(__ParseError::UnrecognizedToken { return Err(__ParseError::UnrecognizedToken {
@ -244,6 +288,28 @@ pub fn __action2<
pub fn __action3< pub fn __action3<
'input, '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>, v: ::std::vec::Vec<&'input str>,
e: &'input str, e: &'input str,
@ -254,6 +320,44 @@ pub fn __action3<
{ let mut v = v; v.push(e); v } { 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, > { pub trait __ToTriple<'input, > {
type Error; type Error;
fn to_triple(value: Self) -> Result<((),LtTok<'input>,()),Self::Error>; fn to_triple(value: Self) -> Result<((),LtTok<'input>,()),Self::Error>;

View File

@ -362,10 +362,7 @@ impl MacroExpander {
public: false, public: false,
span: span, span: span,
name: name, name: name,
annotations: vec![Annotation { annotations: inline(span),
id_span: span,
id: intern(INLINE),
}],
args: vec![], args: vec![],
type_decl: Some(ty_ref), type_decl: Some(ty_ref),
alternatives: vec![Alternative { span: span, alternatives: vec![Alternative { span: span,
@ -390,11 +387,16 @@ impl MacroExpander {
let path = Path::vec(); let path = Path::vec();
let ty_ref = TypeRef::Nominal { path: path, types: vec![base_symbol_ty] }; 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 { Ok(GrammarItem::Nonterminal(NonterminalData {
public: false, public: false,
span: span, span: span,
name: name, name: name,
annotations: vec![], annotations: inline(span),
args: vec![], args: vec![],
type_decl: Some(ty_ref), type_decl: Some(ty_ref),
alternatives: vec![ alternatives: vec![
@ -406,7 +408,7 @@ impl MacroExpander {
action: action("vec![]") action: action("vec![]")
}, },
// X* = <v:X+> <e:X> // X* = <v:X+>
Alternative { Alternative {
span: span, span: span,
expr: ExprSymbol { expr: ExprSymbol {
@ -417,15 +419,10 @@ impl MacroExpander {
v, v,
Box::new( Box::new(
Symbol::new(span, Symbol::new(span,
SymbolKind::Nonterminal(name))))), SymbolKind::Repeat(plus_repeat)))))],
Symbol::new(
span,
SymbolKind::Name(
e,
Box::new(repeat.symbol.clone())))]
}, },
condition: None, condition: None,
action: action("{ let mut v = v; v.push(e); v }") action: action("v"),
}], }],
})) }))
} }
@ -477,7 +474,7 @@ impl MacroExpander {
public: false, public: false,
span: span, span: span,
name: name, name: name,
annotations: vec![], annotations: inline(span),
args: vec![], args: vec![],
type_decl: Some(ty_ref), type_decl: Some(ty_ref),
alternatives: vec![ alternatives: vec![
@ -531,3 +528,10 @@ fn maybe_tuple(v: Vec<TypeRef>) -> TypeRef {
fn action(s: &str) -> Option<ActionKind> { fn action(s: &str) -> Option<ActionKind> {
Some(ActionKind::User(s.to_string())) Some(ActionKind::User(s.to_string()))
} }
fn inline(span: Span) -> Vec<Annotation> {
vec![Annotation {
id_span: span,
id: intern(INLINE),
}]
}

View File

@ -23,18 +23,27 @@ grammar;
`Comma<"Id">`: Vec<#"Id"#> = `Comma<"Id">`: Vec<#"Id"#> =
<v:`(<"Id"> ",")*`> <e:`"Id"?`> => v.into_iter().chain(e.into_iter()).collect(); <v:`(<"Id"> ",")*`> <e:`"Id"?`> => v.into_iter().chain(e.into_iter()).collect();
#[inline]
`"Id"?`: ::std::option::Option<#"Id"#> = { `"Id"?`: ::std::option::Option<#"Id"#> = {
"Id" => Some(<>), "Id" => Some(<>),
=> None => None
}; };
#[inline]
`(<"Id"> ",")*`: ::std::vec::Vec<#`(<"Id"> ",")`#> = { `(<"Id"> ",")*`: ::std::vec::Vec<#`(<"Id"> ",")`#> = {
=> vec![], => vec![],
<v:`(<"Id"> ",")*`> <e:`(<"Id"> ",")`> => { let mut v = v; v.push(e); v } <v:`(<"Id"> ",")+`> => v,
}; };
#[inline] #[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(); "##).unwrap();
compare(actual, expected); compare(actual, expected);