War3Net.CodeAnalysis 6.0.1

dotnet add package War3Net.CodeAnalysis --version 6.0.1
                    
NuGet\Install-Package War3Net.CodeAnalysis -Version 6.0.1
                    
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="War3Net.CodeAnalysis" Version="6.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="War3Net.CodeAnalysis" Version="6.0.1" />
                    
Directory.Packages.props
<PackageReference Include="War3Net.CodeAnalysis" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add War3Net.CodeAnalysis --version 6.0.1
                    
#r "nuget: War3Net.CodeAnalysis, 6.0.1"
                    
#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.
#:package War3Net.CodeAnalysis@6.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=War3Net.CodeAnalysis&version=6.0.1
                    
Install as a Cake Addin
#tool nuget:?package=War3Net.CodeAnalysis&version=6.0.1
                    
Install as a Cake Tool

War3Net.CodeAnalysis

About

War3Net.CodeAnalysis is a library providing helper methods and extension methods for Pidgin parsers, along with utility classes for code generation. It simplifies the creation of complex recursive parsers for domain-specific languages and provides tools for generating properly formatted source code output. It is part of the War3Net modding library.

Key features

  • Parse separated lists (e.g., comma-separated arguments) while preserving separator tokens
  • Parse if/elseif/else/endif block structures with trivia preservation
  • Parse block constructs with open/close tokens (e.g., loops, function bodies)
  • Generate indented source code output with automatic indentation management
  • Immutable data structures for representing parsed syntax lists

How to Use

Parse a comma-separated list

using Pidgin;
using War3Net.CodeAnalysis;

// Define your item and separator parsers
Parser<char, Expression> expressionParser = /* your expression parser */;
Parser<char, char> commaParser = Parser.Char(',');

// Create a separated list parser
Parser<char, SeparatedSyntaxList<Expression, char>> argumentListParser =
    expressionParser.SeparatedList(commaParser);

// Parse input
var result = argumentListParser.Parse("a, b, c");
SeparatedSyntaxList<Expression, char> arguments = result.Value;

// Access items and separators
foreach (var item in arguments.Items)
{
    // Process each expression
}

Parse block structures with UntilWithLeading

using Pidgin;
using War3Net.CodeAnalysis;

// Parse items between open and close tokens (e.g., loop/endloop)
Parser<char, LoopStatement> loopParser = statementParser.UntilWithLeading(
    triviaParser,           // Parser for leading whitespace/comments
    loopKeywordParser,      // Open token parser
    endLoopKeywordParser,   // Close token parser
    (trivia, stmt) => stmt.WithLeadingTrivia(trivia),
    (loopToken, statements, trivia, endLoopToken) =>
        new LoopStatement(loopToken, statements, trivia, endLoopToken));

Build a separated syntax list manually

using War3Net.CodeAnalysis;

// Create a builder with the first item
var builder = SeparatedSyntaxList<string, char>.CreateBuilder("first");

// Add more items with separators
builder.Add(',', "second");
builder.Add(',', "third");

// Build the immutable list
SeparatedSyntaxList<string, char> list = builder.ToSeparatedSyntaxList();

Generate indented source code

using System.IO;
using War3Net.CodeAnalysis;

using var stringWriter = new StringWriter();
using var writer = new IndentedTextWriter(stringWriter);

writer.WriteLine("function Main()");
writer.Indent();
writer.WriteLine("local x = 1");
writer.WriteLine("call DoSomething(x)");
writer.Unindent();
writer.WriteLine("endfunction");

string output = stringWriter.ToString();
// Output:
// function Main()
//     local x = 1
//     call DoSomething(x)
// endfunction

Note: For rendering JASS code, avoid writing strings manually as shown above. Instead, use War3Net.CodeAnalysis.Jass.Extensions.IndentedTextWriterExtensions which provides convenience extension methods that handle indentation for you automatically. See the War3Net.CodeAnalysis.Jass package for details.

Main Types

The main types provided by this library are:

  • War3Net.CodeAnalysis.ParserExtensions - Extension methods for Pidgin parsers (SeparatedList, IfThenElse, UntilWithLeading)
  • War3Net.CodeAnalysis.SeparatedSyntaxList<TItem, TSeparator> - Immutable list of items with separators between them
  • War3Net.CodeAnalysis.SeparatedSyntaxList<TItem, TSeparator>.Builder - Builder for incrementally constructing separated syntax lists
  • War3Net.CodeAnalysis.IndentedTextWriter - TextWriter that automatically handles indentation

Feedback and contributing

War3Net.CodeAnalysis is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Disclaimer

This README was generated with the assistance of AI and may contain inaccuracies. Please verify the information and consult the source code for authoritative details.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
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 War3Net.CodeAnalysis:

Package Downloads
War3Net.CodeAnalysis.Jass

Parse and render JASS source files.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.1 0 2/1/2026
6.0.0 236 1/25/2026
5.8.0 893 9/6/2025
5.6.1 7,717 1/7/2023
5.6.0 1,291 12/20/2022
5.5.5 3,209 11/13/2022
5.5.3 1,582 10/29/2022
5.5.2 1,411 10/25/2022
5.5.0 2,519 8/20/2022