A YAML concrete syntax tree (CST) parser

const src: string = ...
for (const token of new Parser().parse(src)) {
// token: Token
}

To use the parser with a user-provided lexer:

function* parse(source: string, lexer: Lexer) {
const parser = new Parser()
for (const lexeme of lexer.lex(source))
yield* parser.next(lexeme)
yield* parser.end()
}

const src: string = ...
const lexer = new Lexer()
for (const token of parse(src, lexer)) {
// token: Token
}

Constructors

Properties

Methods

Constructors

  • Parameters

    • OptionalonNewLine: ((offset: number) => void)

      If defined, called separately with the start position of each new line (in parse(), including the start of input).

        • (offset): void
        • Parameters

          • offset: number

          Returns void

    Returns Parser

Properties

offset: number

Current offset since the start of parsing

stack: yaml.CST.Token[]

Top indicates the node that's currently being built

Methods

  • Call at end of input to push out any remaining constructions

    Returns Generator<yaml.CST.Token, void, unknown>

  • Advance the parser by the source of one lexical token.

    Parameters

    • source: string

    Returns Generator<yaml.CST.Token, void, unknown>

  • Parse source as a YAML stream. If incomplete, a part of the last line may be left as a buffer for the next call.

    Errors are not thrown, but yielded as { type: 'error', message } tokens.

    Parameters

    • source: string
    • Optionalincomplete: boolean

    Returns Generator<yaml.CST.Token, void, unknown>

    A generator of tokens representing each directive, document, and other structure.