Skip to content

Commit

Permalink
Merge pull request #317 from plaflamme/fix-type-argument-return-position
Browse files Browse the repository at this point in the history
fix: support generic argument in rule's return position
  • Loading branch information
kevinmehall authored Sep 25, 2022
2 parents c0e882b + 4cf66e7 commit 74c48c4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion peg-macros/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub mod peg {
&mut __err_state,
::peg::Parse::start(__input),
) {
::peg::RuleResult::Matched(__pos, __value) => {
::peg::RuleResult::<Grammar>::Matched(__pos, __value) => {
if ::peg::Parse::is_eof(__input, __pos) {
panic!(
"Parser is nondeterministic: succeeded when reparsing for error position"
Expand Down
2 changes: 1 addition & 1 deletion peg-macros/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn compile_rule_export(context: &Context, rule: &Rule) -> TokenStream {
__err_state.reparse_for_error();

match #parse_fn(__input, &mut __state, &mut __err_state, ::peg::Parse::start(__input) #extra_args_call #(, #rule_params_call)*) {
::peg::RuleResult::Matched(__pos, __value) => {
::peg::RuleResult::<#ret_ty>::Matched(__pos, __value) => {
if #eof_check {
panic!("Parser is nondeterministic: succeeded when reparsing for error position");
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/rule_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ peg::parser!( grammar ra() for str {
pub rule ty_arg<T>(x: &T) = ""
pub rule ty_arg_bound<T: Copy>(x: T) = ""
pub rule ty_arg_bound2<'a, T: std::marker::Copy + ?Sized + 'a>(x: T) = ""
pub rule ty_arg_bound_ret<T: std::str::FromStr>() -> T = {? "".parse().or(Err("oops")) }
});

use ra::*;
Expand Down

0 comments on commit 74c48c4

Please sign in to comment.