diff --git a/src/Lua/CodeAnalysis/Compilation/Function.cs b/src/Lua/CodeAnalysis/Compilation/Function.cs
index 0cf1b8b3..4e02a22b 100644
--- a/src/Lua/CodeAnalysis/Compilation/Function.cs
+++ b/src/Lua/CodeAnalysis/Compilation/Function.cs
@@ -147,6 +147,7 @@ public void EnterBlock(bool isLoop)
Assert(FreeRegisterCount == ActiveVariableCount);
}
+ ///
public void UndefinedGotoError(Label g)
{
if (Scanner.IsReserved(g.Name))
@@ -306,6 +307,7 @@ public void MoveGotosOut(Block b)
}
}
+ ///
public void LeaveBlock()
{
var b = Block;
@@ -354,6 +356,7 @@ public static ExprDesc MakeExpression(Kind kind, int info)
};
}
+ ///
public void SemanticError(string message)
{
P.Scanner.Token = default;
diff --git a/src/Lua/CodeAnalysis/Compilation/Parser.cs b/src/Lua/CodeAnalysis/Compilation/Parser.cs
index 646e9d16..36e11ef1 100644
--- a/src/Lua/CodeAnalysis/Compilation/Parser.cs
+++ b/src/Lua/CodeAnalysis/Compilation/Parser.cs
@@ -22,6 +22,7 @@ internal bool TestNext(int token)
return Scanner.TestNext(token);
}
+ ///
internal void Next()
{
Scanner.Next();
@@ -119,6 +120,7 @@ public void LeaveLevel()
Scanner.L.CallCount--;
}
+ ///
public TempBlock EnterLevel()
{
if (!RuntimeHelpers.TryEnsureSufficientExecutionStack())
@@ -251,6 +253,7 @@ public ExprDesc FunctionArguments(ExprDesc f, int line)
return e;
}
+ ///
public ExprDesc PrimaryExpression()
{
switch (T)
@@ -451,6 +454,7 @@ public bool BlockFollow(bool withUntil)
return false;
}
+ ///
public void StatementList()
{
while (!BlockFollow(true))
@@ -659,6 +663,7 @@ public void IfStatement(int line)
Function.PatchToHere(escapes);
}
+ ///
public void Block()
{
Function.EnterBlock(false);
@@ -884,6 +889,7 @@ public void ReturnStatement()
TestNext(';');
}
+ ///
public void Statement()
{
var line = Scanner.LineNumber;
@@ -949,6 +955,7 @@ public void Statement()
Function.FreeRegisterCount = Function.ActiveVariableCount;
}
+ ///
internal void MainFunction()
{
Function.OpenMainFunction();
@@ -958,6 +965,7 @@ internal void MainFunction()
Function = Function.CloseMainFunction();
}
+ ///
public static Prototype Parse(LuaState l, TextReader r, string name)
{
using var internPool = new StringInternPool(4);
diff --git a/src/Lua/CodeAnalysis/Compilation/Scanner.cs b/src/Lua/CodeAnalysis/Compilation/Scanner.cs
index 70fcf6cb..15b68b07 100644
--- a/src/Lua/CodeAnalysis/Compilation/Scanner.cs
+++ b/src/Lua/CodeAnalysis/Compilation/Scanner.cs
@@ -106,16 +106,19 @@ struct Scanner
public static ReadOnlySpan Tokens => tokens;
+ /// Always
public void SyntaxError(int position, string message)
{
ScanError(position, message, Token.T);
}
+ /// Always
public void SyntaxError(string message)
{
ScanError(R.Position, message, Token.T);
}
+ /// Always
public void ErrorExpected(int position, int t)
{
SyntaxError(position, TokenToString(t) + " expected");
@@ -213,6 +216,7 @@ string FormatNearToken(int t)
};
}
+ /// Always
public void ScanError(int pos, string message, int token)
{
var shortSourceBuffer = (stackalloc char[59]);
@@ -641,6 +645,7 @@ public Token ReservedOrName(int pos, ReadOnlySpan text)
return new(pos, token == 0 ? TkName : token, str, rawLength);
}
+ ///
public Token Scan()
{
const bool comment = true,
@@ -799,6 +804,7 @@ public Token Scan()
}
}
+ ///
public void Next()
{
LastLine = LineNumber;
diff --git a/src/Lua/CodeAnalysis/Syntax/Lexer.cs b/src/Lua/CodeAnalysis/Syntax/Lexer.cs
index 5ded48a6..158b1884 100644
--- a/src/Lua/CodeAnalysis/Syntax/Lexer.cs
+++ b/src/Lua/CodeAnalysis/Syntax/Lexer.cs
@@ -18,6 +18,7 @@ public Lexer() { }
internal readonly SourcePosition Position => position;
+ ///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Advance(int count)
{
@@ -60,6 +61,7 @@ bool TryRead(int offset, out char value)
return true;
}
+ ///
public bool MoveNext()
{
if (Source.Length <= offset)
diff --git a/src/Lua/CodeAnalysis/Syntax/Parser.cs b/src/Lua/CodeAnalysis/Syntax/Parser.cs
index 2fd644d3..3017f50c 100644
--- a/src/Lua/CodeAnalysis/Syntax/Parser.cs
+++ b/src/Lua/CodeAnalysis/Syntax/Parser.cs
@@ -60,6 +60,7 @@ public LuaSyntaxTree Parse()
return tree;
}
+ ///
StatementNode ParseStatement(ref SyntaxTokenEnumerator enumerator)
{
switch (enumerator.Current.Type)
@@ -655,6 +656,7 @@ out var endToken
);
}
+ ///
TableMethodDeclarationStatementNode ParseTableMethodDeclarationStatement(
ref SyntaxTokenEnumerator enumerator,
SyntaxToken functionToken
@@ -826,6 +828,7 @@ or SyntaxTokenType.LCurly
return true;
}
+ ///
ExpressionNode ParseExpression(
ref SyntaxTokenEnumerator enumerator,
OperatorPrecedence precedence
@@ -862,6 +865,7 @@ ExpressionNode ParseMinusNumber(ref SyntaxTokenEnumerator enumerator)
}
}
+ ///
UnaryExpressionNode ParseUnaryExpression(
ref SyntaxTokenEnumerator enumerator,
SyntaxToken operatorToken
@@ -885,6 +889,7 @@ SyntaxToken operatorToken
return new(operatorType, right, operatorToken.Position);
}
+ ///
BinaryExpressionNode ParseBinaryExpression(
ref SyntaxTokenEnumerator enumerator,
OperatorPrecedence precedence,
@@ -1028,6 +1033,7 @@ when enumerator.GetNext(true).Type is SyntaxTokenType.Assignment:
return new(items.AsSpan().ToArray(), startToken.Position);
}
+ ///
ExpressionNode ParseTableAccessExpression(
ref SyntaxTokenEnumerator enumerator,
ExpressionNode? parentTable
@@ -1334,6 +1340,7 @@ SourcePosition GetEndPosition(ref SyntaxTokenEnumerator enumerator)
return EndPosition.Line > 0 ? EndPosition : enumerator.Current.Position;
}
+ ///
void MissingClosingToken(
ref SyntaxTokenEnumerator enumerator,
SyntaxTokenType expectedToken,
@@ -1390,6 +1397,7 @@ out SyntaxToken token
MoveNextWithValidation(ref enumerator);
}
+ ///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void CheckCurrent(ref SyntaxTokenEnumerator enumerator, SyntaxTokenType expectedToken)
{
@@ -1405,6 +1413,7 @@ void CheckCurrent(ref SyntaxTokenEnumerator enumerator, SyntaxTokenType expected
}
}
+ ///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void MoveNextWithValidation(ref SyntaxTokenEnumerator enumerator)
{
diff --git a/src/Lua/Exceptions.cs b/src/Lua/Exceptions.cs
index 9459f0c4..2f4c2087 100644
--- a/src/Lua/Exceptions.cs
+++ b/src/Lua/Exceptions.cs
@@ -13,6 +13,7 @@ public class LuaParseException(string? chunkName, SourcePosition position, strin
public string? ChunkName { get; } = chunkName;
public SourcePosition Position { get; } = position;
+ ///
public static void UnexpectedToken(
string? chunkName,
SourcePosition position,
@@ -26,6 +27,7 @@ SyntaxToken token
);
}
+ ///
public static void ExpectedToken(
string? chunkName,
SourcePosition position,
@@ -35,6 +37,7 @@ SyntaxTokenType token
throw new LuaParseException(chunkName, position, $"{GetTokenTypeText(token)} expected");
}
+ ///
internal static void ExpectedToken(
string? chunkName,
SourcePosition position,
@@ -64,6 +67,7 @@ static string GetTokenTypeText(SyntaxTokenType token)
};
}
+ ///
internal static void ExpectedClosingToken(
string? chunkName,
SourcePosition position,
@@ -99,6 +103,7 @@ static string GetNearTokenText(SyntaxToken? token)
};
}
+ ///
public static void UnfinishedLongComment(string? chunkName, SourcePosition position)
{
throw new LuaParseException(
@@ -108,6 +113,7 @@ public static void UnfinishedLongComment(string? chunkName, SourcePosition posit
);
}
+ ///
public static void SyntaxError(string? chunkName, SourcePosition position, SyntaxToken? token)
{
throw new LuaParseException(
@@ -117,11 +123,13 @@ public static void SyntaxError(string? chunkName, SourcePosition position, Synta
);
}
+ ///
public static void NoVisibleLabel(string label, string? chunkName, SourcePosition position)
{
throw new LuaParseException(chunkName, position, $"no visible label '{label}' for ");
}
+ ///
public static void BreakNotInsideALoop(string? chunkName, SourcePosition position)
{
throw new LuaParseException(chunkName, position, " not inside a loop");
diff --git a/src/Lua/IO/FileSystem.cs b/src/Lua/IO/FileSystem.cs
index 1ac6a27c..7a973211 100644
--- a/src/Lua/IO/FileSystem.cs
+++ b/src/Lua/IO/FileSystem.cs
@@ -47,6 +47,11 @@ public bool IsReadable(string path)
return File.Exists(GetFullPath(path));
}
+ /// The specified path, file name, or both exceed the system-defined maximum length.
+ /// The specified path is invalid, (for example, it is on an unmapped drive).
+ /// An I/O error occurred while opening the file.
+ /// ``path`` specified a file that is read-only and ``access`` is not ``Read``. -or- ``path`` specified a directory. -or- The caller does not have the required permission. -or- ``mode`` is ``System.IO.FileMode.Create`` and the specified file is a hidden file.
+ /// ``path`` is in an invalid format.
public ValueTask Open(
string path,
LuaFileOpenMode openMode,
diff --git a/src/Lua/LuaState.cs b/src/Lua/LuaState.cs
index a8f4b0a5..65285316 100644
--- a/src/Lua/LuaState.cs
+++ b/src/Lua/LuaState.cs
@@ -811,6 +811,8 @@ CancellationToken cancellationToken
/// Loads .NET source text and a .NET chunk name. In byte-string mode, text is
/// encoded as UTF-8. Use the byte overload for source that is already encoded.
///
+ ///
+ /// If the parsing is unsuccessful
public LuaClosure Load(ReadOnlySpan chunk, string chunkName, LuaTable? environment = null)
{
var name = Platform.EncodeText(chunkName);
@@ -859,6 +861,8 @@ internal unsafe LuaClosure LoadCore(
/// Loads encoded source bytes with a .NET chunk name. Byte-string mode preserves
/// the source bytes, except for an initial UTF-8 BOM.
///
+ /// The script contains invalid semantics
+ /// If the parsing is unsuccessful
public LuaClosure Load(
ReadOnlySpan chunk,
string? chunkName = null,
@@ -893,7 +897,7 @@ static bool AllowsMode(string mode, char chunkMode)
{
if (!AllowsMode(mode, 'b'))
{
- throw new Exception("attempt to load a binary chunk (mode is 't')");
+ throw new InvalidOperationException("attempt to load a binary chunk (mode is 't')");
}
return new(this, Parser.Undump(chunk, chunkName, Platform.StringMode), environment);
@@ -902,7 +906,7 @@ static bool AllowsMode(string mode, char chunkMode)
if (!AllowsMode(mode, 't'))
{
- throw new Exception("attempt to load a text chunk (mode is 'b')");
+ throw new InvalidOperationException("attempt to load a text chunk (mode is 'b')");
}
Encoding encoding;
diff --git a/src/Lua/LuaStateExtensions.cs b/src/Lua/LuaStateExtensions.cs
index 747603ac..71066f36 100644
--- a/src/Lua/LuaStateExtensions.cs
+++ b/src/Lua/LuaStateExtensions.cs
@@ -23,7 +23,12 @@ public static LuaClosure Load(this LuaState state, LuaModule module)
: state.Load(module.ReadText(), module.Name);
}
+ // It *could* throw multiple exceptions due to `state.GlobalState.Platform.FileSystem.Open`.
+ // However, these exceptions vary based on the implementing interface, so probably best to
+ // omit them here.
/// Loads a file whose name is .NET text, or standard input when null.
+ ///
+ /// If the parsing is unsuccessful
public static async ValueTask LoadFileAsync(
this LuaState state,
string? fileName,
@@ -173,6 +178,8 @@ public static ValueTask ExecuteAsync(
}
/// Executes a file whose path is .NET text, including in byte-string mode.
+ /// The script contains invalid semantics
+ /// If the parsing is unsuccessful
[AsyncMethodBuilder(typeof(LightAsyncValueTaskMethodBuilder<>))]
public static async ValueTask DoFileAsync(
this LuaState state,
@@ -189,6 +196,7 @@ public static async ValueTask DoFileAsync(
}
/// Executes a file whose path is .NET text, including in byte-string mode.
+ ///
[AsyncMethodBuilder(typeof(LightAsyncValueTaskMethodBuilder<>))]
public static async ValueTask DoFileAsync(
this LuaState state,
diff --git a/src/Lua/LuaValue.cs b/src/Lua/LuaValue.cs
index 0d5ef397..b935645a 100644
--- a/src/Lua/LuaValue.cs
+++ b/src/Lua/LuaValue.cs
@@ -428,6 +428,7 @@ out result
}
}
+ /// If the conversion is not possible.
public T Read()
{
if (!TryRead(out var result))