@@ -58,7 +58,8 @@ SubstituteCtx::check_repetition_amount (size_t pattern_start,
58
58
if (macro.at (i)->get_id () == DOLLAR_SIGN)
59
59
{
60
60
auto &frag_token = macro.at (i + 1 );
61
- if (frag_token->get_id () == IDENTIFIER)
61
+ if (token_id_is_keyword (frag_token->get_id ())
62
+ || frag_token->get_id () == IDENTIFIER)
62
63
{
63
64
auto it = fragments.find (frag_token->get_str ());
64
65
if (it == fragments.end ())
@@ -199,11 +200,21 @@ std::pair<std::vector<std::unique_ptr<AST::Token>>, size_t>
199
200
SubstituteCtx::substitute_token (size_t token_idx)
200
201
{
201
202
auto &token = macro.at (token_idx);
203
+
202
204
switch (token->get_id ())
203
205
{
204
- case IDENTIFIER:
205
- rust_debug (" expanding metavar: %s" , token->get_str ().c_str ());
206
- return {substitute_metavar (token), 1 };
206
+ default :
207
+ if (token_id_is_keyword (token->get_id ()))
208
+ {
209
+ case IDENTIFIER:
210
+ rust_debug (" expanding metavar: %s" , token->get_str ().c_str ());
211
+ return {substitute_metavar (token), 1 };
212
+ }
213
+ rust_error_at (token->get_locus (),
214
+ " unexpected token in macro transcribe: expected "
215
+ " %<(%> or identifier after %<$%>, got %<%s%>" ,
216
+ get_token_description (token->get_id ()));
217
+ break ;
207
218
case LEFT_PAREN: {
208
219
// We need to parse up until the closing delimiter and expand this
209
220
// fragment->n times.
@@ -279,11 +290,6 @@ SubstituteCtx::substitute_token (size_t token_idx)
279
290
// with no associated fragment and paste the dollar sign in the
280
291
// transcription. Unsure how to do that since we always have at
281
292
// least the closing curly brace after an empty $...
282
- default :
283
- rust_error_at (token->get_locus (),
284
- " unexpected token in macro transcribe: expected "
285
- " %<(%> or identifier after %<$%>, got %<%s%>" ,
286
- get_token_description (token->get_id ()));
287
293
}
288
294
289
295
// FIXME: gcc_unreachable() error case?
0 commit comments