Skip to content

Commit 32894e6

Browse files
Merge #1042
1042: Parse reserved keywords as valid fragments identifiers r=CohenArthur a=CohenArthur Per the reference, macro fragments actually accept all identifiers, not NON_KEYWORD_IDENTIFIERS Fixes #1013 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 parents 1bb9a29 + 80d9690 commit 32894e6

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

gcc/rust/parse/rust-parse-impl.h

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,56 @@ Parser<ManagedTokenSource>::parse_macro_match ()
18321832
const_TokenPtr t2 = lexer.peek_token (1);
18331833
switch (t2->get_id ())
18341834
{
1835+
case ABSTRACT:
1836+
case AS:
1837+
case ASYNC:
1838+
case BECOME:
1839+
case BOX:
1840+
case BREAK:
1841+
case CONST:
1842+
case CONTINUE:
1843+
case CRATE:
1844+
case DO:
1845+
case DYN:
1846+
case ELSE:
1847+
case ENUM_TOK:
1848+
case EXTERN_TOK:
1849+
case FALSE_LITERAL:
1850+
case FINAL_TOK:
1851+
case FN_TOK:
1852+
case FOR:
1853+
case IF:
1854+
case IMPL:
1855+
case IN:
1856+
case LET:
1857+
case LOOP:
1858+
case MACRO:
1859+
case MATCH_TOK:
1860+
case MOD:
1861+
case MOVE:
1862+
case MUT:
1863+
case OVERRIDE_TOK:
1864+
case PRIV:
1865+
case PUB:
1866+
case REF:
1867+
case RETURN_TOK:
1868+
case SELF_ALIAS:
1869+
case SELF:
1870+
case STATIC_TOK:
1871+
case STRUCT_TOK:
1872+
case SUPER:
1873+
case TRAIT:
1874+
case TRUE_LITERAL:
1875+
case TRY:
1876+
case TYPE:
1877+
case TYPEOF:
1878+
case UNSAFE:
1879+
case UNSIZED:
1880+
case USE:
1881+
case VIRTUAL:
1882+
case WHERE:
1883+
case WHILE:
1884+
case YIELD:
18351885
case IDENTIFIER:
18361886
// macro fragment
18371887
return parse_macro_match_fragment ();
@@ -1877,16 +1927,22 @@ Parser<ManagedTokenSource>::parse_macro_match_fragment ()
18771927
Location fragment_locus = lexer.peek_token ()->get_locus ();
18781928
skip_token (DOLLAR_SIGN);
18791929

1880-
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
1881-
if (ident_tok == nullptr)
1930+
Identifier ident = "";
1931+
auto identifier = lexer.peek_token ();
1932+
if (identifier->has_str ())
1933+
ident = identifier->get_str ();
1934+
else
1935+
ident = std::string (token_id_to_str (identifier->get_id ()));
1936+
1937+
if (ident.empty ())
18821938
{
18831939
Error error (lexer.peek_token ()->get_locus (),
18841940
"missing identifier in macro match fragment");
18851941
add_error (std::move (error));
18861942

18871943
return nullptr;
18881944
}
1889-
Identifier ident = ident_tok->get_str ();
1945+
skip_token (identifier->get_id ());
18901946

18911947
if (!skip_token (COLON))
18921948
{

0 commit comments

Comments
 (0)