mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add convenience functions to inspect the kind of the next token.
This commit is contained in:
@@ -33,6 +33,20 @@ class ParseTree::Parser {
|
||||
return tokens.GetKind(*position) == TokenKind::EndOfFile();
|
||||
}
|
||||
|
||||
// Gets the kind of the next token to be consumed.
|
||||
auto NextTokenKind() const -> TokenKind { return tokens.GetKind(*position); }
|
||||
|
||||
// Tests whether the next token to be consumed is of the specified kind.
|
||||
auto NextTokenIs(TokenKind kind) const -> bool {
|
||||
return NextTokenKind() == kind;
|
||||
}
|
||||
|
||||
// Tests whether the next token to be consumed is of any of the specified
|
||||
// kinds.
|
||||
auto NextTokenIsOneOf(std::initializer_list<TokenKind> kinds) const -> bool {
|
||||
return NextTokenKind().IsOneOf(kinds);
|
||||
}
|
||||
|
||||
// Requires (and asserts) that the current position matches the provide
|
||||
// `Kind`. Returns the current token and advances to the next position.
|
||||
auto Consume(TokenKind kind) -> TokenizedBuffer::Token;
|
||||
|
||||
Reference in New Issue
Block a user