This commit is contained in:
nub31
2025-10-26 22:28:48 +01:00
parent 27bc4da4fd
commit 560e6428ff
18 changed files with 663 additions and 483 deletions

View File

@@ -58,7 +58,7 @@ public sealed class Tokenizer
Tokens.Add(ParseToken(current, _line, _column));
}
catch (TokenizerException e)
catch (CompileException e)
{
Diagnostics.Add(e.Diagnostic);
Next();
@@ -95,7 +95,7 @@ public sealed class Tokenizer
return ParseIdentifier(lineStart, columnStart);
}
throw new TokenizerException(Diagnostic.Error($"Unknown token '{current}'").Build());
throw new CompileException(Diagnostic.Error($"Unknown token '{current}'").Build());
}
private Token ParseNumber(int lineStart, int columnStart)
@@ -116,7 +116,7 @@ public sealed class Tokenizer
if (_index == digitStart)
{
throw new TokenizerException(Diagnostic
throw new CompileException(Diagnostic
.Error("Invalid hex literal, no digits found")
.At(_fileName, _line, _column)
.Build());
@@ -141,7 +141,7 @@ public sealed class Tokenizer
if (_index == digitStart)
{
throw new TokenizerException(Diagnostic
throw new CompileException(Diagnostic
.Error("Invalid binary literal, no digits found")
.At(_fileName, _line, _column)
.Build());
@@ -163,7 +163,7 @@ public sealed class Tokenizer
{
if (isFloat)
{
throw new TokenizerException(Diagnostic
throw new CompileException(Diagnostic
.Error("More than one period found in float literal")
.At(_fileName, _line, _column)
.Build());
@@ -198,7 +198,7 @@ public sealed class Tokenizer
{
if (_index >= _content.Length)
{
throw new TokenizerException(Diagnostic
throw new CompileException(Diagnostic
.Error("Unclosed string literal")
.At(_fileName, _line, _column)
.Build());
@@ -208,7 +208,7 @@ public sealed class Tokenizer
if (next == '\n')
{
throw new TokenizerException(Diagnostic
throw new CompileException(Diagnostic
.Error("Unclosed string literal (newline found)")
.At(_fileName, _line, _column)
.Build());
@@ -375,14 +375,4 @@ public sealed class Tokenizer
_index += count;
_column += count;
}
}
public class TokenizerException : Exception
{
public Diagnostic Diagnostic { get; }
public TokenizerException(Diagnostic diagnostic) : base(diagnostic.Message)
{
Diagnostic = diagnostic;
}
}