SweetLine 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SweetLine --version 1.1.1
                    
NuGet\Install-Package SweetLine -Version 1.1.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="SweetLine" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SweetLine" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="SweetLine" />
                    
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 SweetLine --version 1.1.1
                    
#r "nuget: SweetLine, 1.1.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 SweetLine@1.1.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=SweetLine&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=SweetLine&version=1.1.1
                    
Install as a Cake Tool

SweetLine for .NET

SweetLine is a high-performance syntax highlighting and code structure analysis engine. This package provides the C# binding over the SweetLine native core via P/Invoke.

Features

  • Full-text highlighting (TextAnalyzer.AnalyzeText)
  • Single-line highlighting (TextAnalyzer.AnalyzeLine)
  • Incremental highlighting with managed document (DocumentAnalyzer)
  • Visible-range incremental slice (DocumentAnalyzer.AnalyzeIncrementalInLineRange)
  • Scope and indent guide analysis (AnalyzeIndentGuides)
  • Preprocessor macro support (DefineMacro / UndefineMacro)
  • Style-ID and inline-style output modes (HighlightConfig)
  • Syntax loading from JSON string or file, with file-extension lookup

Install

dotnet add package SweetLine

Quick Start

using SweetLine;

// 1. Create engine (optionally enable character index or inline style)
var config = new HighlightConfig(ShowIndex: true, InlineStyle: false);
using var engine = new HighlightEngine(config);

// 2. Register style name -> ID mapping
engine.RegisterStyleName("keyword", 1);
engine.RegisterStyleName("string",  2);
engine.RegisterStyleName("comment", 3);

// 3. Compile syntax rules
engine.CompileSyntaxFromFile("syntaxes/csharp.json");
// or: engine.CompileSyntaxFromJson(jsonString);

// 4. Full-text analysis (stateless)
TextAnalyzer? textAnalyzer = engine.CreateAnalyzerByName("csharp");
// or: engine.CreateAnalyzerByExtension(".cs");
if (textAnalyzer != null)
{
    DocumentHighlight result = textAnalyzer.AnalyzeText("public class Demo {}");
    IndentGuideResult guides = textAnalyzer.AnalyzeIndentGuides("public class Demo {}");
}

Managed Document (Incremental)

// Create a managed document for incremental updates
using var document = new Document("file:///example.cs", sourceText);
DocumentAnalyzer? analyzer = engine.LoadDocument(document);

// Full analysis
DocumentHighlight highlight = analyzer!.Analyze();

// After an edit, run incremental analysis
var editRange = new TextRange(
    new TextPosition(Line: 2, Column: 4),
    new TextPosition(Line: 2, Column: 8));

DocumentHighlight updated = analyzer.AnalyzeIncremental(editRange, "newText");

// Or get only the visible slice (better for large files)
DocumentHighlightSlice slice = analyzer.AnalyzeIncrementalInLineRange(
    editRange, "newText",
    new LineRange(StartLine: 0, LineCount: 80));

// Indent guide analysis on managed document
IndentGuideResult guides = analyzer.AnalyzeIndentGuides();

Single-Line Analysis

// Useful for editor viewports that process one line at a time
var lineInfo = new TextLineInfo(Line: 0, StartState: 0, StartCharOffset: 0);
LineAnalyzeResult lineResult = textAnalyzer!.AnalyzeLine("int x = 42;", lineInfo);

// lineResult.Highlight  — token spans for this line
// lineResult.EndState   — feed into next line's StartState
// lineResult.CharCount  — characters consumed

Preprocessor Macros

// Define/undefine macros for #ifdef conditional compilation in syntax rules
engine.DefineMacro("FEATURE_X");
engine.UndefineMacro("FEATURE_X");

Output Models

Type Description
DocumentHighlight Full document: list of LineHighlight per line
DocumentHighlightSlice Partial result with StartLine, TotalLineCount, and line slice
LineHighlight List of TokenSpan for one line
TokenSpan Range + StyleId (or InlineStyle when enabled)
IndentGuideResult GuideLines (vertical segments with branches) + LineStates
LineAnalyzeResult Single-line highlight + EndState + CharCount

Native Library

Bundled: runtimes/win-x64/native/sweetline.dll

Native resolver search order:

  1. SWEETLINE_LIB_PATH environment variable (file or directory)
  2. App base directory / current directory
  3. runtimes/{rid}/native/ folders and common build output paths
  4. System default loader

Override if needed:

$env:SWEETLINE_LIB_PATH = "C:\path\to\native"

Requirements

  • .NET 8.0+
  • Windows x64 (bundled native binary)

Pack and Publish

# Build native library first (cmake-build-release-visual-studio/bin/sweetline.dll)

# Pack
dotnet pack platform/CSharp/SweetLine/SweetLine.csproj -c Release -o artifacts/nuget /p:PackageVersion=1.1.1

# Push
dotnet nuget push artifacts/nuget/SweetLine.1.1.1.nupkg \
  --api-key $NUGET_API_KEY \
  --source https://api.nuget.org/v3/index.json \
  --skip-duplicate
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.
  • net8.0

    • No dependencies.

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
1.2.4 92 5/10/2026
1.2.2 107 4/18/2026
1.2.1 106 4/12/2026
1.2.0 128 3/28/2026
1.1.1 104 3/25/2026
1.1.0 99 3/22/2026
1.0.0 98 3/21/2026