Table of Contents

Class DocumentSyntax

Namespace
Icy.Design.Syntax
Assembly
IcyUI.Design.dll

The span-preserving syntax tree of one markup text.

public sealed class DocumentSyntax
Inheritance
DocumentSyntax
Inherited Members
Extension Methods

Remarks

Every character of Text belongs to exactly one node in Nodes or below, so the tree reproduces the text byte for byte, comments, formatting and entities included.

Parsing never throws. Malformed text produces Diagnostics, and the offending characters are kept as TextSyntax nodes.

Properties

Diagnostics

Gets the problems found while parsing; empty for well-formed markup.

public IReadOnlyList<Diagnostic> Diagnostics { get; }

Property Value

IReadOnlyList<Diagnostic>

Elements

Gets every element under Root, the root first, in document order.

public IEnumerable<ElementSyntax> Elements { get; }

Property Value

IEnumerable<ElementSyntax>

HasErrors

Gets a value indicating whether Diagnostics is non-empty.

public bool HasErrors { get; }

Property Value

bool

Nodes

Gets the top-level nodes: the root element and any whitespace, comments and processing instructions around it.

public IReadOnlyList<MarkupSyntaxNode> Nodes { get; }

Property Value

IReadOnlyList<MarkupSyntaxNode>

Root

Gets the root element, or null when the text has none.

public ElementSyntax? Root { get; }

Property Value

ElementSyntax

Text

Gets the text the tree was parsed from.

public string Text { get; }

Property Value

string

Methods

FindElementAt(int)

Finds the element whose start tag begins (its <) at start.

public ElementSyntax? FindElementAt(int start)

Parameters

start int

The offset of the element's <.

Returns

ElementSyntax

The element, or null when none starts there.

GetNamespacesInScope(ElementSyntax, bool)

Collects the namespace declarations in effect for element, keyed by prefix (the empty string for the default namespace).

public IReadOnlyDictionary<string, string> GetNamespacesInScope(ElementSyntax element, bool includeSelf = false)

Parameters

element ElementSyntax

The element to collect for.

includeSelf bool

true to include element's own declarations; false to collect only what it inherits from its ancestors.

Returns

IReadOnlyDictionary<string, string>

The declarations, an inner declaration hiding an outer one with the same prefix.

Parse(string)

Parses text.

public static DocumentSyntax Parse(string text)

Parameters

text string

The markup text.

Returns

DocumentSyntax

The syntax tree.

Exceptions

ArgumentNullException

text is null.

ResolvePrefix(ElementSyntax, string)

Resolves a namespace prefix the way the markup loader does, including its predeclared x prefix.

public string? ResolvePrefix(ElementSyntax element, string prefix)

Parameters

element ElementSyntax

The element the prefix is used on.

prefix string

The prefix, or an empty string for the default namespace.

Returns

string

The namespace URI, or null when the prefix isn't declared.