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

Method readPlain

packages/effect/src/encoding/Yaml.ts:658–679  ·  view source on GitHub ↗
(stop: (code: number) => boolean)

Source from the content-addressed store, hash-verified

656 // Reads a plain scalar up to `stop`, rejecting directive, tag, explicit key and
657 // block sequence indicators.
658 private readPlain(stop: (code: number) => boolean): string {
659 // YAML 1.2.2 §7.3.3: `-` starts a plain scalar only before a non-space character other
660 // than a flow indicator. Checked in the source, since folding and trimming hide a
661 // following space or line break; the end of the line is a line break.
662 if (this.peek() === "-") {
663 const next = this.line.charCodeAt(this.index + 1)
664 if (this.index + 1 >= this.line.length || isWhiteCode(next) || isFlowIndicatorCode(next)) this.fail(flowDashError)
665 }
666 const start = this.offset + this.index
667 const raw = this.readUntil(stop, true)
668 const text = trimWhite(foldFlowLines(raw))
669 if (text.startsWith("%")) this.fail(directiveIndicatorError)
670 // YAML 1.2.2 §7.3.3: `?` directly before a `:` starts a plain scalar. Checked in the source,
671 // since the separating `:` is not part of the text.
672 if (isExplicitKey(text) && !(raw === "?" && this.peek() === ":")) this.fail(explicitKeyError)
673 // YAML 1.2.2 §7.3.3 (ns-plain-safe-in): a plain scalar in a flow collection cannot contain a
674 // flow indicator. `,`, `]` and `}` end it, and `[` or `{` inside it fails.
675 if (/[[{]/.test(text)) {
676 throw new SyntaxError(`A flow plain scalar cannot contain '[' or '{' at flow offset ${start}`)
677 }
678 return text
679 }
680
681 private parseSequence(): Array<unknown> {
682 this.expect("[")

Callers 2

parseValueMethod · 0.95
parseKeyMethod · 0.95

Calls 8

peekMethod · 0.95
failMethod · 0.95
readUntilMethod · 0.95
isWhiteCodeFunction · 0.85
isFlowIndicatorCodeFunction · 0.85
trimWhiteFunction · 0.85
foldFlowLinesFunction · 0.85
isExplicitKeyFunction · 0.85

Tested by

no test coverage detected