Options
All
  • Public
  • Public/Protected
  • All
Menu

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
}

Hierarchy

  • Parser

Index

Constructors

constructor

  • new Parser(onNewLine?: (offset: number) => void): Parser
  • Parameters

    • Optional onNewLine: (offset: number) => void

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

        • (offset: number): void
        • Parameters

          • offset: number

          Returns void

    Returns Parser

Properties

Private atIndentedComment

atIndentedComment: any

Private atNewLine

atNewLine: any

If true, space and sequence indicators count as indentation

Private atScalar

atScalar: any

If true, next token is a scalar value

Private blockMap

blockMap: any

Private blockScalar

blockScalar: any

Private blockSequence

blockSequence: any

Private document

document: any

Private documentEnd

documentEnd: any

Private flowCollection

flowCollection: any

Private flowScalar

flowScalar: any

Private indent

indent: any

Current indentation level

Private lexer

lexer: any

Private lineEnd

lineEnd: any

offset

offset: number

Current offset since the start of parsing

Private onKeyLine

onKeyLine: any

On the same line with a block map key

Private Optional onNewLine

onNewLine?: any

Private peek

peek: any

Private pop

pop: any

Private scalar

scalar: any

Private source

source: any

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

stack

stack: Token[]

Top indicates the node that's currently being built

Private startBlockValue

startBlockValue: any

Private step

step: any

Private stream

stream: any

Private type

type: any

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

Accessors

Private sourceToken

  • get sourceToken(): any
  • Returns any

Methods

end

  • end(): Generator<Token, void, unknown>
  • Call at end of input to push out any remaining constructions

    Returns Generator<Token, void, unknown>

next

  • next(source: string): Generator<Token, void, unknown>
  • Advance the parser by the source of one lexical token.

    Parameters

    • source: string

    Returns Generator<Token, void, unknown>

parse

  • parse(source: string, incomplete?: boolean): Generator<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<Token, void, unknown>

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

Generated using TypeDoc