Skip to content

Commit

Permalink
Merge pull request #418 from tjade273/repeatop_fix
Browse files Browse the repository at this point in the history
Fix type annotation for inline actions
  • Loading branch information
Marwes committed Nov 28, 2018
2 parents 28533af + c263536 commit 273e544
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
11 changes: 11 additions & 0 deletions lalrpop-test/src/generics_issue_417.lalrpop
@@ -0,0 +1,11 @@
use generics_issue_104_lib::Generator;

grammar<T> where T: Generator;

extern {
type Error = String;
}

Id : String = <id:r"[a-zA-Z0-9]*"> => T::schema(id);

pub Tuple : (String, String) = "(" <(<Id> "," <Id>)> ")";
12 changes: 12 additions & 0 deletions lalrpop-test/src/lib.rs
Expand Up @@ -111,6 +111,9 @@ lalrpop_mod!(partial_parse);
/// regression test for issue #278.
lalrpop_mod!(error_issue_278);

/// test for generic macros issue #417.
lalrpop_mod!(generics_issue_417);

// Check that error recovery (which requires cloneable tokens) is not created if it is not used
lalrpop_mod!(
#[allow(unused)]
Expand Down Expand Up @@ -913,6 +916,15 @@ fn error_issue_278() {
}
}

#[test]
fn generics_issue_417(){
// Similar to `generics_issue_104`
// The real thing `generics_issue_417` is testing is that the code
// *compiles*, even though the type parameter `T` does not appear
// in any of the arguments.
assert!(generics_issue_417::TupleParser::new().parse::<()>("(hello, world)").is_ok());
}

#[test]
fn verify_lalrpop_generates_itself() {
let out_dir = "../target";
Expand Down
21 changes: 17 additions & 4 deletions lalrpop/src/build/action.rs
Expand Up @@ -350,6 +350,11 @@ fn emit_inline_action_code<W: Write>(
// Now create temporaries for the inlined things
let mut arg_counter = 0;
let mut temp_counter = 0;

// if there are type parameters then type annotation is required
let annotate = !grammar.non_lifetime_type_parameters().is_empty();
let lparen = if annotate {"::<"} else {"("};

for symbol in &data.symbols {
match *symbol {
r::InlinedSymbol::Original(_) => {
Expand All @@ -359,12 +364,17 @@ fn emit_inline_action_code<W: Write>(
// execute the inlined reduce action
rust!(
rust,
"let {}temp{} = {}action{}(",
"let {}temp{} = {}action{}{}",
grammar.prefix,
temp_counter,
grammar.prefix,
inlined_action.index()
inlined_action.index(),
lparen
);
for t in grammar.non_lifetime_type_parameters() {
rust!(rust, "{},", t);
}
if annotate {rust!(rust, ">(")};
for parameter in &grammar.parameters {
rust!(rust, "{},", parameter.name);
}
Expand Down Expand Up @@ -396,8 +406,11 @@ fn emit_inline_action_code<W: Write>(
}
}
}

rust!(rust, "{}action{}(", grammar.prefix, data.action.index());
rust!(rust, "{}action{}{}", grammar.prefix, data.action.index(), lparen);
for t in grammar.non_lifetime_type_parameters() {
rust!(rust, "{},", t);
}
if annotate {rust!(rust, ">(")};
for parameter in &grammar.parameters {
rust!(rust, "{},", parameter.name);
}
Expand Down

0 comments on commit 273e544

Please sign in to comment.