@descent-vtt/spec-harness 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +107 -0
  4. package/README.md +3 -3
  5. package/dist/commands.js +8 -1
  6. package/dist/commands.js.map +1 -1
  7. package/dist/context.d.ts +7 -1
  8. package/dist/context.js +14 -2
  9. package/dist/context.js.map +1 -1
  10. package/dist/document.d.ts +6 -0
  11. package/dist/document.js.map +1 -1
  12. package/dist/git.d.ts +8 -1
  13. package/dist/git.js +8 -5
  14. package/dist/git.js.map +1 -1
  15. package/dist/reader.js +3 -1
  16. package/dist/reader.js.map +1 -1
  17. package/dist/round.js +1 -1
  18. package/dist/round.js.map +1 -1
  19. package/dist/sandbox.d.ts +3 -1
  20. package/dist/sandbox.js +129 -30
  21. package/dist/sandbox.js.map +1 -1
  22. package/dist/server.js +10 -1
  23. package/dist/server.js.map +1 -1
  24. package/dist/vendor/spec-core/markdown/links.d.ts +2 -2
  25. package/dist/vendor/spec-core/markdown/links.js +92 -26
  26. package/dist/vendor/spec-core/markdown/links.js.map +1 -1
  27. package/dist/vendor/spec-core/markdown/scan.js +1 -1
  28. package/dist/vendor/spec-core/markdown/scan.js.map +1 -1
  29. package/dist/vendor/spec-core/markdown/tables.js +3 -0
  30. package/dist/vendor/spec-core/markdown/tables.js.map +1 -1
  31. package/dist/vendor/spec-core/pattern/automaton.d.ts +15 -2
  32. package/dist/vendor/spec-core/pattern/automaton.js +21 -2
  33. package/dist/vendor/spec-core/pattern/automaton.js.map +1 -1
  34. package/dist/vendor/spec-core/pattern/charset.d.ts +5 -1
  35. package/dist/vendor/spec-core/pattern/charset.js +8 -1
  36. package/dist/vendor/spec-core/pattern/charset.js.map +1 -1
  37. package/dist/vendor/spec-core/pattern/glob.d.ts +14 -3
  38. package/dist/vendor/spec-core/pattern/glob.js +55 -16
  39. package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
  40. package/dist/vendor/spec-core/text/lines.js +10 -0
  41. package/dist/vendor/spec-core/text/lines.js.map +1 -1
  42. package/package.json +1 -1
@@ -26,6 +26,9 @@
26
26
  * tools read it three ways, and the quiet reading narrowed their scope. The
27
27
  * refusal writes the two patterns it may have meant from the one written.
28
28
  * - `*`, `?` and classes never match `/`, and `*` matches a leading dot.
29
+ * - Braces expand first, and each alternative reads as it would written on
30
+ * its own: `{src/,lib}` is `src/` or `lib`, and a trailing `/` means the
31
+ * directory's contents - in an exclusion, the directory and its contents.
29
32
  * - Case is the caller's decision, stated every time. A result must not
30
33
  * depend on the host it ran on.
31
34
  * - A malformed pattern is an error, never a literal. An unclosed `[` or `{`,
@@ -34,7 +37,7 @@
34
37
  * glob is a group holding a `|`, `+(a|b)`: without one, `C++(notes).md` is
35
38
  * a name with parentheses in it, as ripgrep and `.gitignore` read it.
36
39
  */
37
- import { Builder, findWitness, Matcher, WITNESS_BUDGET, } from './automaton.js';
40
+ import { AutomatonTooLarge, Builder, findWitness, Matcher, WITNESS_BUDGET, } from './automaton.js';
38
41
  import { ANY, classSet, literalSet, SEPARATOR } from './charset.js';
