AST::MacroMatcher &matcher = match_rule.get_matcher ();
expansion_depth++;
- if (!match_matcher (parser, matcher))
+ if (!match_matcher (parser, matcher, false, false))
{
expansion_depth--;
return false;
bool
MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser,
- AST::MacroMatcher &matcher, bool in_repetition)
+ AST::MacroMatcher &matcher, bool in_repetition,
+ bool match_delim)
{
if (depth_exceeds_recursion_limit ())
{
auto delimiter = parser.peek_current_token ();
+ auto check_delim = [&matcher, match_delim] (AST::DelimType delim) {
+ return !match_delim || matcher.get_delim_type () == delim;
+ };
+
// this is used so we can check that we delimit the stream correctly.
switch (delimiter->get_id ())
{
case LEFT_PAREN: {
- if (!parser.skip_token (LEFT_PAREN))
+ if (!check_delim (AST::DelimType::PARENS))
return false;
}
break;
case LEFT_SQUARE: {
- if (!parser.skip_token (LEFT_SQUARE))
+ if (!check_delim (AST::DelimType::SQUARE))
return false;
}
break;
case LEFT_CURLY: {
- if (!parser.skip_token (LEFT_CURLY))
+ if (!check_delim (AST::DelimType::CURLY))
return false;
}
break;
default:
- gcc_unreachable ();
+ return false;
}
+ parser.skip_token ();
const MacroInvocLexer &source = parser.get_token_source ();
AST::MacroMatchRepetition &rep);
bool match_matcher (Parser<MacroInvocLexer> &parser,
- AST::MacroMatcher &matcher, bool in_repetition = false);
+ AST::MacroMatcher &matcher, bool in_repetition = false,
+ bool match_delim = true);
/**
* Match any amount of matches
lexer.skip_token ();
}
+/* Skips the current token */
+template <typename ManagedTokenSource>
+void
+Parser<ManagedTokenSource>::skip_token ()
+{
+ lexer.skip_token ();
+}
+
/* Checks if current token has inputted id - skips it and returns true if so,
* diagnoses an error and returns false otherwise. */
template <typename ManagedTokenSource>