Sync the keyword list (#1097)

I was mainly looking at keywords trying to figure out what needs work and the amount to which it doesn't reflect the design confused me (including some things that we've decided not to include, and some things I'm not aware of discussion about). I figured this cleanup would at least make it somewhat clearer why things are in there.

I'm treating https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/lexical_conventions/words.md as canonical, with `_` and `xor` as presumably deliberate exceptions. Similarly avoiding symbol tokens because I assume you'll push proposals for the difference.

I dropped the `Keyword` qualifier because `is` makes `IsKeyword` a name conflict, and dropping the qualifier seemed like the more consistent solution (it doesn't do `AmpSymbol`, after all). If we need clarity I might lean towards a separate namespace to avoid naming conflicts.
This commit is contained in:
Jon Meow
2022-02-24 13:46:17 -08:00
committed by GitHub
parent 900f41cc3a
commit fa07a016b8
6 changed files with 99 additions and 93 deletions
+16 -16
View File
@@ -601,7 +601,7 @@ auto ParseTree::Parser::ParseCodeBlock() -> llvm::Optional<Node> {
}
auto ParseTree::Parser::ParseFunctionDeclaration() -> Node {
TokenizedBuffer::Token function_intro_token = Consume(TokenKind::FnKeyword());
TokenizedBuffer::Token function_intro_token = Consume(TokenKind::Fn());
auto start = GetSubtreeStartPosition();
auto add_error_function_node = [&] {
@@ -663,7 +663,7 @@ auto ParseTree::Parser::ParseFunctionDeclaration() -> Node {
auto ParseTree::Parser::ParseVariableDeclaration() -> Node {
// `var` pattern [= expression] `;`
TokenizedBuffer::Token var_token = Consume(TokenKind::VarKeyword());
TokenizedBuffer::Token var_token = Consume(TokenKind::Var());
auto start = GetSubtreeStartPosition();
RETURN_IF_STACK_LIMITED(AddNode(ParseNodeKind::VariableDeclaration(),
@@ -706,9 +706,9 @@ auto ParseTree::Parser::ParseEmptyDeclaration() -> Node {
auto ParseTree::Parser::ParseDeclaration() -> llvm::Optional<Node> {
RETURN_IF_STACK_LIMITED(llvm::None);
switch (NextTokenKind()) {
case TokenKind::FnKeyword():
case TokenKind::Fn():
return ParseFunctionDeclaration();
case TokenKind::VarKeyword():
case TokenKind::Var():
return ParseVariableDeclaration();
case TokenKind::Semi():
return ParseEmptyDeclaration();
@@ -1184,14 +1184,14 @@ auto ParseTree::Parser::ParseParenCondition(TokenKind introducer)
auto ParseTree::Parser::ParseIfStatement() -> llvm::Optional<Node> {
auto start = GetSubtreeStartPosition();
auto if_token = Consume(TokenKind::IfKeyword());
auto cond = ParseParenCondition(TokenKind::IfKeyword());
auto if_token = Consume(TokenKind::If());
auto cond = ParseParenCondition(TokenKind::If());
auto then_case = ParseCodeBlock();
bool else_has_errors = false;
if (ConsumeAndAddLeafNodeIf(TokenKind::ElseKeyword(),
if (ConsumeAndAddLeafNodeIf(TokenKind::Else(),
ParseNodeKind::IfStatementElse())) {
// 'else if' is permitted as a special case.
if (NextTokenIs(TokenKind::IfKeyword())) {
if (NextTokenIs(TokenKind::If())) {
else_has_errors = !ParseIfStatement();
} else {
else_has_errors = !ParseCodeBlock();
@@ -1204,8 +1204,8 @@ auto ParseTree::Parser::ParseIfStatement() -> llvm::Optional<Node> {
auto ParseTree::Parser::ParseWhileStatement() -> llvm::Optional<Node> {
RETURN_IF_STACK_LIMITED(llvm::None);
auto start = GetSubtreeStartPosition();
auto while_token = Consume(TokenKind::WhileKeyword());
auto cond = ParseParenCondition(TokenKind::WhileKeyword());
auto while_token = Consume(TokenKind::While());
auto cond = ParseParenCondition(TokenKind::While());
auto body = ParseCodeBlock();
return AddNode(ParseNodeKind::WhileStatement(), while_token, start,
/*has_error=*/!cond || !body);
@@ -1241,24 +1241,24 @@ auto ParseTree::Parser::ParseKeywordStatement(ParseNodeKind kind,
auto ParseTree::Parser::ParseStatement() -> llvm::Optional<Node> {
RETURN_IF_STACK_LIMITED(llvm::None);
switch (NextTokenKind()) {
case TokenKind::VarKeyword():
case TokenKind::Var():
return ParseVariableDeclaration();
case TokenKind::IfKeyword():
case TokenKind::If():
return ParseIfStatement();
case TokenKind::WhileKeyword():
case TokenKind::While():
return ParseWhileStatement();
case TokenKind::ContinueKeyword():
case TokenKind::Continue():
return ParseKeywordStatement(ParseNodeKind::ContinueStatement(),
KeywordStatementArgument::None);
case TokenKind::BreakKeyword():
case TokenKind::Break():
return ParseKeywordStatement(ParseNodeKind::BreakStatement(),
KeywordStatementArgument::None);
case TokenKind::ReturnKeyword():
case TokenKind::Return():
return ParseKeywordStatement(ParseNodeKind::ReturnStatement(),
KeywordStatementArgument::Optional);