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

Function fullStringParse

ark/type/parser/string.ts:352–380  ·  view source on GitHub ↗
(s: RuntimeState)

Source from the content-addressed store, hash-verified

350 | otherSuggestions
351
352export const fullStringParse = (s: RuntimeState): InnerParseResult => {
353 s.parseOperand()
354 let result: InnerParseResult = parseUntilFinalizer(s).root
355 if (!result) {
356 return throwInternalError(
357 `Root was unexpectedly unset after parsing string '${s.sc.scanned}'`
358 )
359 }
360
361 if (s.finalizer === "=") result = parseDefault(s as RootedRuntimeState)
362 else if (s.finalizer === "?") {
363 result = [result, "?"]
364 // a property is optional to TypeScript where its definition ends with
365 // "?", which whitespace after it would hide
366 if (s.sc.skipSpace() && !s.sc.peek)
367 throwParseError(whitespaceAfterOptionalMessage)
368 }
369 // only a generic's args end at ",", so one here is unexpected whatever
370 // follows it, as extractFinalizedResult has it (parseString reports ">")
371 else if (s.finalizer === ",")
372 throwParseError(writeUnexpectedCharacterMessage(","))
373
374 s.sc.skipSpace()
375 if (s.sc.peek) {
376 // throw a parse error if non-whitespace characters made it here without being parsed
377 throwParseError(writeUnexpectedCharacterMessage(s.sc.peek))
378 }
379 return result
380}
381
382type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<
383 parseUntilFinalizer<s, $, args>

Callers 1

parseStringFunction · 0.85

Calls 7

throwInternalErrorFunction · 0.90
parseDefaultFunction · 0.90
throwParseErrorFunction · 0.90
parseUntilFinalizerFunction · 0.85
parseOperandMethod · 0.80
skipSpaceMethod · 0.80

Tested by

no test coverage detected