Loretta.CodeAnalysis.Lua.Experimental
0.2.7-beta.3
See the version list below for details.
dotnet add package Loretta.CodeAnalysis.Lua.Experimental --version 0.2.7-beta.3
NuGet\Install-Package Loretta.CodeAnalysis.Lua.Experimental -Version 0.2.7-beta.3
<PackageReference Include="Loretta.CodeAnalysis.Lua.Experimental" Version="0.2.7-beta.3" />
<PackageVersion Include="Loretta.CodeAnalysis.Lua.Experimental" Version="0.2.7-beta.3" />
<PackageReference Include="Loretta.CodeAnalysis.Lua.Experimental" />
paket add Loretta.CodeAnalysis.Lua.Experimental --version 0.2.7-beta.3
#r "nuget: Loretta.CodeAnalysis.Lua.Experimental, 0.2.7-beta.3"
#:package Loretta.CodeAnalysis.Lua.Experimental@0.2.7-beta.3
#addin nuget:?package=Loretta.CodeAnalysis.Lua.Experimental&version=0.2.7-beta.3&prerelease
#tool nuget:?package=Loretta.CodeAnalysis.Lua.Experimental&version=0.2.7-beta.3&prerelease
Loretta
A C# (G)Lua lexer, parser, code analysis, transformation and code generation toolkit.
This is (another) rewrite from scratch based on Roslyn and The Complete Syntax of Lua with a few extensions:
- Operators introduced in Garry's Mod Lua (glua):
&&forand;||foror;!=for~=;!fornot;
- Comment types introduced in Garry's Mod Lua (glua):
- C style single line comment:
// ...; - C style multi line comment:
/* */;
- C style single line comment:
- Characters accepted as part of identifiers by LuaJIT (emojis, non-rendering characters, or basically any byte above
127/0x7F); - Roblox compound assignment:
+=,-=,*=,/=,^=,%=,..=; - Lua 5.3 bitwise operators.
Installing Loretta v0.2
We have a MyGet feed with prebuild binaries: https://www.myget.org/gallery/loretta
To use it, add the following feed to your nuget.config: https://www.myget.org/F/loretta/api/v3/index.json
nuget.config example:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="loretta" value="https://www.myget.org/F/loretta/api/v3/index.json" />
</packageSources>
</configuration>
Using Loretta v0.2
Parsing text
- (Optional) Pick a
LuaSyntaxOptionspreset and then create aLuaParseOptionsfrom it. If no preset is picked,LuaSyntaxOptions.Allis used by default; - (Optional) Create a
SourceTextfrom your code (using one of theSourceText.Fromoverloads); - Call
LuaSyntaxTree.ParseTextwith yourSourceText/string, (optional)LuaParseOptions, (optional)pathand (optional)CancellationToken; - Do whatever you want with the returned
LuaSyntaxTree.
Formatting Code
The NormalizeWhitespace method replaces all whitespace and and end of line trivia by normalized (standard code style) ones.
Accessing scope information
If you'd like to get scoping and variable information, create a new Script from your SyntaxTrees and then do one of the following:
- Access
Script.RootScopeto get the global scope; - Call
Script.GetScope(SyntaxNode)orScript.FindScope(SyntaxNode, ScopeKind)to get anIScope; - Call
Script.GetVariable(SyntaxNode)to get anIVariable; - Call
Script.GetLabel(SyntaxNode)on aGotoStatementSyntaxor aGotoLabelStatementSyntaxto get anIGotoLabel;
Using Variables
There are 4 kinds of variables:
VariableKind.Locala variable declared in aLocalVariableDeclarationStatementSyntax;VariableKind.Globala variable used without a previous declaration;VariableKind.Parametera function parameter;VariableKind.Iterationa variable that is an iteration variable from aNumericForLoopSyntaxorGenericForLoopSyntax;
The interface for variables is IVariable which exposes the following information:
IVariable.Kind- TheVariableKind;IVariable.Scope- The containing scope;IVariable.Name- The variable name (might be...for varargs);IVariable.Declaration- The place where the variable was declared (nullfor the implcitargand...variables available in all files and global variables);IVariable.ReferencingScopes- The scopes that have statements that directly reference this variable;IVariable.CapturingScopes- Scopes that capture this variable as an upvalue;IVariable.ReadLocations- Nodes that read from this variable;IVariable.WriteLocations- Nodes that write to this variable;
Using Scopes
There are 4 kinds of scopes:
ScopeKind.Global- There is only one of these, theScript.RootScope. It implementsIScopeand only contains globals;ScopeKind.File- These implementIFileScopeand are the root scopes for files (LuaSyntaxTrees);ScopeKind.Function- These implementIFunctionScopeand are generated for these nodes:AnonymousFunctionExpressionSyntax;LocalFunctionDeclarationStatementSyntax;FunctionDeclarationStatementSyntax.
ScopeKind.Block- These implement onlyIScopeand are generated for normal blocks from these nodes:NumericForStatementSyntax;GenericForStatementSyntax;WhileStatementSyntax;RepeatUntilStatementSyntax;IfStatementSyntax;ElseIfClauseSyntax;ElseClauseSyntax;DoStatementSyntax.
IScope
IScopes are the most basic kind of scope and all other scopes derive from it.
The information exposed by them is:
IScope.Kind- TheScopeKind;IScope.Node- TheSyntaxNodethat originated the scope. Will benullfor global and file scopes;IScope.Parent- The scope's parentIScope. Will benullfor the global scope;IScope.DeclaredVariables- TheIVariables that were declared in this scope;IScope.ReferencedVariables- TheIVariables that are referenced by this scope or its children;IScope.GotoLabels- TheIGotoLabels directly contained by this scope.
IFunctionScope
IFunctionScopes are scopes from function declarations.
They have everything from IScopes and also:
IFunctionScope.Parameters- TheIVariableparameters for this function;IFunctionScope.CapturedVariables- TheIVariables captured as upvalues by this function.
IFileScope
IFileScopes are scopes for entire files (LuaSyntaxTrees).
They have everything from IScopes and also:
IFileScope.ArgVariable- The implicitargvariable available in all lua script files;IFileScope.VarArgParameter- The implicit vararg parameter available in all lua script files.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- Loretta.CodeAnalysis.Lua (>= 0.2.7-beta.3)
-
.NETStandard 2.0
- Loretta.CodeAnalysis.Lua (>= 0.2.7-beta.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.14-nightly.17 | 130 | 10/8/2025 |
| 0.2.14-nightly.15 | 112 | 7/29/2025 |
| 0.2.14-nightly.13 | 476 | 7/24/2025 |
| 0.2.14-nightly.5 | 199 | 4/11/2025 |
| 0.2.14-nightly.4 | 148 | 4/1/2025 |
| 0.2.13 | 260 | 3/31/2025 |
| 0.2.13-nightly.21 | 92 | 3/29/2025 |
| 0.2.13-nightly.19 | 101 | 3/29/2025 |
| 0.2.13-nightly.18 | 459 | 3/26/2025 |
| 0.2.13-nightly.14 | 70 | 3/22/2025 |
| 0.2.13-nightly.13 | 136 | 3/19/2025 |
| 0.2.13-nightly.3 | 143 | 3/18/2025 |
| 0.2.13-nightly.2 | 231 | 9/28/2024 |
| 0.2.13-nightly.1 | 160 | 3/18/2024 |
| 0.2.12 | 504 | 3/10/2024 |
| 0.2.12-nightly.27 | 95 | 3/10/2024 |
| 0.2.12-nightly.24 | 459 | 6/25/2023 |
| 0.2.12-nightly.23 | 198 | 4/13/2023 |
| 0.2.12-nightly.22 | 175 | 4/12/2023 |
| 0.2.11 | 500 | 4/1/2023 |
| 0.2.11-nightly.15 | 176 | 4/1/2023 |
| 0.2.11-nightly.10 | 203 | 11/15/2022 |
| 0.2.11-nightly.5 | 196 | 11/7/2022 |
| 0.2.10 | 511 | 10/25/2022 |
| 0.2.10-nightly.96 | 216 | 10/8/2022 |
| 0.2.10-nightly.94 | 221 | 9/20/2022 |
| 0.2.10-nightly.81 | 218 | 9/19/2022 |
| 0.2.10-nightly.73 | 219 | 9/16/2022 |
| 0.2.9 | 970 | 3/19/2022 |
| 0.2.9-beta.5 | 240 | 3/5/2022 |
| 0.2.9-beta.4 | 226 | 3/3/2022 |
| 0.2.9-beta.3 | 238 | 3/3/2022 |
| 0.2.9-beta.2 | 236 | 2/22/2022 |
| 0.2.9-beta.1 | 235 | 2/18/2022 |
| 0.2.8 | 584 | 2/16/2022 |
| 0.2.7-beta.13 | 532 | 1/27/2022 |
| 0.2.7-beta.12 | 238 | 1/25/2022 |
| 0.2.7-beta.11 | 256 | 1/17/2022 |
| 0.2.7-beta.10 | 246 | 1/12/2022 |
| 0.2.7-beta.9 | 249 | 1/12/2022 |
| 0.2.7-beta.8 | 257 | 1/10/2022 |
| 0.2.7-beta.7 | 249 | 1/4/2022 |
| 0.2.7-beta.6 | 244 | 12/31/2021 |
| 0.2.7-beta.5 | 255 | 12/28/2021 |
| 0.2.7-beta.4 | 270 | 12/13/2021 |
| 0.2.7-beta.3 | 250 | 12/7/2021 |