1062: Properly perform follow set checking on matcher r=CohenArthur a=CohenArthur

Addresses #947 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
This commit is contained in:
bors[bot] 2022-03-25 07:55:29 +00:00 committed by GitHub
commit 89ad4f21f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -227,9 +227,25 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
}
case AST::MacroMatch::Matcher: {
auto matcher = static_cast<AST::MacroMatcher *> (&match);
auto &matches = matcher->get_matches ();
if (!matches.empty ())
error_locus = matches.front ()->get_match_locus ();
auto first_token = matcher->get_delim_type ();
TokenId delim_id;
switch (first_token)
{
case AST::PARENS:
delim_id = LEFT_PAREN;
break;
case AST::SQUARE:
delim_id = LEFT_SQUARE;
break;
case AST::CURLY:
delim_id = LEFT_CURLY;
break;
}
if (contains (allowed_toks, delim_id))
return true;
kind_str = "token `" + std::string (get_token_description (delim_id))
+ "` at start of matcher";
error_locus = matcher->get_match_locus ();
break;
}
case AST::MacroMatch::Fragment: {

View File

@ -0,0 +1,5 @@
macro_rules! m {
($e:expr (, parenthesis_forbidden)) => {{}}; // { dg-error "token .\\(. at start of matcher is not allowed after .expr. fragment" }
// { dg-error "required first macro rule" "" { target *-*-* } .-1 }
// { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
}