@@ -3615,12 +3615,13 @@ MacroExpander::match_token (Parser<MacroInvocLexer> &parser, AST::Token &token)
3615
3615
}
3616
3616
3617
3617
bool
3618
- MacroExpander::match_n_matches (
3619
- Parser<MacroInvocLexer> &parser ,
3620
- std::vector<std::unique_ptr<AST::MacroMatch>> &matches , size_t &match_amount ,
3621
- size_t lo_bound, size_t hi_bound)
3618
+ MacroExpander::match_n_matches (Parser<MacroInvocLexer> &parser,
3619
+ AST::MacroMatchRepetition &rep ,
3620
+ size_t &match_amount , size_t lo_bound ,
3621
+ size_t hi_bound)
3622
3622
{
3623
3623
match_amount = 0 ;
3624
+ auto &matches = rep.get_matches ();
3624
3625
3625
3626
const MacroInvocLexer &source = parser.get_token_source ();
3626
3627
while (true )
@@ -3631,6 +3632,12 @@ MacroExpander::match_n_matches (
3631
3632
if (t_id == RIGHT_PAREN || t_id == RIGHT_SQUARE || t_id == RIGHT_CURLY)
3632
3633
break ;
3633
3634
3635
+ // Skip parsing a separator on the first match, otherwise consume it.
3636
+ // If it isn't present, this is an error
3637
+ if (rep.has_sep () && match_amount > 0 )
3638
+ if (!match_token (parser, *rep.get_sep ()))
3639
+ break ;
3640
+
3634
3641
bool valid_current_match = false ;
3635
3642
for (auto &match : matches)
3636
3643
{
@@ -3705,17 +3712,17 @@ MacroExpander::match_repetition (Parser<MacroInvocLexer> &parser,
3705
3712
case AST::MacroMatchRepetition::MacroRepOp::ANY:
3706
3713
lo_str = " 0" ;
3707
3714
hi_str = " +inf" ;
3708
- res = match_n_matches (parser, rep. get_matches () , match_amount);
3715
+ res = match_n_matches (parser, rep, match_amount);
3709
3716
break ;
3710
3717
case AST::MacroMatchRepetition::MacroRepOp::ONE_OR_MORE:
3711
3718
lo_str = " 1" ;
3712
3719
hi_str = " +inf" ;
3713
- res = match_n_matches (parser, rep. get_matches () , match_amount, 1 );
3720
+ res = match_n_matches (parser, rep, match_amount, 1 );
3714
3721
break ;
3715
3722
case AST::MacroMatchRepetition::MacroRepOp::ZERO_OR_ONE:
3716
3723
lo_str = " 0" ;
3717
3724
hi_str = " 1" ;
3718
- res = match_n_matches (parser, rep. get_matches () , match_amount, 0 , 1 );
3725
+ res = match_n_matches (parser, rep, match_amount, 0 , 1 );
3719
3726
break ;
3720
3727
default :
3721
3728
gcc_unreachable ();
0 commit comments