Class CstNode
One node or token of the concrete syntax tree of a Links Notation document.
Inherited Members
Namespace: Link.Foundation.Links.Notation
Assembly: Link.Foundation.Links.Notation.dll
Syntax
public sealed class CstNode
Remarks
Every character of a document belongs to exactly one token, so the text of the tree is the document itself, comments, blank lines, indentation, quotes and line endings included. A Document holds Line nodes; a line holds the tokens up to and including its line ending, and a parenthesized Group holds its own parentheses and the lines written between them. A group is part of the line it opens on, however many lines it spans. Read a tree with ParseCst(string).
Constructors
| Edit this page View SourceCstNode(CstKind, IEnumerable<CstNode>?)
Creates a node.
Declaration
public CstNode(CstKind kind, IEnumerable<CstNode>? children = null)
Parameters
| Type | Name | Description |
|---|---|---|
| CstKind | kind | A node kind. |
| IEnumerable<CstNode> | children | The node's children, in document order. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
CstNode(CstKind, string, string?, char?)
Creates a token.
Declaration
public CstNode(CstKind kind, string text, string? value = null, char? quote = null)
Parameters
| Type | Name | Description |
|---|---|---|
| CstKind | kind | A token kind. |
| string | text | The token's text exactly as written. |
| string | value | What a reference token means; null otherwise. |
| char? | quote | The delimiter of a quoted reference token; null otherwise. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Properties
| Edit this page View SourceChildren
The children of a node, in document order; empty for a token.
Declaration
public IReadOnlyList<CstNode> Children { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<CstNode> |
IsToken
Whether this is a token rather than a node with children.
Declaration
public bool IsToken { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Kind
The kind of this node or token.
Declaration
public CstKind Kind { get; }
Property Value
| Type | Description |
|---|---|
| CstKind |
Quote
The delimiter a quoted reference token was written between (', " or
`); null for a bare or literal reference and every other kind.
Declaration
public char? Quote { get; }
Property Value
| Type | Description |
|---|---|
| char? |
Text
The exact text this node or token was read from: a token's own text, and the text of its children one after another for a node.
Declaration
public string Text { get; }
Property Value
| Type | Description |
|---|---|
| string |
Value
What a reference token means, its delimiters and escapes resolved: the ID a parsed link has. null for every other node and token.
Declaration
public string? Value { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
| Edit this page View SourceToSExpression()
The tree as an S-expression: (kind child ...) for a node and
kind:"text" for a token, the text with </code>, ", line feeds,
carriage returns and tabs escaped. Every Links Notation implementation writes the
same S-expression for the same document, and two trees are the same exactly when
their S-expressions are.
Declaration
public string ToSExpression()
Returns
| Type | Description |
|---|---|
| string | The S-expression of this subtree. |
Examples
new Parser().ParseCst("a '1'").ToSExpression() is
(document (line reference:"a" whitespace:" " reference:"'1'")).
ToString()
The exact text this node or token was read from; see Text.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | The text of this node or token. |
Overrides
| Edit this page View SourceTokens()
Every token of this subtree, in document order; a token yields just itself.
Declaration
public IReadOnlyList<CstNode> Tokens()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<CstNode> | The tokens of this subtree. |