39
42
  export class GlobError extends Error {
40
43
  source;
@@ -50,12 +53,19 @@ export const MAX_ALTERNATIVES = 256;
50
53
  export function isGlobSyntax(source) {
51
54
  return /[*?[\]{}]/.test(source);
52
55
  }
53
- /** Parses and compiles a glob, or says why it cannot. */
56
+ /**
57
+ * Parses and compiles a glob, or says why it cannot: malformed, or too large
58
+ * to compile, past {@link MAX_ALTERNATIVES} alternatives or `MAX_STATES`
59
+ * states. It throws only what a `literal` function throws.
60
+ */
54
61
  export function parseGlob(source, options) {
55
62
  const result = build(source, options);
56
63
  return typeof result === 'string' ? { ok: false, error: result } : { ok: true, glob: result };
57
64
  }
58
- /** Parses and compiles a glob, throwing {@link GlobError} when it cannot. */
65
+ /**
66
+ * Parses and compiles a glob, throwing {@link GlobError} for every reason
67
+ * {@link parseGlob} gives, and what a `literal` function throws.
68
+ */
59
69
  export function compileGlob(source, options) {
60
70
  const result = build(source, options);
61
71
  if (typeof result === 'string')
@@ -87,13 +97,6 @@ function build(source, options) {
87
97
  rooted = true;
88
98
  pattern = pattern.replace(/^\/+/, '');
89
99
  }
90
- // A trailing slash means a directory's contents, except in an exclusion,
91
- // where `build/` and `build` exclude the same things.
92
- if (pattern.endsWith('/')) {
93
- pattern = pattern.replace(/\/+$/, '');
94
- if (options.dialect !== 'gitignore')
95
- pattern = `${pattern}/**`;
96
- }
97
100
  if (pattern.length === 0)
98
101
  return 'the pattern names the root itself, not a path under it';
99
102
  const expanded = expandBraces(pattern, escapes);
@@ -101,7 +104,7 @@ function build(source, options) {
101
104
  return expanded;
102
105
  const alternatives = [];
103
106
  for (const text of expanded) {
104
- const parsed = parseAlternative(text, escapes);
107
+ const parsed = parseAlternative(trailingSlash(text, options.dialect), escapes);
105
108
  if (parsed === GLOBSTAR_IN_NAME)
106
109
  return `${GLOBSTAR_IN_NAME}: ${globstarAdvice(written)}`;
107
110
  if (typeof parsed === 'string')
@@ -111,12 +114,23 @@ function build(source, options) {
111
114
  const builder = new Builder();
112
115
  const fragments = [];
113
116
  const bases = [];
114
- for (const alternative of alternatives) {
115
- const compiled = compileAlternative(builder, alternative, options, rooted, anchored);
116
- fragments.push(compiled.fragment);
117
- bases.push(compiled.base);
117
+ let automaton;
118
+ try {
119
+ for (const alternative of alternatives) {
120
+ const compiled = compileAlternative(builder, alternative, options, rooted, anchored);
121
+ fragments.push(compiled.fragment);
122
+ bases.push(compiled.base);
123
+ }
124
+ automaton = builder.finish(builder.either(fragments), options.caseSensitive);
125
+ }
126
+ catch (error) {
127
+ // A pattern too large to compile is refused with a reason, as a malformed
128
+ // one is. Anything else - a caller's literal reading that throws - is the
129
+ // caller's failure, not the pattern's, and goes on up.
130
+ if (error instanceof AutomatonTooLarge)
131
+ return error.message;
132
+ throw error;
118
133
  }
119
- const automaton = builder.finish(builder.either(fragments), options.caseSensitive);
120
134
  let matcher = null;
121
135
  return {
122
136
  source,
@@ -138,6 +152,12 @@ function build(source, options) {
138
152
  * Classes and escapes are skipped while looking for braces and commas, so
139
153
  * `{[,]x,y}` is two alternatives, `[,]x` and `y`. A lone `}` is a literal: it
140
154
  * cannot be read as anything else. An unclosed `{` is an error.
155
+ *
156
+ * Here and in the two functions after it, a loop that reads one step past
157
+ * the end reads `''`, which none of them acts on, and `classEnd` answers -1
158
+ * or an index past the `[`, so `close > 0` and `close >= 0` read the same.
159
+ * `open` is set by the `{` that any `}` read here closes, so its first value
160
+ * is never read.
141
161
  */
142
162
  function expandBraces(pattern, escapes) {
143
163
  let depth = 0;
@@ -233,6 +253,25 @@ function classEnd(pattern, open, escapes) {
233
253
  return -1;
234
254
  }
235
255
  /* ---------------------------------------------------------------- segments */
256
+ /**
257
+ * What a trailing slash means, read on each alternative the braces give, so
258
+ * that `{src/,lib}` reads `src/` as `src/` alone reads: the directory's
259
+ * contents, `src/**`, and not a literal that may be the directory itself.
260
+ *
261
+ * In an exclusion `build/` excludes what `build` does. Git's rule is that a
262
+ * trailing slash matches only a directory, and a directory is excluded with
263
+ * everything in it; a matcher that sees only a path cannot tell a directory
264
+ * from a file, so the slash is dropped, and it anchors nothing. An
265
+ * alternative that is only slashes names the root, which `parseAlternative`
266
+ * refuses as naming no path.
267
+ *
268
+ * The whole run of slashes is taken, so that `{//,a}` is refused as `{/,a}`
269
+ * is; taken lazily it is the whole run all the same, since it ends the text.
270
+ */
271
+ function trailingSlash(text, dialect) {
272
+ const name = text.replace(/\/+$/, '');
273
+ return name === text || name === '' || dialect === 'gitignore' ? name : `${name}/**`;
274
+ }
236
275
  function parseAlternative(text, escapes) {
237
276
  const segments = [];
238
277
  const raw = text.split('/');
@@ -1 +1 @@
1
- {"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/pattern/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;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CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ,OAAO;YACP,KAAK,CAAC,IAAY;gBAChB,IAAI,QAAQ,GAAG,KAAK,CAAC;gBACrB,KAAK,MAAM,KAAK,IAAI,OAAO;oBAAE,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;wBAAE,QAAQ,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC;gBACnF,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Globs, in the three dialects the spec-* tools speak, compiled to one kind of\n * automaton.\n *\n * The syntax is the part people type: `*`, `**`, `?`, `[abc]`, `[!a-z]`,\n * `{a,b}`, and `\\` to escape. What differs between the tools is not the\n * syntax but what a pattern is matched against, and those differences are\n * deliberate, so each has a name (docs/adr/0003-glob-dialects.md):\n *\n * - `path` - the whole repository-relative path, anchored at the root. A\n * pattern with no glob syntax names a file, a directory, or either, as the\n * caller says; `src/auth` may cover `src/auth/login.ts`.\n * - `ripgrep` - as ripgrep's `-g`: a pattern with no `/` is matched against\n * the last segment at any depth, so `*.ts` matches `src/deep/a.ts`; one with\n * a `/` is matched against the whole path.\n * - `gitignore` - as an exclusion list reads: a pattern matches a path or any\n * directory above it, so `tests` excludes everything under any `tests`; one\n * with a `/` other than a trailing one is anchored at the root, and a\n * leading `/` only anchors.\n *\n * Shared by all three:\n *\n * - `**` is a globstar only as a whole segment. `a/**\\/b` matches `a/b` and\n * `a/x/y/b`; a trailing `/**` matches everything inside a directory and not\n * the directory itself. Two stars inside a name, `**.md`, are refused: the\n * tools read it three ways, and the quiet reading narrowed their scope. The\n * refusal writes the two patterns it may have meant from the one written.\n * - `*`, `?` and classes never match `/`, and `*` matches a leading dot.\n * - Case is the caller's decision, stated every time. A result must not\n * depend on the host it ran on.\n * - A malformed pattern is an error, never a literal. An unclosed `[` or `{`,\n * an extended glob, a `..` - each is refused with a reason, because a typo\n * read as a literal is a scope that silently matches nothing. An extended\n * glob is a group holding a `|`, `+(a|b)`: without one, `C++(notes).md` is\n * a name with parentheses in it, as ripgrep and `.gitignore` read it.\n */\n\nimport {\n Builder,\n findWitness,\n Matcher,\n WITNESS_BUDGET,\n type Automaton,\n type Fragment,\n type Witness,\n} from './automaton.js';\nimport { ANY, classSet, literalSet, SEPARATOR, type CodeRange } from './charset.js';\n\nexport type GlobDialect = 'path' | 'ripgrep' | 'gitignore';\n\n/** How a `path` pattern with no glob syntax is read. */\nexport type LiteralReading = 'file' | 'directory' | 'either';\n\nexport interface GlobOptions {\n readonly dialect: GlobDialect;\n /** Whether `A` and `a` differ. No default: the caller decides, every time. */\n readonly caseSensitive: boolean;\n /**\n * `path` dialect only: how a pattern with no glob syntax is read - as a\n * file, as a directory and everything beneath it, or as either. A function\n * is asked per literal path, for a caller that knows the tree. `either` when\n * unset. A trailing `/` always means a directory.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n /**\n * `escape` (the default): `\\` escapes the next character, and a `\\` before a\n * letter or digit is refused as a Windows separator typed by mistake.\n * `separator`: every `\\` is a `/`, for patterns typed on a Windows shell.\n */\n readonly backslash?: 'escape' | 'separator' | undefined;\n}\n\nexport interface Glob {\n readonly source: string;\n readonly dialect: GlobDialect;\n readonly caseSensitive: boolean;\n /**\n * The directories a walk must enter to find every match: one per\n * alternative, the leading literal segments. `''` for an alternative that\n * can match at any depth.\n */\n readonly bases: readonly string[];\n readonly automaton: Automaton;\n /** Whether a canonical path - POSIX, no `.`, no empty or trailing segment - matches. */\n match(path: string): boolean;\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport class GlobError extends Error {\n readonly source: string;\n constructor(source: string, reason: string) {\n super(`invalid glob \"${source}\": ${reason}`);\n this.name = 'GlobError';\n this.source = source;\n }\n}\n\n/** More alternatives than this is a pattern nobody meant. */\nexport const MAX_ALTERNATIVES = 256;\n\ntype Token =\n | { readonly kind: 'literal'; readonly point: number }\n | { readonly kind: 'any' }\n | { readonly kind: 'star' }\n | { readonly kind: 'class'; readonly negated: boolean; readonly ranges: readonly CodeRange[] };\n\ntype Segment = { readonly kind: 'globstar' } | { readonly kind: 'name'; readonly tokens: readonly Token[] };\n\ninterface Alternative {\n readonly segments: readonly Segment[];\n /** Written with a `/` somewhere other than at its end. */\n readonly slashed: boolean;\n}\n\n/** Whether a string uses glob syntax at all. */\nexport function isGlobSyntax(source: string): boolean {\n return /[*?[\\]{}]/.test(source);\n}\n\n/** Parses and compiles a glob, or says why it cannot. */\nexport function parseGlob(source: string, options: GlobOptions): GlobParse {\n const result = build(source, options);\n return typeof result === 'string' ? { ok: false, error: result } : { ok: true, glob: result };\n}\n\n/** Parses and compiles a glob, throwing {@link GlobError} when it cannot. */\nexport function compileGlob(source: string, options: GlobOptions): Glob {\n const result = build(source, options);\n if (typeof result === 'string') throw new GlobError(source, result);\n return result;\n}\n\nfunction build(source: string, options: GlobOptions): Glob | string {\n const escapes = options.backslash !== 'separator';\n let pattern = source.trim();\n if (!escapes) pattern = pattern.replace(/\\\\/g, '/');\n const written = pattern;\n if (pattern.length === 0) return 'the pattern is empty';\n if (pattern.startsWith('!')) return 'a negated pattern is a list entry, not a glob; narrow the positive pattern';\n if (/(?:^|[^\\\\])[?*+@!]\\([^)]*\\|/.test(pattern)) return EXTGLOB;\n while (pattern.startsWith('./')) pattern = pattern.slice(2);\n\n // A leading slash roots a pattern at the filesystem's root in the path and\n // ripgrep dialects, and only anchors it at the repository root in gitignore.\n let rooted = false;\n let anchored = false;\n if (pattern.startsWith('/')) {\n if (options.dialect === 'gitignore') anchored = true;\n else rooted = true;\n pattern = pattern.replace(/^\\/+/, '');\n }\n // A trailing slash means a directory's contents, except in an exclusion,\n // where `build/` and `build` exclude the same things.\n if (pattern.endsWith('/')) {\n pattern = pattern.replace(/\\/+$/, '');\n if (options.dialect !== 'gitignore') pattern = `${pattern}/**`;\n }\n if (pattern.length === 0) return 'the pattern names the root itself, not a path under it';\n\n const expanded = expandBraces(pattern, escapes);\n if (typeof expanded === 'string') return expanded;\n\n const alternatives: Alternative[] = [];\n for (const text of expanded) {\n const parsed = parseAlternative(text, escapes);\n if (parsed === GLOBSTAR_IN_NAME) return `${GLOBSTAR_IN_NAME}: ${globstarAdvice(written)}`;\n if (typeof parsed === 'string') return parsed;\n alternatives.push(parsed);\n }\n\n const builder = new Builder();\n const fragments: Fragment[] = [];\n const bases: string[] = [];\n for (const alternative of alternatives) {\n const compiled = compileAlternative(builder, alternative, options, rooted, anchored);\n fragments.push(compiled.fragment);\n bases.push(compiled.base);\n }\n const automaton = builder.finish(builder.either(fragments), options.caseSensitive);\n let matcher: Matcher | null = null;\n return {\n source,\n dialect: options.dialect,\n caseSensitive: options.caseSensitive,\n bases: [...new Set(bases)],\n automaton,\n match(path: string): boolean {\n matcher ??= new Matcher(automaton);\n return matcher.test(path);\n },\n };\n}\n\n/* ------------------------------------------------------------------ braces */\n\n/**\n * Expands `{a,b}` groups into the patterns they stand for, or says why the\n * pattern is malformed.\n *\n * Classes and escapes are skipped while looking for braces and commas, so\n * `{[,]x,y}` is two alternatives, `[,]x` and `y`. A lone `}` is a literal: it\n * cannot be read as anything else. An unclosed `{` is an error.\n */\nfunction expandBraces(pattern: string, escapes: boolean): string[] | string {\n let depth = 0;\n let open = -1;\n for (let i = 0; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\' && escapes) {\n i += 1;\n continue;\n }\n if (ch === '[') {\n const close = classEnd(pattern, i, escapes);\n if (close > 0) i = close;\n continue;\n }\n if (ch === '{') {\n if (depth === 0) open = i;\n depth += 1;\n continue;\n }\n if (ch !== '}' || depth === 0) continue;\n depth -= 1;\n if (depth > 0) continue;\n const prefix = pattern.slice(0, open);\n const suffix = pattern.slice(i + 1);\n const results: string[] = [];\n for (const option of splitOptions(pattern.slice(open + 1, i), escapes)) {\n const expanded = expandBraces(`${prefix}${option}${suffix}`, escapes);\n if (typeof expanded === 'string') return expanded;\n results.push(...expanded);\n if (results.length > MAX_ALTERNATIVES) return `the braces expand to more than ${MAX_ALTERNATIVES} patterns`;\n }\n return results;\n }\n if (depth > 0) return 'a \"{\" is never closed';\n return [pattern];\n}\n\n/** Splits a brace body on its top-level commas. */\nfunction splitOptions(body: string, escapes: boolean): string[] {\n const parts: string[] = [];\n let depth = 0;\n let start = 0;\n for (let i = 0; i < body.length; i += 1) {\n const ch = body.charAt(i);\n if (ch === '\\\\' && escapes) {\n i += 1;\n } else if (ch === '[') {\n const close = classEnd(body, i, escapes);\n if (close > 0) i = close;\n } else if (ch === '{') {\n depth += 1;\n } else if (ch === '}') {\n depth -= 1;\n } else if (ch === ',' && depth === 0) {\n parts.push(body.slice(start, i));\n start = i + 1;\n }\n }\n parts.push(body.slice(start));\n return parts;\n}\n\n/** The index of the `]` closing a class opened at `open`, or -1 when none does within the segment. */\nfunction classEnd(pattern: string, open: number, escapes: boolean): number {\n let i = open + 1;\n if (pattern.charAt(i) === '!' || pattern.charAt(i) === '^') i += 1;\n // The first member is always a member, even `]`.\n if (pattern.charAt(i) === ']') i += 1;\n for (; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\' && escapes) {\n i += 1;\n continue;\n }\n if (ch === '/') return -1;\n if (ch === ']') return i;\n }\n return -1;\n}\n\n/* ---------------------------------------------------------------- segments */\n\nfunction parseAlternative(text: string, escapes: boolean): Alternative | string {\n const segments: Segment[] = [];\n const raw = text.split('/');\n for (const part of raw) {\n if (part === '' || part === '.') continue;\n if (part === '..') return 'a pattern cannot climb out of its root with \"..\"';\n if (part === '**') {\n if (segments[segments.length - 1]?.kind !== 'globstar') segments.push({ kind: 'globstar' });\n continue;\n }\n const tokens = tokenize(part, escapes);\n if (typeof tokens === 'string') return tokens;\n segments.push({ kind: 'name', tokens });\n }\n if (segments.length === 0) return 'the pattern names no path';\n return { segments, slashed: raw.filter((part) => part !== '' && part !== '.').length > 1 };\n}\n\nconst EXTGLOB = 'extended globs such as \"+(a|b)\" are not supported: write alternatives as \"{a,b}\", and a literal parenthesis as \"[(]\"';\nconst GLOBSTAR_IN_NAME = '\"**\" means any number of directories only as a whole segment';\n\n/**\n * The two patterns a writer of `**` inside a name may have meant, built from\n * what they wrote. Each run of stars that is not a whole segment becomes, for\n * any depth, a globstar segment with a star kept on each side where a name\n * went on - `docs/**.md` to `docs/**\\/*.md`, `src/a**` to `src/a*\\/**`,\n * `a**b` to `a*\\/**\\/*b` - and for one level a single star. Everything else\n * stays as written, braces and classes included, and a globstar that was a\n * whole segment stays one.\n *\n * Only `/` is taken for a boundary. A run beside a brace, `{**.md,x}`, is\n * given a star on that side too, which keeps the advice a pattern that\n * compiles whatever the braces expand to.\n *\n * `written` holds a `\\` only where it escapes: in the `separator` reading\n * each one is already a `/`.\n */\nfunction globstarAdvice(written: string): string {\n let deep = '';\n let flat = '';\n let at = 0;\n // One step past the end reads `''` and appends nothing, so the bound could\n // be one further and give the same advice.\n while (at < written.length) {\n const ch = written.charAt(at);\n let next = at + 1;\n if (ch === '\\\\') {\n next = at + 2;\n } else if (ch === '[') {\n // A class is copied as written. `classEnd` answers an index past the\n // `[`, or -1 for one never closed, so `close >= 0` reads the same; and\n // stopping one short of the `]` copies the class all the same, since\n // its last member and the `]` after it are never a run of stars.\n const close = classEnd(written, at, true);\n if (close > 0) next = close + 1;\n } else if (ch === '*') {\n while (written.charAt(next) === '*') next += 1;\n const before = at > 0 && written.charAt(at - 1) !== '/';\n const after = next < written.length && written.charAt(next) !== '/';\n if (next - at > 2 || (next - at === 2 && (before || after))) {\n deep += `${before ? '*/' : ''}**${after ? '/*' : ''}`;\n flat += '*';\n at = next;\n continue;\n }\n }\n deep += written.slice(at, next);\n flat += written.slice(at, next);\n at = next;\n }\n return `write \"${deep}\" for any depth, or \"${flat}\" for one level`;\n}\n\nfunction tokenize(segment: string, escapes: boolean): Token[] | string {\n const tokens: Token[] = [];\n const chars = Array.from(segment);\n for (let i = 0; i < chars.length; i += 1) {\n const ch = chars[i] as string;\n if (ch === '\\\\' && escapes) {\n const next = chars[i + 1];\n if (next === undefined || /[A-Za-z0-9]/.test(next)) {\n return '\"\\\\\" escapes glob syntax; separate directories with \"/\"';\n }\n tokens.push({ kind: 'literal', point: next.codePointAt(0) as number });\n i += 1;\n } else if (ch === '*') {\n // Two stars inside a name are refused rather than read as one. The\n // tools this replaces read `docs/**.md` three ways - recursive, one\n // level, and as ripgrep does - and reading it as one level silently\n // dropped every nested document from a run that used to include them.\n if (chars[i + 1] === '*') return GLOBSTAR_IN_NAME;\n tokens.push({ kind: 'star' });\n } else if (ch === '?') {\n tokens.push({ kind: 'any' });\n } else if (ch === '[') {\n const parsed = readClass(chars, i, escapes);\n if (typeof parsed === 'string') return parsed;\n tokens.push(parsed.token);\n i = parsed.end;\n } else {\n tokens.push({ kind: 'literal', point: ch.codePointAt(0) as number });\n }\n }\n return tokens;\n}\n\nfunction readClass(chars: readonly string[], open: number, escapes: boolean): { token: Token; end: number } | string {\n let i = open + 1;\n let negated = false;\n if (chars[i] === '!' || chars[i] === '^') {\n negated = true;\n i += 1;\n }\n const ranges: CodeRange[] = [];\n let first = true;\n for (; i < chars.length; i += 1) {\n const ch = chars[i] as string;\n if (ch === ']' && !first) return { token: { kind: 'class', negated, ranges }, end: i };\n first = false;\n let low = ch;\n if (ch === '\\\\' && escapes && chars[i + 1] !== undefined) {\n i += 1;\n low = chars[i] as string;\n }\n let high = low;\n if (chars[i + 1] === '-' && chars[i + 2] !== undefined && chars[i + 2] !== ']') {\n i += 2;\n high = chars[i] as string;\n if (high === '\\\\' && escapes && chars[i + 1] !== undefined) {\n i += 1;\n high = chars[i] as string;\n }\n }\n const from = low.codePointAt(0) as number;\n const to = high.codePointAt(0) as number;\n if (to < from) return `the range \"${low}-${high}\" runs backwards`;\n ranges.push([from, to]);\n }\n return 'a \"[\" is never closed';\n}\n\n/* --------------------------------------------------------------- compiling */\n\nfunction literalText(segments: readonly Segment[]): string | null {\n const names: string[] = [];\n for (const segment of segments) {\n if (segment.kind !== 'name') return null;\n let name = '';\n for (const token of segment.tokens) {\n if (token.kind !== 'literal') return null;\n name += String.fromCodePoint(token.point);\n }\n names.push(name);\n }\n return names.join('/');\n}\n\n/** One segment name: at least one character, none of them `/`. */\nfunction name(b: Builder): Fragment {\n return b.plus(b.char(ANY));\n}\n\n/** Zero or more whole directories: `(name/)*`. */\nfunction anyDirectories(b: Builder): Fragment {\n return b.star(b.sequence([name(b), b.char(SEPARATOR)]));\n}\n\n/** One or more whole segments below a path: `/name(/name)*`. */\nfunction beneath(b: Builder): Fragment {\n return b.sequence([b.char(SEPARATOR), name(b), b.star(b.sequence([b.char(SEPARATOR), name(b)]))]);\n}\n\nfunction tokens(b: Builder, list: readonly Token[]): Fragment {\n return b.sequence(\n list.map((token) => {\n switch (token.kind) {\n case 'literal':\n return b.char(literalSet(token.point));\n case 'any':\n return b.char(ANY);\n case 'star':\n return b.star(b.char(ANY));\n case 'class':\n return b.char(classSet(token.ranges, token.negated));\n }\n }),\n );\n}\n\nfunction segmentsFragment(b: Builder, segments: readonly Segment[]): Fragment {\n const parts: Fragment[] = [];\n segments.forEach((segment, i) => {\n const last = i === segments.length - 1;\n if (segment.kind === 'globstar') {\n // Inside a path a globstar is any number of whole directories, the\n // separator after them included; at its end, at least one segment.\n parts.push(last ? b.sequence([name(b), b.star(b.sequence([b.char(SEPARATOR), name(b)]))]) : anyDirectories(b));\n return;\n }\n parts.push(tokens(b, segment.tokens));\n if (!last) parts.push(b.char(SEPARATOR));\n });\n return b.sequence(parts);\n}\n\nfunction compileAlternative(\n b: Builder,\n alternative: Alternative,\n options: GlobOptions,\n rooted: boolean,\n anchored: boolean,\n): { fragment: Fragment; base: string } {\n const { segments } = alternative;\n const body = segmentsFragment(b, segments);\n const root = rooted ? '/' : '';\n const literal = literalText(segments);\n const leading = leadingLiteral(segments);\n\n if (options.dialect === 'gitignore') {\n const floating = !anchored && !alternative.slashed;\n const parts = [body, b.optional(beneath(b))];\n if (floating) parts.unshift(anyDirectories(b));\n const base = literal !== null ? leading.slice(0, -1) : leading;\n return { fragment: b.sequence(parts), base: floating ? '' : base.join('/') };\n }\n\n if (options.dialect === 'ripgrep' && !rooted && !alternative.slashed) {\n return { fragment: b.sequence([anyDirectories(b), body]), base: '' };\n }\n\n const parts = rooted ? [b.char(SEPARATOR), body] : [body];\n if (options.dialect === 'path' && literal !== null) {\n const reading = typeof options.literal === 'function' ? options.literal(root + literal) : options.literal ?? 'either';\n if (reading === 'directory') {\n parts.push(beneath(b));\n return { fragment: b.sequence(parts), base: root + literal };\n }\n if (reading === 'either') parts.push(b.optional(beneath(b)));\n }\n // A literal path may be a file, whose base is the directory holding it.\n const base = literal !== null ? leading.slice(0, -1) : leading;\n return { fragment: b.sequence(parts), base: root + base.join('/') };\n}\n\nfunction leadingLiteral(segments: readonly Segment[]): string[] {\n const out: string[] = [];\n for (const segment of segments) {\n const text = literalText([segment]);\n if (text === null) break;\n out.push(text);\n }\n return out;\n}\n\n/* ---------------------------------------------------------------- questions */\n\nfunction assertComparable(globs: readonly Glob[]): void {\n for (const glob of globs) {\n if (!glob.caseSensitive) throw new Error(`\"${glob.source}\" ignores case; scopes are compared case-sensitively`);\n }\n}\n\n/**\n * A shortest path every glob in `include` matches and no glob in `exclude`\n * does: the file two scopes would both write, less what either protects.\n * `none` is a proof that there is no such path. Case-sensitive globs only.\n */\nexport function globWitness(\n include: readonly Glob[],\n exclude: readonly Glob[] = [],\n budget: number = WITNESS_BUDGET,\n): Witness {\n assertComparable([...include, ...exclude]);\n return findWitness(\n include.map((glob) => glob.automaton),\n exclude.map((glob) => glob.automaton),\n budget,\n );\n}\n\n/**\n * Whether every path `inner` matches is matched by one of `outer`: `true`,\n * `false`, or `undecided` when the search met its budget.\n */\nexport function globCovers(\n outer: readonly Glob[],\n inner: Glob,\n budget: number = WITNESS_BUDGET,\n): boolean | 'undecided' {\n const witness = globWitness([inner], outer, budget);\n return witness.kind === 'undecided' ? 'undecided' : witness.kind === 'none';\n}\n\n/* -------------------------------------------------------------------- lists */\n\nexport interface GlobList {\n /** Whether a path is in: the last entry that matches it decides, and a `!` entry takes it out. */\n match(path: string): boolean;\n readonly entries: readonly { readonly negated: boolean; readonly glob: Glob }[];\n}\n\nexport type GlobListParse = { readonly ok: true; readonly list: GlobList } | { readonly ok: false; readonly error: string };\n\n/**\n * A list of patterns read the way a `.gitignore` reads: in order, each entry\n * deciding the paths it matches, a leading `!` taking them back out.\n */\nexport function parseGlobList(patterns: readonly string[], options: GlobOptions): GlobListParse {\n const entries: { negated: boolean; glob: Glob }[] = [];\n for (const pattern of patterns) {\n const trimmed = pattern.trim();\n const negated = trimmed.startsWith('!');\n const parsed = parseGlob(negated ? trimmed.slice(1) : trimmed, options);\n if (!parsed.ok) return { ok: false, error: `\"${pattern}\": ${parsed.error}` };\n entries.push({ negated, glob: parsed.glob });\n }\n return {\n ok: true,\n list: {\n entries,\n match(path: string): boolean {\n let included = false;\n for (const entry of entries) if (entry.glob.match(path)) included = !entry.negated;\n return included;\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/pattern/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EACL,iBAAiB,EACjB,OAAO,EACP,WAAW,EACX,OAAO,EACP,cAAc,GAIf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAkB,MAAM,cAAc,CAAC;AA4CpF,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,MAAM,CAAS;IACxB,YAAY,MAAc,EAAE,MAAc;QACxC,KAAK,CAAC,iBAAiB,MAAM,MAAM,MAAM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,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ,OAAO;YACP,KAAK,CAAC,IAAY;gBAChB,IAAI,QAAQ,GAAG,KAAK,CAAC;gBACrB,KAAK,MAAM,KAAK,IAAI,OAAO;oBAAE,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;wBAAE,QAAQ,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC;gBACnF,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Globs, in the three dialects the spec-* tools speak, compiled to one kind of\n * automaton.\n *\n * The syntax is the part people type: `*`, `**`, `?`, `[abc]`, `[!a-z]`,\n * `{a,b}`, and `\\` to escape. What differs between the tools is not the\n * syntax but what a pattern is matched against, and those differences are\n * deliberate, so each has a name (docs/adr/0003-glob-dialects.md):\n *\n * - `path` - the whole repository-relative path, anchored at the root. A\n * pattern with no glob syntax names a file, a directory, or either, as the\n * caller says; `src/auth` may cover `src/auth/login.ts`.\n * - `ripgrep` - as ripgrep's `-g`: a pattern with no `/` is matched against\n * the last segment at any depth, so `*.ts` matches `src/deep/a.ts`; one with\n * a `/` is matched against the whole path.\n * - `gitignore` - as an exclusion list reads: a pattern matches a path or any\n * directory above it, so `tests` excludes everything under any `tests`; one\n * with a `/` other than a trailing one is anchored at the root, and a\n * leading `/` only anchors.\n *\n * Shared by all three:\n *\n * - `**` is a globstar only as a whole segment. `a/**\\/b` matches `a/b` and\n * `a/x/y/b`; a trailing `/**` matches everything inside a directory and not\n * the directory itself. Two stars inside a name, `**.md`, are refused: the\n * tools read it three ways, and the quiet reading narrowed their scope. The\n * refusal writes the two patterns it may have meant from the one written.\n * - `*`, `?` and classes never match `/`, and `*` matches a leading dot.\n * - Braces expand first, and each alternative reads as it would written on\n * its own: `{src/,lib}` is `src/` or `lib`, and a trailing `/` means the\n * directory's contents - in an exclusion, the directory and its contents.\n * - Case is the caller's decision, stated every time. A result must not\n * depend on the host it ran on.\n * - A malformed pattern is an error, never a literal. An unclosed `[` or `{`,\n * an extended glob, a `..` - each is refused with a reason, because a typo\n * read as a literal is a scope that silently matches nothing. An extended\n * glob is a group holding a `|`, `+(a|b)`: without one, `C++(notes).md` is\n * a name with parentheses in it, as ripgrep and `.gitignore` read it.\n */\n\nimport {\n AutomatonTooLarge,\n Builder,\n findWitness,\n Matcher,\n WITNESS_BUDGET,\n type Automaton,\n type Fragment,\n type Witness,\n} from './automaton.js';\nimport { ANY, classSet, literalSet, SEPARATOR, type CodeRange } from './charset.js';\n\nexport type GlobDialect = 'path' | 'ripgrep' | 'gitignore';\n\n/** How a `path` pattern with no glob syntax is read. */\nexport type LiteralReading = 'file' | 'directory' | 'either';\n\nexport interface GlobOptions {\n readonly dialect: GlobDialect;\n /** Whether `A` and `a` differ. No default: the caller decides, every time. */\n readonly caseSensitive: boolean;\n /**\n * `path` dialect only: how a pattern with no glob syntax is read - as a\n * file, as a directory and everything beneath it, or as either. A function\n * is asked per literal path, for a caller that knows the tree. `either` when\n * unset. A trailing `/`, on the pattern or on one of its brace alternatives,\n * always means a directory's contents, and is never asked about.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n /**\n * `escape` (the default): `\\` escapes the next character, and a `\\` before a\n * letter or digit is refused as a Windows separator typed by mistake.\n * `separator`: every `\\` is a `/`, for patterns typed on a Windows shell.\n */\n readonly backslash?: 'escape' | 'separator' | undefined;\n}\n\nexport interface Glob {\n readonly source: string;\n readonly dialect: GlobDialect;\n readonly caseSensitive: boolean;\n /**\n * The directories a walk must enter to find every match: one per\n * alternative, the leading literal segments. `''` for an alternative that\n * can match at any depth.\n */\n readonly bases: readonly string[];\n readonly automaton: Automaton;\n /** Whether a canonical path - POSIX, no `.`, no empty or trailing segment - matches. */\n match(path: string): boolean;\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport class GlobError extends Error {\n readonly source: string;\n constructor(source: string, reason: string) {\n super(`invalid glob \"${source}\": ${reason}`);\n this.name = 'GlobError';\n this.source = source;\n }\n}\n\n/** More alternatives than this is a pattern nobody meant. */\nexport const MAX_ALTERNATIVES = 256;\n\ntype Token =\n | { readonly kind: 'literal'; readonly point: number }\n | { readonly kind: 'any' }\n | { readonly kind: 'star' }\n | { readonly kind: 'class'; readonly negated: boolean; readonly ranges: readonly CodeRange[] };\n\ntype Segment = { readonly kind: 'globstar' } | { readonly kind: 'name'; readonly tokens: readonly Token[] };\n\ninterface Alternative {\n readonly segments: readonly Segment[];\n /** Written with a `/` somewhere other than at its end. */\n readonly slashed: boolean;\n}\n\n/** Whether a string uses glob syntax at all. */\nexport function isGlobSyntax(source: string): boolean {\n return /[*?[\\]{}]/.test(source);\n}\n\n/**\n * Parses and compiles a glob, or says why it cannot: malformed, or too large\n * to compile, past {@link MAX_ALTERNATIVES} alternatives or `MAX_STATES`\n * states. It throws only what a `literal` function throws.\n */\nexport function parseGlob(source: string, options: GlobOptions): GlobParse {\n const result = build(source, options);\n return typeof result === 'string' ? { ok: false, error: result } : { ok: true, glob: result };\n}\n\n/**\n * Parses and compiles a glob, throwing {@link GlobError} for every reason\n * {@link parseGlob} gives, and what a `literal` function throws.\n */\nexport function compileGlob(source: string, options: GlobOptions): Glob {\n const result = build(source, options);\n if (typeof result === 'string') throw new GlobError(source, result);\n return result;\n}\n\nfunction build(source: string, options: GlobOptions): Glob | string {\n const escapes = options.backslash !== 'separator';\n let pattern = source.trim();\n if (!escapes) pattern = pattern.replace(/\\\\/g, '/');\n const written = pattern;\n if (pattern.length === 0) return 'the pattern is empty';\n if (pattern.startsWith('!')) return 'a negated pattern is a list entry, not a glob; narrow the positive pattern';\n if (/(?:^|[^\\\\])[?*+@!]\\([^)]*\\|/.test(pattern)) return EXTGLOB;\n while (pattern.startsWith('./')) pattern = pattern.slice(2);\n\n // A leading slash roots a pattern at the filesystem's root in the path and\n // ripgrep dialects, and only anchors it at the repository root in gitignore.\n let rooted = false;\n let anchored = false;\n if (pattern.startsWith('/')) {\n if (options.dialect === 'gitignore') anchored = true;\n else rooted = true;\n pattern = pattern.replace(/^\\/+/, '');\n }\n if (pattern.length === 0) return 'the pattern names the root itself, not a path under it';\n\n const expanded = expandBraces(pattern, escapes);\n if (typeof expanded === 'string') return expanded;\n\n const alternatives: Alternative[] = [];\n for (const text of expanded) {\n const parsed = parseAlternative(trailingSlash(text, options.dialect), escapes);\n if (parsed === GLOBSTAR_IN_NAME) return `${GLOBSTAR_IN_NAME}: ${globstarAdvice(written)}`;\n if (typeof parsed === 'string') return parsed;\n alternatives.push(parsed);\n }\n\n const builder = new Builder();\n const fragments: Fragment[] = [];\n const bases: string[] = [];\n let automaton: Automaton;\n try {\n for (const alternative of alternatives) {\n const compiled = compileAlternative(builder, alternative, options, rooted, anchored);\n fragments.push(compiled.fragment);\n bases.push(compiled.base);\n }\n automaton = builder.finish(builder.either(fragments), options.caseSensitive);\n } catch (error) {\n // A pattern too large to compile is refused with a reason, as a malformed\n // one is. Anything else - a caller's literal reading that throws - is the\n // caller's failure, not the pattern's, and goes on up.\n if (error instanceof AutomatonTooLarge) return error.message;\n throw error;\n }\n let matcher: Matcher | null = null;\n return {\n source,\n dialect: options.dialect,\n caseSensitive: options.caseSensitive,\n bases: [...new Set(bases)],\n automaton,\n match(path: string): boolean {\n matcher ??= new Matcher(automaton);\n return matcher.test(path);\n },\n };\n}\n\n/* ------------------------------------------------------------------ braces */\n\n/**\n * Expands `{a,b}` groups into the patterns they stand for, or says why the\n * pattern is malformed.\n *\n * Classes and escapes are skipped while looking for braces and commas, so\n * `{[,]x,y}` is two alternatives, `[,]x` and `y`. A lone `}` is a literal: it\n * cannot be read as anything else. An unclosed `{` is an error.\n *\n * Here and in the two functions after it, a loop that reads one step past\n * the end reads `''`, which none of them acts on, and `classEnd` answers -1\n * or an index past the `[`, so `close > 0` and `close >= 0` read the same.\n * `open` is set by the `{` that any `}` read here closes, so its first value\n * is never read.\n */\nfunction expandBraces(pattern: string, escapes: boolean): string[] | string {\n let depth = 0;\n let open = -1;\n for (let i = 0; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\' && escapes) {\n i += 1;\n continue;\n }\n if (ch === '[') {\n const close = classEnd(pattern, i, escapes);\n if (close > 0) i = close;\n continue;\n }\n if (ch === '{') {\n if (depth === 0) open = i;\n depth += 1;\n continue;\n }\n if (ch !== '}' || depth === 0) continue;\n depth -= 1;\n if (depth > 0) continue;\n const prefix = pattern.slice(0, open);\n const suffix = pattern.slice(i + 1);\n const results: string[] = [];\n for (const option of splitOptions(pattern.slice(open + 1, i), escapes)) {\n const expanded = expandBraces(`${prefix}${option}${suffix}`, escapes);\n if (typeof expanded === 'string') return expanded;\n results.push(...expanded);\n if (results.length > MAX_ALTERNATIVES) return `the braces expand to more than ${MAX_ALTERNATIVES} patterns`;\n }\n return results;\n }\n if (depth > 0) return 'a \"{\" is never closed';\n return [pattern];\n}\n\n/** Splits a brace body on its top-level commas. */\nfunction splitOptions(body: string, escapes: boolean): string[] {\n const parts: string[] = [];\n let depth = 0;\n let start = 0;\n for (let i = 0; i < body.length; i += 1) {\n const ch = body.charAt(i);\n if (ch === '\\\\' && escapes) {\n i += 1;\n } else if (ch === '[') {\n const close = classEnd(body, i, escapes);\n if (close > 0) i = close;\n } else if (ch === '{') {\n depth += 1;\n } else if (ch === '}') {\n depth -= 1;\n } else if (ch === ',' && depth === 0) {\n parts.push(body.slice(start, i));\n start = i + 1;\n }\n }\n parts.push(body.slice(start));\n return parts;\n}\n\n/** The index of the `]` closing a class opened at `open`, or -1 when none does within the segment. */\nfunction classEnd(pattern: string, open: number, escapes: boolean): number {\n let i = open + 1;\n if (pattern.charAt(i) === '!' || pattern.charAt(i) === '^') i += 1;\n // The first member is always a member, even `]`.\n if (pattern.charAt(i) === ']') i += 1;\n for (; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\' && escapes) {\n i += 1;\n continue;\n }\n if (ch === '/') return -1;\n if (ch === ']') return i;\n }\n return -1;\n}\n\n/* ---------------------------------------------------------------- segments */\n\n/**\n * What a trailing slash means, read on each alternative the braces give, so\n * that `{src/,lib}` reads `src/` as `src/` alone reads: the directory's\n * contents, `src/**`, and not a literal that may be the directory itself.\n *\n * In an exclusion `build/` excludes what `build` does. Git's rule is that a\n * trailing slash matches only a directory, and a directory is excluded with\n * everything in it; a matcher that sees only a path cannot tell a directory\n * from a file, so the slash is dropped, and it anchors nothing. An\n * alternative that is only slashes names the root, which `parseAlternative`\n * refuses as naming no path.\n *\n * The whole run of slashes is taken, so that `{//,a}` is refused as `{/,a}`\n * is; taken lazily it is the whole run all the same, since it ends the text.\n */\nfunction trailingSlash(text: string, dialect: GlobDialect): string {\n const name = text.replace(/\\/+$/, '');\n return name === text || name === '' || dialect === 'gitignore' ? name : `${name}/**`;\n}\n\nfunction parseAlternative(text: string, escapes: boolean): Alternative | string {\n const segments: Segment[] = [];\n const raw = text.split('/');\n for (const part of raw) {\n if (part === '' || part === '.') continue;\n if (part === '..') return 'a pattern cannot climb out of its root with \"..\"';\n if (part === '**') {\n if (segments[segments.length - 1]?.kind !== 'globstar') segments.push({ kind: 'globstar' });\n continue;\n }\n const tokens = tokenize(part, escapes);\n if (typeof tokens === 'string') return tokens;\n segments.push({ kind: 'name', tokens });\n }\n if (segments.length === 0) return 'the pattern names no path';\n return { segments, slashed: raw.filter((part) => part !== '' && part !== '.').length > 1 };\n}\n\nconst EXTGLOB = 'extended globs such as \"+(a|b)\" are not supported: write alternatives as \"{a,b}\", and a literal parenthesis as \"[(]\"';\nconst GLOBSTAR_IN_NAME = '\"**\" means any number of directories only as a whole segment';\n\n/**\n * The two patterns a writer of `**` inside a name may have meant, built from\n * what they wrote. Each run of stars that is not a whole segment becomes, for\n * any depth, a globstar segment with a star kept on each side where a name\n * went on - `docs/**.md` to `docs/**\\/*.md`, `src/a**` to `src/a*\\/**`,\n * `a**b` to `a*\\/**\\/*b` - and for one level a single star. Everything else\n * stays as written, braces and classes included, and a globstar that was a\n * whole segment stays one.\n *\n * Only `/` is taken for a boundary. A run beside a brace, `{**.md,x}`, is\n * given a star on that side too, which keeps the advice a pattern that\n * compiles whatever the braces expand to.\n *\n * `written` holds a `\\` only where it escapes: in the `separator` reading\n * each one is already a `/`.\n */\nfunction globstarAdvice(written: string): string {\n let deep = '';\n let flat = '';\n let at = 0;\n // One step past the end reads `''` and appends nothing, so the bound could\n // be one further and give the same advice.\n while (at < written.length) {\n const ch = written.charAt(at);\n let next = at + 1;\n if (ch === '\\\\') {\n next = at + 2;\n } else if (ch === '[') {\n // A class is copied as written. `classEnd` answers an index past the\n // `[`, or -1 for one never closed, so `close >= 0` reads the same; and\n // stopping one short of the `]` copies the class all the same, since\n // its last member and the `]` after it are never a run of stars.\n const close = classEnd(written, at, true);\n if (close > 0) next = close + 1;\n } else if (ch === '*') {\n while (written.charAt(next) === '*') next += 1;\n const before = at > 0 && written.charAt(at - 1) !== '/';\n const after = next < written.length && written.charAt(next) !== '/';\n if (next - at > 2 || (next - at === 2 && (before || after))) {\n deep += `${before ? '*/' : ''}**${after ? '/*' : ''}`;\n flat += '*';\n at = next;\n continue;\n }\n }\n deep += written.slice(at, next);\n flat += written.slice(at, next);\n at = next;\n }\n return `write \"${deep}\" for any depth, or \"${flat}\" for one level`;\n}\n\nfunction tokenize(segment: string, escapes: boolean): Token[] | string {\n const tokens: Token[] = [];\n const chars = Array.from(segment);\n for (let i = 0; i < chars.length; i += 1) {\n const ch = chars[i] as string;\n if (ch === '\\\\' && escapes) {\n const next = chars[i + 1];\n if (next === undefined || /[A-Za-z0-9]/.test(next)) {\n return '\"\\\\\" escapes glob syntax; separate directories with \"/\"';\n }\n tokens.push({ kind: 'literal', point: next.codePointAt(0) as number });\n i += 1;\n } else if (ch === '*') {\n // Two stars inside a name are refused rather than read as one. The\n // tools this replaces read `docs/**.md` three ways - recursive, one\n // level, and as ripgrep does - and reading it as one level silently\n // dropped every nested document from a run that used to include them.\n if (chars[i + 1] === '*') return GLOBSTAR_IN_NAME;\n tokens.push({ kind: 'star' });\n } else if (ch === '?') {\n tokens.push({ kind: 'any' });\n } else if (ch === '[') {\n const parsed = readClass(chars, i, escapes);\n if (typeof parsed === 'string') return parsed;\n tokens.push(parsed.token);\n i = parsed.end;\n } else {\n tokens.push({ kind: 'literal', point: ch.codePointAt(0) as number });\n }\n }\n return tokens;\n}\n\nfunction readClass(chars: readonly string[], open: number, escapes: boolean): { token: Token; end: number } | string {\n let i = open + 1;\n let negated = false;\n if (chars[i] === '!' || chars[i] === '^') {\n negated = true;\n i += 1;\n }\n const ranges: CodeRange[] = [];\n let first = true;\n for (; i < chars.length; i += 1) {\n const ch = chars[i] as string;\n if (ch === ']' && !first) return { token: { kind: 'class', negated, ranges }, end: i };\n first = false;\n let low = ch;\n if (ch === '\\\\' && escapes && chars[i + 1] !== undefined) {\n i += 1;\n low = chars[i] as string;\n }\n let high = low;\n if (chars[i + 1] === '-' && chars[i + 2] !== undefined && chars[i + 2] !== ']') {\n i += 2;\n high = chars[i] as string;\n if (high === '\\\\' && escapes && chars[i + 1] !== undefined) {\n i += 1;\n high = chars[i] as string;\n }\n }\n const from = low.codePointAt(0) as number;\n const to = high.codePointAt(0) as number;\n if (to < from) return `the range \"${low}-${high}\" runs backwards`;\n ranges.push([from, to]);\n }\n return 'a \"[\" is never closed';\n}\n\n/* --------------------------------------------------------------- compiling */\n\nfunction literalText(segments: readonly Segment[]): string | null {\n const names: string[] = [];\n for (const segment of segments) {\n if (segment.kind !== 'name') return null;\n let name = '';\n for (const token of segment.tokens) {\n if (token.kind !== 'literal') return null;\n name += String.fromCodePoint(token.point);\n }\n names.push(name);\n }\n return names.join('/');\n}\n\n/** One segment name: at least one character, none of them `/`. */\nfunction name(b: Builder): Fragment {\n return b.plus(b.char(ANY));\n}\n\n/** Zero or more whole directories: `(name/)*`. */\nfunction anyDirectories(b: Builder): Fragment {\n return b.star(b.sequence([name(b), b.char(SEPARATOR)]));\n}\n\n/** One or more whole segments below a path: `/name(/name)*`. */\nfunction beneath(b: Builder): Fragment {\n return b.sequence([b.char(SEPARATOR), name(b), b.star(b.sequence([b.char(SEPARATOR), name(b)]))]);\n}\n\nfunction tokens(b: Builder, list: readonly Token[]): Fragment {\n return b.sequence(\n list.map((token) => {\n switch (token.kind) {\n case 'literal':\n return b.char(literalSet(token.point));\n case 'any':\n return b.char(ANY);\n case 'star':\n return b.star(b.char(ANY));\n case 'class':\n return b.char(classSet(token.ranges, token.negated));\n }\n }),\n );\n}\n\nfunction segmentsFragment(b: Builder, segments: readonly Segment[]): Fragment {\n const parts: Fragment[] = [];\n segments.forEach((segment, i) => {\n const last = i === segments.length - 1;\n if (segment.kind === 'globstar') {\n // Inside a path a globstar is any number of whole directories, the\n // separator after them included; at its end, at least one segment.\n parts.push(last ? b.sequence([name(b), b.star(b.sequence([b.char(SEPARATOR), name(b)]))]) : anyDirectories(b));\n return;\n }\n parts.push(tokens(b, segment.tokens));\n if (!last) parts.push(b.char(SEPARATOR));\n });\n return b.sequence(parts);\n}\n\nfunction compileAlternative(\n b: Builder,\n alternative: Alternative,\n options: GlobOptions,\n rooted: boolean,\n anchored: boolean,\n): { fragment: Fragment; base: string } {\n const { segments } = alternative;\n const body = segmentsFragment(b, segments);\n const root = rooted ? '/' : '';\n const literal = literalText(segments);\n const leading = leadingLiteral(segments);\n\n if (options.dialect === 'gitignore') {\n const floating = !anchored && !alternative.slashed;\n const parts = [body, b.optional(beneath(b))];\n if (floating) parts.unshift(anyDirectories(b));\n const base = literal !== null ? leading.slice(0, -1) : leading;\n return { fragment: b.sequence(parts), base: floating ? '' : base.join('/') };\n }\n\n if (options.dialect === 'ripgrep' && !rooted && !alternative.slashed) {\n return { fragment: b.sequence([anyDirectories(b), body]), base: '' };\n }\n\n const parts = rooted ? [b.char(SEPARATOR), body] : [body];\n if (options.dialect === 'path' && literal !== null) {\n const reading = typeof options.literal === 'function' ? options.literal(root + literal) : options.literal ?? 'either';\n if (reading === 'directory') {\n parts.push(beneath(b));\n return { fragment: b.sequence(parts), base: root + literal };\n }\n if (reading === 'either') parts.push(b.optional(beneath(b)));\n }\n // A literal path may be a file, whose base is the directory holding it.\n const base = literal !== null ? leading.slice(0, -1) : leading;\n return { fragment: b.sequence(parts), base: root + base.join('/') };\n}\n\nfunction leadingLiteral(segments: readonly Segment[]): string[] {\n const out: string[] = [];\n for (const segment of segments) {\n const text = literalText([segment]);\n if (text === null) break;\n out.push(text);\n }\n return out;\n}\n\n/* ---------------------------------------------------------------- questions */\n\nfunction assertComparable(globs: readonly Glob[]): void {\n for (const glob of globs) {\n if (!glob.caseSensitive) throw new Error(`\"${glob.source}\" ignores case; scopes are compared case-sensitively`);\n }\n}\n\n/**\n * A shortest path every glob in `include` matches and no glob in `exclude`\n * does: the file two scopes would both write, less what either protects.\n * `none` is a proof that there is no such path. Case-sensitive globs only.\n */\nexport function globWitness(\n include: readonly Glob[],\n exclude: readonly Glob[] = [],\n budget: number = WITNESS_BUDGET,\n): Witness {\n assertComparable([...include, ...exclude]);\n return findWitness(\n include.map((glob) => glob.automaton),\n exclude.map((glob) => glob.automaton),\n budget,\n );\n}\n\n/**\n * Whether every path `inner` matches is matched by one of `outer`: `true`,\n * `false`, or `undecided` when the search met its budget.\n */\nexport function globCovers(\n outer: readonly Glob[],\n inner: Glob,\n budget: number = WITNESS_BUDGET,\n): boolean | 'undecided' {\n const witness = globWitness([inner], outer, budget);\n return witness.kind === 'undecided' ? 'undecided' : witness.kind === 'none';\n}\n\n/* -------------------------------------------------------------------- lists */\n\nexport interface GlobList {\n /** Whether a path is in: the last entry that matches it decides, and a `!` entry takes it out. */\n match(path: string): boolean;\n readonly entries: readonly { readonly negated: boolean; readonly glob: Glob }[];\n}\n\nexport type GlobListParse = { readonly ok: true; readonly list: GlobList } | { readonly ok: false; readonly error: string };\n\n/**\n * A list of patterns read the way a `.gitignore` reads: in order, each entry\n * deciding the paths it matches, a leading `!` taking them back out.\n */\nexport function parseGlobList(patterns: readonly string[], options: GlobOptions): GlobListParse {\n const entries: { negated: boolean; glob: Glob }[] = [];\n for (const pattern of patterns) {\n const trimmed = pattern.trim();\n const negated = trimmed.startsWith('!');\n const parsed = parseGlob(negated ? trimmed.slice(1) : trimmed, options);\n if (!parsed.ok) return { ok: false, error: `\"${pattern}\": ${parsed.error}` };\n entries.push({ negated, glob: parsed.glob });\n }\n return {\n ok: true,\n list: {\n entries,\n match(path: string): boolean {\n let included = false;\n for (const entry of entries) if (entry.glob.match(path)) included = !entry.negated;\n return included;\n },\n },\n };\n}\n"]}
@@ -15,6 +15,8 @@ const CR = 13;
15
15
  /** Offsets at which each line starts; index 0 is line 1. */
16
16
  export function lineStarts(text) {
17
17
  const starts = [0];
18
+ // One step past the end reads NaN, no terminator, so the bound could be one
19
+ // further and give the same table.
18
20
  for (let i = 0; i < text.length; i += 1) {
19
21
  const ch = text.charCodeAt(i);
20
22
  if (ch === LF) {
@@ -36,6 +38,8 @@ export function lineStarts(text) {
36
38
  export function createLineIndex(text) {
37
39
  const starts = lineStarts(text);
38
40
  const lineCount = starts.length;
41
+ // Each clamp, here and in `positionAt`, answers the bound itself at the
42
+ // bound, so `<=` and `>=` for `<` and `>` give the same answers.
39
43
  const clamp = (line) => (line < 1 ? 1 : line > lineCount ? lineCount : line);
40
44
  const startOf = (line) => starts[clamp(line) - 1];
41
45
  const endOf = (line) => {
@@ -43,6 +47,11 @@ export function createLineIndex(text) {
43
47
  const start = starts[index - 1];
44
48
  let end = index === lineCount ? text.length : starts[index];
45
49
  // At most two terminator characters, and never past the line's own start.
50
+ // With the table `lineStarts` builds, `end > start` never decides: a line
51
+ // holds no character, terminator included, only in the empty text, and
52
+ // one that holds only `\n` follows a `\n`, since a `\r` before it would
53
+ // have made one `\r\n` with it. The guards keep the promise without
54
+ // leaning on that.
46
55
  if (end > start && text.charCodeAt(end - 1) === LF)
47
56
  end -= 1;
48
57
  if (end > start && text.charCodeAt(end - 1) === CR)
@@ -116,6 +125,7 @@ const NOT_A_TERMINATOR = /[^\n\r]/g;
116
125
  */
117
126
  export function maskRanges(text, ranges) {
118
127
  const merged = mergeRanges(ranges);
128
+ // Only a shortcut: with nothing to blank, the loop below gives the text back.
119
129
  if (merged.length === 0)
120
130
  return text;
121
131
  let out = '';
@@ -1 +1 @@
1
- {"version":3,"file":"lines.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/text/lines.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwBH,MAAM,EAAE,GAAG,EAAE,CAAC;AACd,MAAM,EAAE,GAAG,EAAE,CAAC;AAEd,4DAA4D;AAC5D,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,MAAM,GAAa,CAAC,CAAC,CAAC,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACrB,CAAC;aAAM,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE;gBAAE,CAAC,IAAI,CAAC,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,0EAA0E;IAC1E,4CAA4C;IAC5C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM;QAAE,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,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE;YAAE,IAAI,IAAI,CAAC,CAAC;;YACjD,EAAE,IAAI,CAAC,CAAC;IACf,CAAC;IACD,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC","sourcesContent":["/**\n * Lines, offsets and masks.\n *\n * Every finding a spec-* tool reports points at a line and a column, and every\n * structure the scanner builds carries raw offsets rather than copies of the\n * text. Converting between the two is on the hot path, so the line table is\n * built once per file and searched by bisection.\n *\n * All three line terminators end a line - `\\n`, `\\r\\n` and a lone `\\r`, as\n * CommonMark has it - and `\\r\\n` counts once. A Windows checkout of a document\n * must produce the line numbers a POSIX checkout does.\n */\n\nexport interface Position {\n /** UTF-16 offset into the text. */\n readonly offset: number;\n /** 1-based. */\n readonly line: number;\n /** 1-based, in UTF-16 code units. */\n readonly column: number;\n}\n\nexport interface LineIndex {\n /** Number of lines. A final terminator does not open a line of its own. */\n readonly lineCount: number;\n /** Offset at which a 1-based line starts. Out-of-range lines are clamped. */\n lineStart(line: number): number;\n /** Offset just past a 1-based line, before its terminator. */\n lineEnd(line: number): number;\n /** A 1-based line without its terminator. */\n lineText(line: number): string;\n /** The line and column of an offset. Out-of-range offsets are clamped. */\n positionAt(offset: number): Position;\n}\n\nconst LF = 10;\nconst CR = 13;\n\n/** Offsets at which each line starts; index 0 is line 1. */\nexport function lineStarts(text: string): number[] {\n const starts: number[] = [0];\n for (let i = 0; i < text.length; i += 1) {\n const ch = text.charCodeAt(i);\n if (ch === LF) {\n starts.push(i + 1);\n } else if (ch === CR) {\n if (text.charCodeAt(i + 1) === LF) i += 1;\n starts.push(i + 1);\n }\n }\n // A terminator at the very end opens a line that holds nothing; an editor\n // does not count it, and neither does this.\n if (starts.length > 1 && starts[starts.length - 1] === text.length) starts.pop();\n return starts;\n}\n\n/** Builds the line table for a text. */\nexport function createLineIndex(text: string): LineIndex {\n const starts = lineStarts(text);\n const lineCount = starts.length;\n const clamp = (line: number): number => (line < 1 ? 1 : line > lineCount ? lineCount : line);\n const startOf = (line: number): number => starts[clamp(line) - 1] as number;\n const endOf = (line: number): number => {\n const index = clamp(line);\n const start = starts[index - 1] as number;\n let end = index === lineCount ? text.length : (starts[index] as number);\n // At most two terminator characters, and never past the line's own start.\n if (end > start && text.charCodeAt(end - 1) === LF) end -= 1;\n if (end > start && text.charCodeAt(end - 1) === CR) end -= 1;\n return end;\n };\n return {\n lineCount,\n lineStart: startOf,\n lineEnd: endOf,\n lineText: (line) => text.slice(startOf(line), endOf(line)),\n positionAt: (offset) => locate(starts, offset < 0 ? 0 : offset > text.length ? text.length : offset),\n };\n}\n\n/**\n * The line and column of an offset, by bisection over a line table.\n *\n * The search is half-open: `high` is one past the last candidate, and it\n * narrows until one is left. There is no `- 1` to get wrong.\n */\nexport function locate(starts: readonly number[], offset: number): Position {\n let low = 0;\n let high = starts.length;\n while (high - low > 1) {\n const mid = (low + high) >> 1;\n if ((starts[mid] as number) <= offset) low = mid;\n else high = mid;\n }\n return { offset, line: low + 1, column: offset - (starts[low] as number) + 1 };\n}\n\n/** A half-open range of offsets. */\nexport interface Range {\n readonly start: number;\n readonly end: number;\n}\n\n/** Sorts and merges ranges; touching ranges merge. Empty ranges vanish. */\nexport function mergeRanges(ranges: readonly Range[]): Range[] {\n const sorted = ranges.filter((r) => r.end > r.start).sort((a, b) => a.start - b.start || a.end - b.end);\n const out: { start: number; end: number }[] = [];\n for (const range of sorted) {\n const last = out[out.length - 1];\n if (last !== undefined && range.start <= last.end) last.end = Math.max(last.end, range.end);\n else out.push({ start: range.start, end: range.end });\n }\n return out;\n}\n\n/** Whether an offset lies in one of a list of merged, sorted ranges. */\nexport function inRanges(merged: readonly Range[], offset: number): boolean {\n let low = 0;\n let high = merged.length;\n while (low < high) {\n const mid = (low + high) >> 1;\n const range = merged[mid] as Range;\n if (offset < range.start) high = mid;\n else if (offset >= range.end) low = mid + 1;\n else return true;\n }\n return false;\n}\n\nconst NOT_A_TERMINATOR = /[^\\n\\r]/g;\n\n/**\n * Blanks the given ranges with spaces, keeping every other character and\n * every line terminator where it was.\n *\n * Offsets survive a mask, which is the point: something found at offset 400\n * of the masked text is at offset 400 of the original, on the same line. The\n * replacement walks UTF-16 code units, so a surrogate pair becomes two spaces\n * and every later offset still lands where it did.\n */\nexport function maskRanges(text: string, ranges: readonly Range[]): string {\n const merged = mergeRanges(ranges);\n if (merged.length === 0) return text;\n let out = '';\n let cursor = 0;\n for (const range of merged) {\n const start = Math.min(range.start, text.length);\n const end = Math.min(range.end, text.length);\n out += text.slice(cursor, start);\n out += text.slice(start, end).replace(NOT_A_TERMINATOR, ' ');\n cursor = end;\n }\n return out + text.slice(cursor);\n}\n\n/** A text without a leading byte-order mark. */\nexport function stripBom(text: string): string {\n return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;\n}\n\n/** The terminator a text mostly uses; `\\n` when it has none or they tie. */\nexport function lineEnding(text: string): '\\n' | '\\r\\n' {\n let crlf = 0;\n let lf = 0;\n for (let i = text.indexOf('\\n'); i >= 0; i = text.indexOf('\\n', i + 1)) {\n if (i > 0 && text.charCodeAt(i - 1) === CR) crlf += 1;\n else lf += 1;\n }\n return crlf > lf ? '\\r\\n' : '\\n';\n}\n\n/**\n * The lines of a text, without terminators. Unlike the line table, a final\n * terminator does produce a last, empty line, so that joining the lines with\n * the same terminator gives the text back byte for byte.\n */\nexport function splitLines(text: string): string[] {\n return text.split(/\\r\\n|\\n|\\r/);\n}\n"]}
1
+ {"version":3,"file":"lines.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/text/lines.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwBH,MAAM,EAAE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AAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC","sourcesContent":["/**\n * Lines, offsets and masks.\n *\n * Every finding a spec-* tool reports points at a line and a column, and every\n * structure the scanner builds carries raw offsets rather than copies of the\n * text. Converting between the two is on the hot path, so the line table is\n * built once per file and searched by bisection.\n *\n * All three line terminators end a line - `\\n`, `\\r\\n` and a lone `\\r`, as\n * CommonMark has it - and `\\r\\n` counts once. A Windows checkout of a document\n * must produce the line numbers a POSIX checkout does.\n */\n\nexport interface Position {\n /** UTF-16 offset into the text. */\n readonly offset: number;\n /** 1-based. */\n readonly line: number;\n /** 1-based, in UTF-16 code units. */\n readonly column: number;\n}\n\nexport interface LineIndex {\n /** Number of lines. A final terminator does not open a line of its own. */\n readonly lineCount: number;\n /** Offset at which a 1-based line starts. Out-of-range lines are clamped. */\n lineStart(line: number): number;\n /** Offset just past a 1-based line, before its terminator. */\n lineEnd(line: number): number;\n /** A 1-based line without its terminator. */\n lineText(line: number): string;\n /** The line and column of an offset. Out-of-range offsets are clamped. */\n positionAt(offset: number): Position;\n}\n\nconst LF = 10;\nconst CR = 13;\n\n/** Offsets at which each line starts; index 0 is line 1. */\nexport function lineStarts(text: string): number[] {\n const starts: number[] = [0];\n // One step past the end reads NaN, no terminator, so the bound could be one\n // further and give the same table.\n for (let i = 0; i < text.length; i += 1) {\n const ch = text.charCodeAt(i);\n if (ch === LF) {\n starts.push(i + 1);\n } else if (ch === CR) {\n if (text.charCodeAt(i + 1) === LF) i += 1;\n starts.push(i + 1);\n }\n }\n // A terminator at the very end opens a line that holds nothing; an editor\n // does not count it, and neither does this.\n if (starts.length > 1 && starts[starts.length - 1] === text.length) starts.pop();\n return starts;\n}\n\n/** Builds the line table for a text. */\nexport function createLineIndex(text: string): LineIndex {\n const starts = lineStarts(text);\n const lineCount = starts.length;\n // Each clamp, here and in `positionAt`, answers the bound itself at the\n // bound, so `<=` and `>=` for `<` and `>` give the same answers.\n const clamp = (line: number): number => (line < 1 ? 1 : line > lineCount ? lineCount : line);\n const startOf = (line: number): number => starts[clamp(line) - 1] as number;\n const endOf = (line: number): number => {\n const index = clamp(line);\n const start = starts[index - 1] as number;\n let end = index === lineCount ? text.length : (starts[index] as number);\n // At most two terminator characters, and never past the line's own start.\n // With the table `lineStarts` builds, `end > start` never decides: a line\n // holds no character, terminator included, only in the empty text, and\n // one that holds only `\\n` follows a `\\n`, since a `\\r` before it would\n // have made one `\\r\\n` with it. The guards keep the promise without\n // leaning on that.\n if (end > start && text.charCodeAt(end - 1) === LF) end -= 1;\n if (end > start && text.charCodeAt(end - 1) === CR) end -= 1;\n return end;\n };\n return {\n lineCount,\n lineStart: startOf,\n lineEnd: endOf,\n lineText: (line) => text.slice(startOf(line), endOf(line)),\n positionAt: (offset) => locate(starts, offset < 0 ? 0 : offset > text.length ? text.length : offset),\n };\n}\n\n/**\n * The line and column of an offset, by bisection over a line table.\n *\n * The search is half-open: `high` is one past the last candidate, and it\n * narrows until one is left. There is no `- 1` to get wrong.\n */\nexport function locate(starts: readonly number[], offset: number): Position {\n let low = 0;\n let high = starts.length;\n while (high - low > 1) {\n const mid = (low + high) >> 1;\n if ((starts[mid] as number) <= offset) low = mid;\n else high = mid;\n }\n return { offset, line: low + 1, column: offset - (starts[low] as number) + 1 };\n}\n\n/** A half-open range of offsets. */\nexport interface Range {\n readonly start: number;\n readonly end: number;\n}\n\n/** Sorts and merges ranges; touching ranges merge. Empty ranges vanish. */\nexport function mergeRanges(ranges: readonly Range[]): Range[] {\n const sorted = ranges.filter((r) => r.end > r.start).sort((a, b) => a.start - b.start || a.end - b.end);\n const out: { start: number; end: number }[] = [];\n for (const range of sorted) {\n const last = out[out.length - 1];\n if (last !== undefined && range.start <= last.end) last.end = Math.max(last.end, range.end);\n else out.push({ start: range.start, end: range.end });\n }\n return out;\n}\n\n/** Whether an offset lies in one of a list of merged, sorted ranges. */\nexport function inRanges(merged: readonly Range[], offset: number): boolean {\n let low = 0;\n let high = merged.length;\n while (low < high) {\n const mid = (low + high) >> 1;\n const range = merged[mid] as Range;\n if (offset < range.start) high = mid;\n else if (offset >= range.end) low = mid + 1;\n else return true;\n }\n return false;\n}\n\nconst NOT_A_TERMINATOR = /[^\\n\\r]/g;\n\n/**\n * Blanks the given ranges with spaces, keeping every other character and\n * every line terminator where it was.\n *\n * Offsets survive a mask, which is the point: something found at offset 400\n * of the masked text is at offset 400 of the original, on the same line. The\n * replacement walks UTF-16 code units, so a surrogate pair becomes two spaces\n * and every later offset still lands where it did.\n */\nexport function maskRanges(text: string, ranges: readonly Range[]): string {\n const merged = mergeRanges(ranges);\n // Only a shortcut: with nothing to blank, the loop below gives the text back.\n if (merged.length === 0) return text;\n let out = '';\n let cursor = 0;\n for (const range of merged) {\n const start = Math.min(range.start, text.length);\n const end = Math.min(range.end, text.length);\n out += text.slice(cursor, start);\n out += text.slice(start, end).replace(NOT_A_TERMINATOR, ' ');\n cursor = end;\n }\n return out + text.slice(cursor);\n}\n\n/** A text without a leading byte-order mark. */\nexport function stripBom(text: string): string {\n return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;\n}\n\n/** The terminator a text mostly uses; `\\n` when it has none or they tie. */\nexport function lineEnding(text: string): '\\n' | '\\r\\n' {\n let crlf = 0;\n let lf = 0;\n for (let i = text.indexOf('\\n'); i >= 0; i = text.indexOf('\\n', i + 1)) {\n if (i > 0 && text.charCodeAt(i - 1) === CR) crlf += 1;\n else lf += 1;\n }\n return crlf > lf ? '\\r\\n' : '\\n';\n}\n\n/**\n * The lines of a text, without terminators. Unlike the line table, a final\n * terminator does produce a last, empty line, so that joining the lines with\n * the same terminator gives the text back byte for byte.\n */\nexport function splitLines(text: string): string[] {\n return text.split(/\\r\\n|\\n|\\r/);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descent-vtt/spec-harness",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "The agent-facing member of the spec-* tools: context for a round, a guard on every write, an audit when it ends, probes that prove a defect before it is filed, and rulings a person signs.",
5
5
  "keywords": [
6
6
  "agents",