token: reserve "and", "or", "in" as keywords

This commit is contained in:
2025-10-16 01:37:24 -04:00
parent b5d552376e
commit f47de24cfb
2 changed files with 6 additions and 0 deletions

View File

@@ -235,6 +235,7 @@ impl<'t> Lexer<'t> {
let token = self.produce(TKind::Identifier); let token = self.produce(TKind::Identifier);
Ok(Token { Ok(Token {
kind: match lexeme { kind: match lexeme {
"and" => TKind::And,
"as" => TKind::As, "as" => TKind::As,
"break" => TKind::Break, "break" => TKind::Break,
"const" => TKind::Const, "const" => TKind::Const,
@@ -244,11 +245,13 @@ impl<'t> Lexer<'t> {
"fn" => TKind::Fn, "fn" => TKind::Fn,
"for" => TKind::For, "for" => TKind::For,
"if" => TKind::If, "if" => TKind::If,
"in" => TKind::In,
"let" => TKind::Let, "let" => TKind::Let,
"loop" => TKind::Loop, "loop" => TKind::Loop,
"macro" => TKind::Macro, "macro" => TKind::Macro,
"match" => TKind::Match, "match" => TKind::Match,
"mod" => TKind::Module, "mod" => TKind::Module,
"or" => TKind::Or,
"pub" => TKind::Public, "pub" => TKind::Public,
"return" => TKind::Return, "return" => TKind::Return,
"struct" => TKind::Struct, "struct" => TKind::Struct,

View File

@@ -56,6 +56,7 @@ impl std::fmt::Display for Lexeme {
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TKind { pub enum TKind {
Comment, Comment,
And,
As, As,
Break, Break,
Const, Const,
@@ -65,11 +66,13 @@ pub enum TKind {
Fn, Fn,
For, For,
If, If,
In,
Let, Let,
Loop, Loop,
Macro, Macro,
Match, Match,
Module, Module,
Or,
Public, Public,
Return, Return,
Struct, Struct,