Class Parser
Parses Links Notation documents into links.
Inherited Members
Namespace: Link.Foundation.Links.Notation
Assembly: Link.Foundation.Links.Notation.dll
Syntax
public class Parser
Remarks
The rules live in Parser.peg and are compiled into
Link.Foundation.Links.Notation.GeneratedParser; this class runs them and, when a document does not
parse, reports the position the parser stopped at instead of the bare
FormatException the generated parser raises.
Constructors
| Edit this page View SourceParser(bool)
Creates a parser.
Declaration
public Parser(bool comments = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | comments | When false, |
Parser(bool, int)
Creates a parser that refuses links nested deeper than maxDepth.
Declaration
public Parser(bool comments, int maxDepth)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | comments | When false, |
| int | maxDepth | How deep links may nest; see MaxDepth. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Fields
| Edit this page View SourceDefaultMaxDepth
How deep links may nest when nothing says otherwise.
Declaration
public const int DefaultMaxDepth = 64
Field Value
| Type | Description |
|---|---|
| int |
Remarks
The parser recurses once per level of nesting, and running out of stack ends the process where no caller can catch it. The limit is set well below what fits in a 1 MiB thread stack, and it is the same in every Links Notation implementation, so a document one of them reads is not too deep for another.
Properties
| Edit this page View SourceComments
Whether # starts a comment that runs to the end of its line.
Declaration
public bool Comments { get; }
Property Value
| Type | Description |
|---|---|
| bool |
MaxDepth
How deep links may nest. Every parenthesized group and every indentation level
is one level, and the lines of a document are at level 0, so with a limit of 1
(a) parses while ((a)), (a (b)) and a group on an indented
line do not. A document nested deeper is refused with a
ParseException whose MaxDepth is set,
rather than recursed into until the stack runs out.
Declaration
public int MaxDepth { get; init; }
Property Value
| Type | Description |
|---|---|
| int |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is negative. |
Methods
| Edit this page View SourceParse(string, string?)
Parses a Links Notation document.
Declaration
public IList<Link<string>> Parse(string subject, string? fileName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | subject | The document to parse. |
| string | fileName | The optional file name to use in error messages. |
Returns
| Type | Description |
|---|---|
| IList<Link<string>> | The links the document holds. |
Exceptions
| Type | Condition |
|---|---|
| ParseException | Thrown when the document does not parse, or nests deeper than MaxDepth. The exception carries the line, the column and the offending line of the position the parser stopped at. |