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


  • Parameters

    • Optional onNewLine: ((offset) => 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


atIndentedComment: any
atNewLine: any

If true, space and sequence indicators count as indentation

atScalar: any

If true, next token is a scalar value

blockMap: any
blockScalar: any
blockSequence: any
document: any
documentEnd: any
flowCollection: any
flowScalar: any
indent: any

Current indentation level

lexer: any
lineEnd: any
offset: number

Current offset since the start of parsing

onKeyLine: any

On the same line with a block map key

onNewLine?: any
peek: any
pop: any
scalar: any
source: any

The source of the current token, set in parse()

stack: yaml.CST.Token[]

Top indicates the node that's currently being built

startBlockValue: any
step: any
stream: any
type: any

The type of the current token, set in parse()


  • get sourceToken(): any
  • Returns any


  • 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.


    • 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.


    • source: string
    • Optional incomplete: boolean

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

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

Generated using TypeDoc