break;
case AST::MacroFragSpec::IDENT:
- parser.parse_identifier_pattern ();
+ parser.parse_identifier_or_keyword_token ();
break;
case AST::MacroFragSpec::LITERAL:
}
}
+/* checks if a token is a keyword */
+bool
+token_id_is_keyword (TokenId id)
+{
+ switch (id)
+ {
+#define RS_TOKEN_KEYWORD(name, _) case name:
+#define RS_TOKEN(a, b)
+ RS_TOKEN_LIST return true;
+#undef RS_TOKEN_KEYWORD
+#undef RS_TOKEN
+ default:
+ return false;
+ }
+}
+
+/* gets the string associated with a keyword */
+const char *
+token_id_keyword_string (TokenId id)
+{
+ switch (id)
+ {
+#define RS_TOKEN_KEYWORD(id, str) \
+ case id: \
+ return str;
+#define RS_TOKEN(a, b)
+ RS_TOKEN_LIST
+#undef RS_TOKEN_KEYWORD
+#undef RS_TOKEN
+ default:
+ return nullptr;
+ }
+}
+
const char *
get_type_hint_string (PrimitiveCoreType type)
{
* x-macros */
const char *
token_id_to_str (TokenId id);
+/* checks if a token is a keyword */
+bool
+token_id_is_keyword (TokenId id);
+/* gets the string associated with a keyword */
+const char *
+token_id_keyword_string (TokenId id);
// Get type hint description as a string.
const char *
get_type_hint_string (PrimitiveCoreType type);
}
}
+// Parses an identifier/keyword as a Token
+template <typename ManagedTokenSource>
+std::unique_ptr<AST::Token>
+Parser<ManagedTokenSource>::parse_identifier_or_keyword_token ()
+{
+ const_TokenPtr t = lexer.peek_token ();
+
+ if (t->get_id () == IDENTIFIER || token_id_is_keyword (t->get_id ()))
+ {
+ lexer.skip_token ();
+ return std::unique_ptr<AST::Token> (new AST::Token (std::move (t)));
+ }
+ else
+ {
+ return nullptr;
+ }
+}
+
/* Parses a TokenTree syntactical production. This is either a delimited token
* tree or a non-delimiter token. */
template <typename ManagedTokenSource>
std::vector<std::unique_ptr<AST::LifetimeParam> > parse_lifetime_params ();
AST::Visibility parse_visibility ();
std::unique_ptr<AST::IdentifierPattern> parse_identifier_pattern ();
+ std::unique_ptr<AST::Token> parse_identifier_or_keyword_token ();
std::unique_ptr<AST::TokenTree> parse_token_tree ();
std::tuple<AST::SimplePath, std::unique_ptr<AST::AttrInput>, Location>
parse_attribute_body ();
--- /dev/null
+macro_rules! foo {
+ ($a:ident) => {}
+}
+
+pub fn bar() {
+ foo!(self);
+}