Parser
Defined in: src/source/parser.ts:159
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
Section titled “Constructors”Constructor
Section titled “Constructor”new Parser(
onNewLine?):Parser
Defined in: src/source/parser.ts:182
Parameters
Section titled “Parameters”onNewLine?
Section titled “onNewLine?”(offset) => void
If defined, called separately with the start position of
each new line (in parse(), including the start of input).
Returns
Section titled “Returns”Parser
Properties
Section titled “Properties”offset
Section titled “offset”offset:
number=0
Defined in: src/source/parser.ts:168
stack:
Token[] =[]
Defined in: src/source/parser.ts:172
Methods
Section titled “Methods”end():
Generator<Token,void>
Defined in: src/source/parser.ts:255
Call at end of input to push out any remaining constructions
Returns
Section titled “Returns”Generator<Token, void>
next()
Section titled “next()”next(
source):Generator<Token,void>
Defined in: src/source/parser.ts:204
Advance the parser by the source of one lexical token.
Parameters
Section titled “Parameters”source
Section titled “source”string
Returns
Section titled “Returns”Generator<Token, void>
parse()
Section titled “parse()”parse(
source,incomplete?):Generator<Token,void>
Defined in: src/source/parser.ts:194
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
Section titled “Parameters”source
Section titled “source”string
incomplete?
Section titled “incomplete?”boolean = false
Returns
Section titled “Returns”Generator<Token, void>
A generator of tokens representing each directive, document, and other structure.