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

Function parseGitClass

packages/effect/src/IgnoreFile.ts:242–301  ·  view source on GitHub ↗
(
  chars: ReadonlyArray<string>,
  open: number
)

Source from the content-addressed store, hash-verified

240// wildmatch's bracket parser: `]` first is a member, an unknown class name or
241// an unclosed class aborts the match, so the caller drops the rule.
242const parseGitClass = (
243 chars: ReadonlyArray<string>,
244 open: number
245): { readonly token: Glob.Token; readonly end: number } | undefined => {
246 let i = open + 1
247 const negated = chars[i] === "!" || chars[i] === "^"
248 if (negated) {
249 i++
250 }
251 const ranges: Array<number> = []
252 let char: string | undefined = chars[i]
253 let previous: string | undefined
254 do {
255 if (char === undefined) {
256 return undefined
257 }
258 if (char === "\\") {
259 char = chars[++i]
260 if (char === undefined) {
261 return undefined
262 }
263 ranges.push(...single(char))
264 } else if (char === "-" && previous !== undefined && chars[i + 1] !== undefined && chars[i + 1] !== "]") {
265 char = chars[++i]
266 if (char === "\\") {
267 char = chars[++i]
268 if (char === undefined) {
269 return undefined
270 }
271 }
272 ranges.push(codePoint(previous), codePoint(char))
273 char = undefined
274 } else if (char === "[" && chars[i + 1] === ":") {
275 let end = i + 2
276 while (chars[end] !== undefined && chars[end] !== "]") {
277 end++
278 }
279 if (chars[end] === undefined) {
280 return undefined
281 }
282 if (end === i + 2 || chars[end - 1] !== ":") {
283 // not a class name, so `[` is a member
284 ranges.push(...single(char))
285 } else {
286 const members = lookup(gitClasses, chars.slice(i + 2, end - 1).join(""))
287 if (members === undefined) {
288 return undefined
289 }
290 ranges.push(...members)
291 i = end
292 char = undefined
293 }
294 } else {
295 ranges.push(...single(char))
296 }
297 previous = char
298 char = chars[++i]
299 } while (char !== "]")

Callers 1

compileGitSegmentFunction · 0.85

Calls 6

codePointFunction · 0.85
sliceMethod · 0.80
singleFunction · 0.70
lookupFunction · 0.70
pushMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected