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
+18 -20
View File
@@ -272,7 +272,7 @@ TEST_F(LexerTest, SplitsNumericLiteralsProperly) {
// newline
{.kind = TokenKind::IntegerLiteral(), .text = "13"},
{.kind = TokenKind::Period()},
{.kind = TokenKind::UnderscoreKeyword()},
{.kind = TokenKind::Underscore()},
// newline
{.kind = TokenKind::EndOfFile()},
}));
@@ -577,28 +577,26 @@ TEST_F(LexerTest, Whitespace) {
TEST_F(LexerTest, Keywords) {
auto buffer = Lex(" fn");
EXPECT_FALSE(buffer.HasErrors());
EXPECT_THAT(
buffer,
HasTokens(llvm::ArrayRef<ExpectedToken>{
{.kind = TokenKind::FnKeyword(), .column = 4, .indent_column = 4},
{TokenKind::EndOfFile()},
}));
EXPECT_THAT(buffer,
HasTokens(llvm::ArrayRef<ExpectedToken>{
{.kind = TokenKind::Fn(), .column = 4, .indent_column = 4},
{TokenKind::EndOfFile()},
}));
buffer = Lex("and or not if else for loop return var break continue _");
buffer = Lex("and or not if else for return var break continue _");
EXPECT_FALSE(buffer.HasErrors());
EXPECT_THAT(buffer, HasTokens(llvm::ArrayRef<ExpectedToken>{
{TokenKind::AndKeyword()},
{TokenKind::OrKeyword()},
{TokenKind::NotKeyword()},
{TokenKind::IfKeyword()},
{TokenKind::ElseKeyword()},
{TokenKind::ForKeyword()},
{TokenKind::LoopKeyword()},
{TokenKind::ReturnKeyword()},
{TokenKind::VarKeyword()},
{TokenKind::BreakKeyword()},
{TokenKind::ContinueKeyword()},
{TokenKind::UnderscoreKeyword()},
{TokenKind::And()},
{TokenKind::Or()},
{TokenKind::Not()},
{TokenKind::If()},
{TokenKind::Else()},
{TokenKind::For()},
{TokenKind::Return()},
{TokenKind::Var()},
{TokenKind::Break()},
{TokenKind::Continue()},
{TokenKind::Underscore()},
{TokenKind::EndOfFile()},
}));
}