aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/parse')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h18
-rw-r--r--gcc/rust/parse/rust-parse.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index cdcc8b8..1824545 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -999,6 +999,24 @@ Parser<ManagedTokenSource>::parse_delim_token_tree ()
}
}
+// 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>
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 6957b66..71f0ff1 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -148,6 +148,7 @@ public:
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 ();