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

Method parseNodeValue

packages/effect/src/encoding/Yaml.ts:1203–1236  ·  view source on GitHub ↗
(
    rawValue: string,
    parentIndent: number,
    allowIndentless = false,
    outer?: { readonly anchor: string | undefined; readonly tag: string | undefined }
  )

Source from the content-addressed store, hash-verified

1201
1202 // `outer` holds properties from a previous line that belong to this node.
1203 private parseNodeValue(
1204 rawValue: string,
1205 parentIndent: number,
1206 allowIndentless = false,
1207 outer?: { readonly anchor: string | undefined; readonly tag: string | undefined }
1208 ): unknown {
1209 const fail = throwSyntaxError
1210 const own = nodeProperties(rawValue, fail)
1211 if (outer?.anchor !== undefined && own.anchor !== undefined) fail("Multiple anchors on one node")
1212 if (outer?.tag !== undefined && own.tag !== undefined) fail("Multiple tags on one node")
1213 const anchor = outer?.anchor ?? own.anchor
1214 const tag = outer?.tag ?? own.tag
1215 const rest = own.rest
1216 if (anchor === undefined && tag === undefined) return this.parseValue(rest, parentIndent, allowIndentless)
1217 // YAML 1.2.2 §7.1: an alias has no properties.
1218 if (rest.startsWith("*")) fail(tag === undefined ? "An alias cannot have an anchor" : "An alias cannot have a tag")
1219 const empty = isSeparationOnly(rest)
1220 if (empty) {
1221 // YAML 1.2.2 §6.9: properties and scalar content may continue on later lines.
1222 const next = this.scalarContinuation(parentIndent)
1223 if (next !== undefined) {
1224 this.index++
1225 return this.parseNodeValue(next.text, parentIndent, allowIndentless, { anchor, tag })
1226 }
1227 }
1228 if (tag !== undefined) this.plainText = undefined
1229 const node = empty
1230 ? this.parseBlockValue(parentIndent, allowIndentless)
1231 : this.parseValue(rest, parentIndent, allowIndentless)
1232 const value = tag === undefined ? node : resolveTag(tag, node, this.plainText, fail)
1233 // Recorded once the whole node, with its tag, is resolved.
1234 if (anchor !== undefined) this.anchors.set(anchor, value)
1235 return value
1236 }
1237
1238 // The next line, when it continues a node as a scalar rather than starting a collection.
1239 private scalarContinuation(parentIndent: number): Line | undefined {

Callers 4

parseDocumentContentMethod · 0.95
parseNodeMethod · 0.95
parseMappingEntryMethod · 0.95
parseSequenceEntryMethod · 0.95

Calls 8

parseValueMethod · 0.95
scalarContinuationMethod · 0.95
parseBlockValueMethod · 0.95
nodePropertiesFunction · 0.85
isSeparationOnlyFunction · 0.85
resolveTagFunction · 0.85
failFunction · 0.70
setMethod · 0.65

Tested by

no test coverage detected