Search Results for

    Show / Hide Table of Contents

    Class Parser

    Parses Links Notation documents into links.

    Inheritance
    object
    Parser
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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 Source

    Parser(bool)

    Creates a parser.

    Declaration
    public Parser(bool comments = true)
    Parameters
    Type Name Description
    bool comments

    When false, # is read as an ordinary character instead of the start of a comment.

    | Edit this page View Source

    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, # is read as an ordinary character instead of the start of a comment.

    int maxDepth

    How deep links may nest; see MaxDepth.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    maxDepth is negative.

    Fields

    | Edit this page View Source

    DefaultMaxDepth

    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 Source

    Comments

    Whether # starts a comment that runs to the end of its line.

    Declaration
    public bool Comments { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    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 Source

    Parse(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.

    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX