diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-05-16 13:35:07 -0400 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:55:59 +0100 |
commit | d686ffaf26b3da16d1ea6e61f88f0a546bb33cf0 (patch) | |
tree | f0f1d3439e5a5a8146b82d00498baa167932c530 /gcc/rust/parse/rust-parse-impl.h | |
parent | 865efbdc2f195b7a9c9cfcb1d3c248c315eafeea (diff) | |
download | gcc-d686ffaf26b3da16d1ea6e61f88f0a546bb33cf0.zip gcc-d686ffaf26b3da16d1ea6e61f88f0a546bb33cf0.tar.gz gcc-d686ffaf26b3da16d1ea6e61f88f0a546bb33cf0.tar.bz2 |
gccrs: Improve keyword check while parsing a macro match
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h
(Parser::parse_macro_match): Use token_id_is_keyword.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 75 |
1 files changed, 16 insertions, 59 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 21310e3..3476128 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2063,57 +2063,6 @@ Parser<ManagedTokenSource>::parse_macro_match () const_TokenPtr t2 = lexer.peek_token (1); switch (t2->get_id ()) { - case ABSTRACT: - case AS: - case ASYNC: - case BECOME: - case BOX: - case BREAK: - case CONST: - case CONTINUE: - case CRATE: - case DO: - case DYN: - case ELSE: - case ENUM_TOK: - case EXTERN_TOK: - case FALSE_LITERAL: - case FINAL_TOK: - case FN_TOK: - case FOR: - case IF: - case IMPL: - case IN: - case LET: - case LOOP: - case MACRO: - case MATCH_TOK: - case MOD: - case MOVE: - case MUT: - case OVERRIDE_TOK: - case PRIV: - case PUB: - case REF: - case RETURN_TOK: - case SELF_ALIAS: - case SELF: - case STATIC_TOK: - case STRUCT_TOK: - case SUPER: - case AUTO: - case TRAIT: - case TRUE_LITERAL: - case TRY: - case TYPE: - case TYPEOF: - case UNSAFE: - case UNSIZED: - case USE: - case VIRTUAL: - case WHERE: - case WHILE: - case YIELD: case IDENTIFIER: case UNDERSCORE: // macro fragment @@ -2122,15 +2071,23 @@ Parser<ManagedTokenSource>::parse_macro_match () // macro repetition return parse_macro_match_repetition (); default: - // error: unrecognised - add_error ( - Error (t2->get_locus (), - "unrecognised token combination %<$%s%> at start of " - "macro match - did you mean %<$identifier%> or %<$(%>?", - t2->get_token_description ())); + if (token_id_is_keyword (t2->get_id ()) && t2->get_id () != CRATE) + { + // keyword as macro fragment + return parse_macro_match_fragment (); + } + else + { + // error: unrecognised + add_error (Error ( + t2->get_locus (), + "unrecognised token combination %<$%s%> at start of " + "macro match - did you mean %<$identifier%> or %<$(%>?", + t2->get_token_description ())); - // skip somewhere? - return nullptr; + // skip somewhere? + return nullptr; + } } } case RIGHT_PAREN: |