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

  • 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

Properties

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()

Accessors

  • get sourceToken(): any
  • Returns any

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
    • Optional incomplete: boolean

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

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

Generated using TypeDoc