Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Lua/CodeAnalysis/Compilation/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void SyntaxError(string message)
ScanError(R.Position, message, Token.T);
}

public void ErrorExpected(int position, char t)
public void ErrorExpected(int position, int t)
{
SyntaxError(position, TokenToString(t) + " expected");
}
Expand Down Expand Up @@ -187,13 +187,12 @@ public static string TokenToString(Token t)
};
}

public string TokenToString(int t)
public static string TokenToString(int t)
{
return t switch
{
TkName or TkString => Token.S,
TkNumber => $"{Token.N}",
< FirstReserved => $"{(char)t}", // TODO check for printable rune
< FirstReserved when t is >= ' ' and <= '~' => $"'{(char)t}'",
< FirstReserved => CharTokenToLiteral(t),
< TkEos => $"'{tokens[t - FirstReserved]}'",
_ => tokens[t - FirstReserved],
};
Expand Down Expand Up @@ -938,7 +937,8 @@ public void Check(int t)
{
if (Token.T != t)
{
ErrorExpected(R.Position, (char)t);
// Reserved tokens exceed char.MaxValue; narrowing them loses the token identity.
ErrorExpected(R.Position, t);
}
}

Expand All @@ -951,7 +951,7 @@ public void CheckMatch(int what, int who, int where)

if (where == LineNumber)
{
ErrorExpected(R.Position, (char)what);
ErrorExpected(R.Position, what);
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/Lua/CodeAnalysis/Syntax/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public Lexer() { }

public readonly SyntaxToken Current => current;

internal readonly SourcePosition Position => position;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Advance(int count)
{
Expand Down
1 change: 1 addition & 0 deletions src/Lua/CodeAnalysis/Syntax/LuaSyntaxTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static LuaSyntaxTree Parse(string source, string? chunkName = null)
parser.Add(lexer.Current);
}

parser.EndPosition = lexer.Position;
return parser.Parse();
}
}
Loading
Loading