Loretta.CodeAnalysis.Common
0.2.7-beta.3
See the version list below for details.
dotnet add package Loretta.CodeAnalysis.Common --version 0.2.7-beta.3
NuGet\Install-Package Loretta.CodeAnalysis.Common -Version 0.2.7-beta.3
<PackageReference Include="Loretta.CodeAnalysis.Common" Version="0.2.7-beta.3" />
paket add Loretta.CodeAnalysis.Common --version 0.2.7-beta.3
#r "nuget: Loretta.CodeAnalysis.Common, 0.2.7-beta.3"
// Install Loretta.CodeAnalysis.Common as a Cake Addin #addin nuget:?package=Loretta.CodeAnalysis.Common&version=0.2.7-beta.3&prerelease // Install Loretta.CodeAnalysis.Common as a Cake Tool #tool nuget:?package=Loretta.CodeAnalysis.Common&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
- System.Text.Encoding.CodePages (>= 4.5.1)
-
.NETStandard 2.0
- Microsoft.Bcl.HashCode (>= 1.1.1)
- System.Collections.Immutable (>= 5.0.0)
- System.Memory (>= 4.5.4)
- System.Runtime.CompilerServices.Unsafe (>= 5.0.0)
- System.Text.Encoding.CodePages (>= 4.5.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Loretta.CodeAnalysis.Common:
Package | Downloads |
---|---|
Loretta.CodeAnalysis.Lua
A GLua/Lua lexer, parser, code analysis, transformation and generation library. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.2.13-nightly.2 | 88 | 9/28/2024 |
0.2.13-nightly.1 | 129 | 3/18/2024 |
0.2.12 | 2,741 | 3/10/2024 |
0.2.12-nightly.27 | 60 | 3/10/2024 |
0.2.12-nightly.24 | 226 | 6/25/2023 |
0.2.12-nightly.23 | 130 | 4/13/2023 |
0.2.12-nightly.22 | 97 | 4/12/2023 |
0.2.11 | 856 | 4/1/2023 |
0.2.11-nightly.15 | 104 | 4/1/2023 |
0.2.11-nightly.10 | 210 | 11/15/2022 |
0.2.11-nightly.5 | 131 | 11/7/2022 |
0.2.10 | 948 | 10/25/2022 |
0.2.10-nightly.96 | 289 | 10/8/2022 |
0.2.10-nightly.94 | 147 | 9/20/2022 |
0.2.10-nightly.81 | 147 | 9/19/2022 |
0.2.10-nightly.73 | 135 | 9/16/2022 |
0.2.9 | 1,404 | 3/19/2022 |
0.2.9-beta.5 | 146 | 3/5/2022 |
0.2.9-beta.4 | 127 | 3/3/2022 |
0.2.9-beta.3 | 143 | 3/3/2022 |
0.2.9-beta.2 | 132 | 2/22/2022 |
0.2.9-beta.1 | 140 | 2/18/2022 |
0.2.8 | 1,011 | 2/16/2022 |
0.2.7-beta.13 | 444 | 1/27/2022 |
0.2.7-beta.12 | 147 | 1/25/2022 |
0.2.7-beta.11 | 157 | 1/17/2022 |
0.2.7-beta.10 | 145 | 1/12/2022 |
0.2.7-beta.9 | 148 | 1/12/2022 |
0.2.7-beta.8 | 144 | 1/10/2022 |
0.2.7-beta.7 | 153 | 1/4/2022 |
0.2.7-beta.6 | 139 | 12/31/2021 |
0.2.7-beta.5 | 141 | 12/28/2021 |
0.2.7-beta.4 | 169 | 12/13/2021 |
0.2.7-beta.3 | 147 | 12/7/2021 |