MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseStream

Method parseStream

packages/effect/src/encoding/Yaml.ts:995–1024  ·  view source on GitHub ↗
(limit = Number.POSITIVE_INFINITY)

Source from the content-addressed store, hash-verified

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 {

Callers 2

parseFunction · 0.80
parseAllFunction · 0.80

Calls 10

skipIgnoredMethod · 0.95
failMethod · 0.95
parseDirectivesMethod · 0.95
parseDocumentMethod · 0.95
makeLineFunction · 0.85
isDocumentMarkerFunction · 0.85
isDocumentStartFunction · 0.85
boundaryContentFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected