This commit is contained in:
nub31
2026-02-09 19:34:47 +01:00
parent 9fb9c50a0b
commit 96670b1201
7 changed files with 335 additions and 262 deletions

View File

@@ -177,6 +177,12 @@ public sealed class Tokenizer(string fileName, string contents)
Consume();
return new TokenSymbol(line, startColumn, column - startColumn, Symbol.Period);
}
case ':' when Peek(1) is ':':
{
Consume();
Consume();
return new TokenSymbol(line, startColumn, column - startColumn, Symbol.ColonColon);
}
case ':':
{
Consume();
@@ -340,6 +346,9 @@ public sealed class Tokenizer(string fileName, string contents)
"else" => new TokenKeyword(line, startColumn, column - startColumn, Keyword.Else),
"while" => new TokenKeyword(line, startColumn, column - startColumn, Keyword.While),
"return" => new TokenKeyword(line, startColumn, column - startColumn, Keyword.Return),
"module" => new TokenKeyword(line, startColumn, column - startColumn, Keyword.Module),
"import" => new TokenKeyword(line, startColumn, column - startColumn, Keyword.Import),
"export" => new TokenKeyword(line, startColumn, column - startColumn, Keyword.Export),
"true" => new TokenBoolLiteral(line, startColumn, column - startColumn, true),
"false" => new TokenBoolLiteral(line, startColumn, column - startColumn, false),
_ => new TokenIdent(line, startColumn, column - startColumn, value)
@@ -430,6 +439,7 @@ public enum Symbol
Comma,
Period,
Colon,
ColonColon,
Caret,
Bang,
Equal,
@@ -471,6 +481,9 @@ public enum Keyword
Else,
While,
Return,
Module,
Import,
Export,
}
public sealed class TokenKeyword(int line, int column, int length, Keyword keyword) : Token(line, column, length)
@@ -491,6 +504,7 @@ public static class TokenExtensions
Symbol.Comma => ",",
Symbol.Period => ",",
Symbol.Colon => ":",
Symbol.ColonColon => "::",
Symbol.Caret => "^",
Symbol.Bang => "!",
Symbol.Equal => "=",
@@ -531,6 +545,9 @@ public static class TokenExtensions
Keyword.Else => "else",
Keyword.While => "while",
Keyword.Return => "return",
Keyword.Module => "module",
Keyword.Import => "import",
Keyword.Export => "export",
_ => throw new ArgumentOutOfRangeException(nameof(symbol), symbol, null)
};
}