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" />
paket add Loretta.CodeAnalysis.Lua.Experimental --version 0.2.7-beta.3
#r "nuget: Loretta.CodeAnalysis.Lua.Experimental, 0.2.7-beta.3"
// Install Loretta.CodeAnalysis.Lua.Experimental as a Cake Addin #addin nuget:?package=Loretta.CodeAnalysis.Lua.Experimental&version=0.2.7-beta.3&prerelease // Install Loretta.CodeAnalysis.Lua.Experimental as a Cake Tool #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
LuaSyntaxOptions
preset and then create aLuaParseOptions
from it. If no preset is picked,LuaSyntaxOptions.All
is used by default; - (Optional) Create a
SourceText
from your code (using one of theSourceText.From
overloads); - Call
LuaSyntaxTree.ParseText
with yourSourceText
/string
, (optional)LuaParseOptions
, (optional)path
and (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 SyntaxTree
s and then do one of the following:
- Access
Script.RootScope
to 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 aGotoStatementSyntax
or aGotoLabelStatementSyntax
to get anIGotoLabel
;
Using Variables
There are 4 kinds of variables:
VariableKind.Local
a variable declared in aLocalVariableDeclarationStatementSyntax
;VariableKind.Global
a variable used without a previous declaration;VariableKind.Parameter
a function parameter;VariableKind.Iteration
a variable that is an iteration variable from aNumericForLoopSyntax
orGenericForLoopSyntax
;
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 (null
for the implcitarg
and...
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 implementsIScope
and only contains globals;ScopeKind.File
- These implementIFileScope
and are the root scopes for files (LuaSyntaxTree
s);ScopeKind.Function
- These implementIFunctionScope
and are generated for these nodes:AnonymousFunctionExpressionSyntax
;LocalFunctionDeclarationStatementSyntax
;FunctionDeclarationStatementSyntax
.
ScopeKind.Block
- These implement onlyIScope
and are generated for normal blocks from these nodes:NumericForStatementSyntax
;GenericForStatementSyntax
;WhileStatementSyntax
;RepeatUntilStatementSyntax
;IfStatementSyntax
;ElseIfClauseSyntax
;ElseClauseSyntax
;DoStatementSyntax
.
IScope
IScope
s 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
- TheSyntaxNode
that originated the scope. Will benull
for global and file scopes;IScope.Parent
- The scope's parentIScope
. Will benull
for the global scope;IScope.DeclaredVariables
- TheIVariable
s that were declared in this scope;IScope.ReferencedVariables
- TheIVariable
s that are referenced by this scope or its children;IScope.GotoLabels
- TheIGotoLabel
s directly contained by this scope.
IFunctionScope
IFunctionScope
s are scopes from function declarations.
They have everything from IScope
s and also:
IFunctionScope.Parameters
- TheIVariable
parameters for this function;IFunctionScope.CapturedVariables
- TheIVariable
s captured as upvalues by this function.
IFileScope
IFileScope
s are scopes for entire files (LuaSyntaxTree
s).
They have everything from IScope
s and also:
IFileScope.ArgVariable
- The implicitarg
variable 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. |
.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.13-nightly.2 | 53 | 9/28/2024 |
0.2.13-nightly.1 | 114 | 3/18/2024 |
0.2.12 | 290 | 3/10/2024 |
0.2.12-nightly.27 | 62 | 3/10/2024 |
0.2.12-nightly.24 | 201 | 6/25/2023 |
0.2.12-nightly.23 | 122 | 4/13/2023 |
0.2.12-nightly.22 | 96 | 4/12/2023 |
0.2.11 | 344 | 4/1/2023 |
0.2.11-nightly.15 | 104 | 4/1/2023 |
0.2.11-nightly.10 | 118 | 11/15/2022 |
0.2.11-nightly.5 | 112 | 11/7/2022 |
0.2.10 | 411 | 10/25/2022 |
0.2.10-nightly.96 | 120 | 10/8/2022 |
0.2.10-nightly.94 | 143 | 9/20/2022 |
0.2.10-nightly.81 | 133 | 9/19/2022 |
0.2.10-nightly.73 | 131 | 9/16/2022 |
0.2.9 | 777 | 3/19/2022 |
0.2.9-beta.5 | 143 | 3/5/2022 |
0.2.9-beta.4 | 125 | 3/3/2022 |
0.2.9-beta.3 | 135 | 3/3/2022 |
0.2.9-beta.2 | 132 | 2/22/2022 |
0.2.9-beta.1 | 128 | 2/18/2022 |
0.2.8 | 456 | 2/16/2022 |
0.2.7-beta.13 | 429 | 1/27/2022 |
0.2.7-beta.12 | 132 | 1/25/2022 |
0.2.7-beta.11 | 149 | 1/17/2022 |
0.2.7-beta.10 | 143 | 1/12/2022 |
0.2.7-beta.9 | 138 | 1/12/2022 |
0.2.7-beta.8 | 146 | 1/10/2022 |
0.2.7-beta.7 | 140 | 1/4/2022 |
0.2.7-beta.6 | 138 | 12/31/2021 |
0.2.7-beta.5 | 141 | 12/28/2021 |
0.2.7-beta.4 | 164 | 12/13/2021 |
0.2.7-beta.3 | 145 | 12/7/2021 |