Loretta.CodeAnalysis.Common 0.2.7-beta.3

This is a prerelease version of Loretta.CodeAnalysis.Common.
There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Loretta.CodeAnalysis.Common" Version="0.2.7-beta.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Loretta.CodeAnalysis.Common --version 0.2.7-beta.3                
#r "nuget: Loretta.CodeAnalysis.Common, 0.2.7-beta.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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:

  1. Operators introduced in Garry's Mod Lua (glua):
    • && for and;
    • || for or;
    • != for ~=;
    • ! for not;
  2. Comment types introduced in Garry's Mod Lua (glua):
    • C style single line comment: // ...;
    • C style multi line comment: /* */;
  3. Characters accepted as part of identifiers by LuaJIT (emojis, non-rendering characters, or basically any byte above 127/0x7F);
  4. Roblox compound assignment: +=, -=, *=, /=, ^=, %=, ..=;
  5. 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

  1. (Optional) Pick a LuaSyntaxOptions preset and then create a LuaParseOptions from it. If no preset is picked, LuaSyntaxOptions.All is used by default;
  2. (Optional) Create a SourceText from your code (using one of the SourceText.From overloads);
  3. Call LuaSyntaxTree.ParseText with your SourceText/string, (optional) LuaParseOptions, (optional) path and (optional) CancellationToken;
  4. 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:

Using Variables

There are 4 kinds of variables:

  • VariableKind.Local a variable declared in a LocalVariableDeclarationStatementSyntax;
  • VariableKind.Global a variable used without a previous declaration;
  • VariableKind.Parameter a function parameter;
  • VariableKind.Iteration a variable that is an iteration variable from a NumericForLoopSyntax or GenericForLoopSyntax;

The interface for variables is IVariable which exposes the following information:

  • IVariable.Kind- The VariableKind;
  • 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 implcit arg 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, the Script.RootScope. It implements IScope and only contains globals;
  • ScopeKind.File - These implement IFileScope and are the root scopes for files (LuaSyntaxTrees);
  • ScopeKind.Function - These implement IFunctionScope and are generated for these nodes:
    • AnonymousFunctionExpressionSyntax;
    • LocalFunctionDeclarationStatementSyntax;
    • FunctionDeclarationStatementSyntax.
  • ScopeKind.Block - These implement only IScope and 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 - The ScopeKind;
  • IScope.Node - The SyntaxNode that originated the scope. Will be null for global and file scopes;
  • IScope.Parent - The scope's parent IScope. Will be null for the global scope;
  • IScope.DeclaredVariables - The IVariables that were declared in this scope;
  • IScope.ReferencedVariables - The IVariables that are referenced by this scope or its children;
  • IScope.GotoLabels - The IGotoLabels directly contained by this scope.
IFunctionScope

IFunctionScopes are scopes from function declarations. They have everything from IScopes and also:

  • IFunctionScope.Parameters - The IVariable parameters for this function;
  • IFunctionScope.CapturedVariables - The IVariables captured as upvalues by this function.
IFileScope

IFileScopes are scopes for entire files (LuaSyntaxTrees). They have everything from IScopes and also:

  • IFileScope.ArgVariable - The implicit arg variable available in all lua script files;
  • IFileScope.VarArgParameter - The implicit vararg parameter available in all lua script files.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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