summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/macro_rules/eval.cpp16
-rw-r--r--src/parse/eTokenType.enum.h1
2 files changed, 15 insertions, 2 deletions
diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp
index d37f0279..3ccb6f6f 100644
--- a/src/macro_rules/eval.cpp
+++ b/src/macro_rules/eval.cpp
@@ -577,6 +577,13 @@ void Macro_InitDefaults()
{
}
+namespace {
+ bool is_reserved_word(eTokenType tok)
+ {
+ return tok >= TOK_RWORD_PUB;
+ }
+}
+
bool Macro_TryPatternCap(TokenStream& lex, MacroPatEnt::Type type)
{
switch(type)
@@ -588,7 +595,7 @@ bool Macro_TryPatternCap(TokenStream& lex, MacroPatEnt::Type type)
case MacroPatEnt::PAT_BLOCK:
return LOOK_AHEAD(lex) == TOK_BRACE_OPEN || LOOK_AHEAD(lex) == TOK_INTERPOLATED_BLOCK;
case MacroPatEnt::PAT_IDENT:
- return LOOK_AHEAD(lex) == TOK_IDENT;
+ return LOOK_AHEAD(lex) == TOK_IDENT || is_reserved_word(LOOK_AHEAD(lex));
case MacroPatEnt::PAT_TT:
switch(LOOK_AHEAD(lex))
{
@@ -683,7 +690,12 @@ void Macro_HandlePatternCap(TokenStream& lex, unsigned int index, MacroPatEnt::T
bound_tts.insert( index, iterations, InterpolatedFragment( Parse_Mod_Item_S(lex, cur_mod.m_file_info, cur_mod.path(), AST::MetaItems{}) ) );
} break;
case MacroPatEnt::PAT_IDENT:
- GET_CHECK_TOK(tok, lex, TOK_IDENT);
+ // TODO: Any reserved word is also valid as an ident
+ GET_TOK(tok, lex);
+ if( tok.type() == TOK_IDENT || is_reserved_word(tok.type()) )
+ ;
+ else
+ CHECK_TOK(tok, TOK_IDENT);
bound_tts.insert( index, iterations, InterpolatedFragment( TokenTree(tok) ) );
break;
}
diff --git a/src/parse/eTokenType.enum.h b/src/parse/eTokenType.enum.h
index 21bbb1d5..9caa3aba 100644
--- a/src/parse/eTokenType.enum.h
+++ b/src/parse/eTokenType.enum.h
@@ -85,6 +85,7 @@ _(TOK_CARET_EQUAL)
_(TOK_BACKTICK)
// Reserved Words
+// NOTE: ORDERING MATTERS! _PUB must be the first, and no non-rword tokens should follow
_(TOK_RWORD_PUB)
_(TOK_RWORD_PRIV)
_(TOK_RWORD_MUT)