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

Method shiftUntilEscapable

ark/util/scanner.ts:98–119  ·  view source on GitHub ↗

* shifts until condition holds, reading `\` before the terminator as the * terminator and `\\` as escapeEscape followed by a backslash. Where * escapeEscape is "", as in a literal, the escapes JSON writes for a * control character are read as that character, so a literal's expression * parse

(
		condition: Scanner.UntilCondition,
		escapeEscape: typeof Backslash | "" = ""
	)

Source from the content-addressed store, hash-verified

96 * parses back to it
97 */
98 shiftUntilEscapable(
99 condition: Scanner.UntilCondition,
100 escapeEscape: typeof Backslash | "" = ""
101 ): string {
102 let shifted = ""
103 while (this.peek) {
104 if (this.peek === Backslash) {
105 this.shift()
106 if (!this.peek) {
107 shifted += Backslash
108 break
109 }
110 if (condition(this, shifted)) shifted += this.shift()
111 else if (this.peek === Backslash)
112 shifted += `${escapeEscape}${this.shift()}`
113 else if (escapeEscape === "") shifted += this.shiftControlEscape()
114 else shifted += `${Backslash}${this.shift()}`
115 } else if (condition(this, shifted)) break
116 else shifted += this.shift()
117 }
118 return shifted
119 }
120
121 /** the control character escaped after a backslash, or the backslash as written */
122 private shiftControlEscape(): string {

Callers 2

parseEnclosedFunction · 0.80
scanner.test.tsFile · 0.80

Calls 3

shiftMethod · 0.95
shiftControlEscapeMethod · 0.95
conditionFunction · 0.85

Tested by

no test coverage detected