Parser

public enum Parser : Sendable

Notes:

Be careful when writing rules that start with an optional symbol that may be recognized at the beginning of the following construct. A naive combinator may not be able to backtrack. For example:

let p0 = maybe(foo.and(bar)).and(ham)
let p1 = foo.and(bar).or(ham)

Both p0 and p1 will fail to recognize inputs recognized by ham if foo can recognize the same prefix, as the latter will throw a committing failure it applies bar rather than backtracking. A correct definition is:

let p2 = attempt(foo.and(bar)).or(foo)

A namespace for the routines of Hylo’s parser.

  • Parses the contents of input as a translation unit, registering the identities of newly formed ASTs in space k and reporting errors to diagnostics.

    Throws

    Diagnostics if syntax errors were encountered.

    Declaration

    Swift

    public static func parse(
      _ input: SourceFile,
      inNodeSpace k: Int,
      in ast: inout AST,
      diagnostics: inout DiagnosticSet
    ) throws -> TranslationUnit.ID
  • Fails the parsing of the expected construct with the given diagnostic.

    Declaration

    Swift

    private static func fail(_ d: Diagnostic) throws -> Never
  • Fails the parsing of the expected construct with the given diagnostics.

    Declaration

    Swift

    private static func fail<C>(_ ds: C) throws -> Never where C : Collection, C.Element == Diagnostic

Declarations

Expressions

Comma-separated lists

Patterns

Statements

Type expressions

Attributes