MCPcopy Create free account
hub / github.com/arktypeio/arktype / parseString

Function parseString

ark/type/parser/string.ts:71–100  ·  view source on GitHub ↗
(
	def: string,
	ctx: BaseParseContext
)

Source from the content-addressed store, hash-verified

69}
70
71export const parseString = (
72 def: string,
73 ctx: BaseParseContext
74): InnerParseResult => {
75 const aliasResolution = maybeResolveReference(def, ctx)
76 if (aliasResolution) return aliasResolution
77
78 if (def.endsWith("[]")) {
79 const possibleElementResolution = maybeResolveReference(
80 def.slice(0, -2),
81 ctx
82 )
83 if (possibleElementResolution) return possibleElementResolution.rawArray()
84 }
85
86 const s = new RuntimeState(new Scanner(def), ctx)
87
88 const node = fullStringParse(s)
89
90 if (s.finalizer === ">") {
91 const beforeGt = s.sc.scanned.trimEnd().slice(0, -1).trimEnd()
92 throwParseError(
93 s.trailingRightBounded || beforeGt.endsWith(">") ?
94 writeUnexpectedCharacterMessage(">")
95 : writeMissingRightOperandMessage(">")
96 )
97 }
98
99 return node
100}
101
102/**
103 * Try to parse the definition from right to left using the most common syntax.

Callers 1

parseInnerDefinitionFunction · 0.90

Calls 5

throwParseErrorFunction · 0.90
maybeResolveReferenceFunction · 0.85
fullStringParseFunction · 0.85

Tested by

no test coverage detected