Meziantou.Framework.Language
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package Meziantou.Framework.Language --version 1.0.0
NuGet\Install-Package Meziantou.Framework.Language -Version 1.0.0
<PackageReference Include="Meziantou.Framework.Language" Version="1.0.0" />
<PackageVersion Include="Meziantou.Framework.Language" Version="1.0.0" />
<PackageReference Include="Meziantou.Framework.Language" />
paket add Meziantou.Framework.Language --version 1.0.0
#r "nuget: Meziantou.Framework.Language, 1.0.0"
#:package Meziantou.Framework.Language@1.0.0
#addin nuget:?package=Meziantou.Framework.Language&version=1.0.0
#tool nuget:?package=Meziantou.Framework.Language&version=1.0.0
Meziantou.Framework.Language
Meziantou.Framework.Language holds the primitives the
Meziantou.Framework.Language.* parsers share: source text and its lines, character
spans, text changes, locations, and diagnostics.
It is not useful on its own. It is referenced by
Meziantou.Framework.Language.Json,
Meziantou.Framework.Language.Regex,
Meziantou.Framework.Language.Shell, and
Meziantou.Framework.Language.Xml,
so a span, a text change, or a diagnostic means the same thing whichever of them produced it.
Every type lives in the Meziantou.Framework.Language namespace, the parent of each
parser's own namespace, so a file that already has using Meziantou.Framework.Language.Xml;
resolves TextSpan without a second using directive.
Diagnostics and locations
A diagnostic carries a Location, which pairs the character range with the text it indexes
into, so it can report line and character positions:
using Meziantou.Framework.Language;
using Meziantou.Framework.Language.Xml;
var tree = XmlSyntaxTree.ParseText("<root>\n <item>\n</root>");
foreach (var diagnostic in tree.Diagnostics)
{
Console.WriteLine($"{diagnostic.Id} at {diagnostic.Location}: {diagnostic.Message}");
var lineSpan = diagnostic.Location.GetLineSpan();
Console.WriteLine(lineSpan.Start.Line); // zero-based
Console.WriteLine(lineSpan.Start.Character); // zero-based
}
A diagnostic produced by a parser is always bound to the tree's own text, so
diagnostic.Location.SourceText is the same instance as tree.SourceText. A Location
you build yourself may leave the text out, in which case GetLineSpan() returns default.
Source text and edits
var source = SourceText.From("<root/>");
var updated = source.WithChanges([new TextChange(new TextSpan(1, 4), "item")]);
Console.WriteLine(updated.Text); // <item/>
var line = source.GetLine(position: 3);
Console.WriteLine(line.LineNumber);
WithChanges applies changes from the end of the text backwards, so the spans of the
changes that come earlier in the text stay valid regardless of the order they are passed
in. A change reaching past the end of the text is ignored.
| 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. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Meziantou.Framework.Language:
| Package | Downloads |
|---|---|
|
Meziantou.Framework.Language.Json
A Roslyn-style immutable JSON syntax tree: green and red nodes, trivia, diagnostics, annotations, and editing that keeps the text you did not touch. |
|
|
Meziantou.Framework.Language.Xml
Immutable XML syntax tree with diagnostics, editing helpers, and XPath navigation. |
|
|
Meziantou.Framework.Language.Shell
Immutable, round-trip shell script concrete syntax tree for bash, sh, zsh, PowerShell, PowerShell Core, and cmd, with diagnostics, trivia, source locations, and editing helpers. |
|
|
Meziantou.Framework.Language.Regex
Immutable, round-trip regular-expression pattern concrete syntax tree for .NET, JavaScript, PCRE/Perl, and POSIX ERE/BRE, with diagnostics, trivia, source locations, and editing helpers. |
|
|
Meziantou.Framework.Language.Toml
A Roslyn-style immutable TOML syntax tree with lossless parsing and diagnostics. |
GitHub repositories
This package is not used by any popular GitHub repositories.