Loom.Parser.Lua
2.0.0
dotnet add package Loom.Parser.Lua --version 2.0.0
NuGet\Install-Package Loom.Parser.Lua -Version 2.0.0
<PackageReference Include="Loom.Parser.Lua" Version="2.0.0" />
<PackageVersion Include="Loom.Parser.Lua" Version="2.0.0" />
<PackageReference Include="Loom.Parser.Lua" />
paket add Loom.Parser.Lua --version 2.0.0
#r "nuget: Loom.Parser.Lua, 2.0.0"
#:package Loom.Parser.Lua@2.0.0
#addin nuget:?package=Loom.Parser.Lua&version=2.0.0
#tool nuget:?package=Loom.Parser.Lua&version=2.0.0
This parser was written due to my belief that existing, modern day Lua parsers are way too boilerplate to interact with.
Loom Parser
Loom parser is a robust recursive-descent / precedence Lua parser designed to make transforming of AST easy.
The end goal is a parser with AST you can easily interact with.
This parser is experimental, do not take the output for granted just yet.
Usage
Example
using Loom.Lua.Parser.ASTGenerator;
using Loom.Lua.Parser.ASTGenerator.AST.Statements;
using Loom.Lua.Parser.Lexer;
using Loom.Lua.Parser.Lexer.Objects;
using Loom.Lua.Parser.Preprocessor;
using Loom.Lua.Parser.PrettyPrint;
// ...
string script = File.ReadAllText("Tests\\Sample.lua");
LexicalAnalyser codeLexer = new LexicalAnalyser(script);
LexTokenList lexTokens = codeLexer.Analyze();
Preprocessor preProcessor = new Preprocessor(lexTokens);
lexTokens = preProcessor.Process();
ASTGenerator astGenerator = new ASTGenerator(lexTokens);
StatementList statements = astGenerator.ParseStatements();
PrettyPrinter prettyPrinter = new PrettyPrinter(PrettyPrinterSettings.Minify);
Console.WriteLine(prettyPrinter.Print(statements));
Supported syntax
Statements
- Locals
- Functions
- Variables
- Assignments
- Multiple assignments
- Function declarations
- If .. then
- While .. do
- Return
- For .. do
- Repeat .. until
- Do
- Break
- Continue
- Calls
- Locals
Expressions
- Ternary (if true then "hello" else "goodbye")
- Grouped
- Negative (E.g -10)
- Length (E.g #table)
- Not (E.g not true)
- Nil
- Function declaration (e.g function(...) print(...) end)
- Identifier (E.g print)
- Vararg (E.g ...)
- Constant (E.g 123, "hello")
- Array and records (E.g {["this"] = "hi"})
- Call (E.g math.pow(5, 5))
- Index (E.g table[1])
- Relational (E.g 4 > 3)
- Arithmetic (E.g 2 + 2)
- Logical (E.g and, or, not)
- Concat (E.g "Hello " .. "world")
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Tools.GeneralTK (>= 1.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Changed the namespace Loom to Loom.Lua, reverted to old parsing method - now complete and stable for Lua 5.1.