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

Function nodeProperties

packages/effect/src/encoding/Yaml.ts:935–965  ·  view source on GitHub ↗
(
  text: string,
  fail: (message: string) => never
)

Source from the content-addressed store, hash-verified

933
934// Splits the node properties, an anchor and a tag in either order, from the start of `text`.
935const nodeProperties = (
936 text: string,
937 fail: (message: string) => never
938): { readonly anchor: string | undefined; readonly tag: string | undefined; readonly rest: string } => {
939 // Neither an anchor nor a tag, the common case: the checks below would all fail.
940 const first = text.charCodeAt(0)
941 if (first !== 38 && first !== 33) return { anchor: undefined, tag: undefined, rest: text }
942 let anchor: string | undefined
943 let tag: string | undefined
944 let rest = text
945 while (true) {
946 // `s`: U+2028 and U+2029 are content, not line breaks.
947 const property = anchor === undefined ? /^&([^ \t,[\]{}]+)(?:[ \t]+|$)/s.exec(rest) : null
948 if (property !== null) {
949 anchor = property[1]
950 rest = rest.slice(property[0].length)
951 } else if (tag === undefined && rest.startsWith("!")) {
952 tag = readTag(rest, fail)
953 rest = rest.slice(tag.length)
954 if (rest.length > 0 && !isWhiteCode(rest.charCodeAt(0))) fail(`Expected white space after the YAML tag ${tag}`)
955 rest = trimWhiteStart(rest)
956 } else {
957 // A node has at most one anchor and one tag.
958 if (tag !== undefined && rest.startsWith("!")) fail("Multiple tags on one node")
959 if (anchor !== undefined && /^&[^ \t,[\]{}]/.test(rest)) fail("Multiple anchors on one node")
960 // YAML 1.2.2 §§5.3 and 6.9.2: `&` cannot start a plain scalar, so it must start a named anchor.
961 if (rest.startsWith("&")) fail("Invalid anchor")
962 return { anchor, tag, rest }
963 }
964 }
965}
966
967const throwSyntaxError = (message: string): never => {
968 throw new SyntaxError(message)

Callers 1

parseNodeValueMethod · 0.85

Calls 6

readTagFunction · 0.85
isWhiteCodeFunction · 0.85
trimWhiteStartFunction · 0.85
sliceMethod · 0.80
failFunction · 0.70
execMethod · 0.45

Tested by

no test coverage detected