From 912b04216d71a2cd95001cfb0570095db1824207 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 24 Mar 2022 13:50:03 +0100 Subject: macros: Check follow-set restrictions on matcher's first delimiter --- gcc/rust/parse/rust-parse.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'gcc/rust/parse') diff --git a/gcc/rust/parse/rust-parse.cc b/gcc/rust/parse/rust-parse.cc index 0153b37..900964e 100644 --- a/gcc/rust/parse/rust-parse.cc +++ b/gcc/rust/parse/rust-parse.cc @@ -202,9 +202,25 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match, } case AST::MacroMatch::Matcher: { auto matcher = static_cast (&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: { -- cgit v1.1