(limit = Number.POSITIVE_INFINITY)
| 993 | |
| 994 | // YAML 1.2.2 §9.2. `limit` stops with an error before a document past it starts. |
| 995 | parseStream(limit = Number.POSITIVE_INFINITY): Array<unknown> { |
| 996 | const documents: Array<unknown> = [] |
| 997 | // True at the start of the stream and after a document end marker, where directives and bare documents may start. |
| 998 | let prefix = true |
| 999 | while (true) { |
| 1000 | this.skipIgnored() |
| 1001 | const line = this.lines[this.index] |
| 1002 | if (line === undefined) return documents |
| 1003 | // YAML 1.2.2 §9.1.1: a byte order mark may start any document prefix. |
| 1004 | if (prefix && line.raw.startsWith("\uFEFF")) { |
| 1005 | this.lines[this.index] = makeLine(line.raw.slice(1), line.number) |
| 1006 | continue |
| 1007 | } |
| 1008 | if (isDocumentMarker(line) && !isDocumentStart(line)) { |
| 1009 | if (boundaryContent(line.raw) !== "...") this.fail(line, "Unexpected content after document end marker") |
| 1010 | this.index++ |
| 1011 | prefix = true |
| 1012 | continue |
| 1013 | } |
| 1014 | if (!prefix && !isDocumentStart(line)) this.fail(line, "Unexpected content") |
| 1015 | if (documents.length >= limit) { |
| 1016 | this.fail(line, "Expected a single YAML document, use parseAll to parse a document stream") |
| 1017 | } |
| 1018 | if (prefix && line.indent === 0 && line.text.startsWith("%")) this.parseDirectives() |
| 1019 | this.anchors = new Map() |
| 1020 | this.merges = new MergeBudget() |
| 1021 | documents.push(this.parseDocument()) |
| 1022 | prefix = false |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | // YAML 1.2.2 §6.8: only `%YAML 1.2` is supported, and directives must be followed by `---`. |
| 1027 | private parseDirectives(): void { |
no test coverage detected