@descent-vtt/spec-harness 0.3.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +39 -0
- package/dist/vendor/spec-core/markdown/links.js +15 -2
- package/dist/vendor/spec-core/markdown/links.js.map +1 -1
- package/dist/vendor/spec-core/markdown/tables.js +3 -0
- package/dist/vendor/spec-core/markdown/tables.js.map +1 -1
- package/dist/vendor/spec-core/pattern/automaton.d.ts +15 -2
- package/dist/vendor/spec-core/pattern/automaton.js +21 -2
- package/dist/vendor/spec-core/pattern/automaton.js.map +1 -1
- package/dist/vendor/spec-core/pattern/charset.d.ts +5 -1
- package/dist/vendor/spec-core/pattern/charset.js +8 -1
- package/dist/vendor/spec-core/pattern/charset.js.map +1 -1
- package/dist/vendor/spec-core/pattern/glob.d.ts +14 -3
- package/dist/vendor/spec-core/pattern/glob.js +55 -16
- package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
- package/dist/vendor/spec-core/text/lines.js +10 -0
- package/dist/vendor/spec-core/text/lines.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-harness",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Rounds of agent work under a brief: context, a guard on every write, escalations a person signs, an audit at the end. Needs Claude Code 2.1.139 or later, and @descent-vtt/spec-harness and @descent-vtt/spec-brief 0.2.0 or later installed in the project.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "DescentVTT",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
spec-core at f9ce375. A trailing `/` on a brace alternative in a brief's
|
|
6
|
+
patterns means that directory's contents, and a pattern too large to compile
|
|
7
|
+
is refused as a pattern the guard cannot read, where it crashed the guard and
|
|
8
|
+
the hook refused every write.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- spec-core at f9ce375. Its glob reads a trailing `/` on a brace
|
|
13
|
+
alternative as it reads one written alone, as that directory's contents,
|
|
14
|
+
where the slash was dropped and the alternative read as a literal:
|
|
15
|
+
- In a brief's `affectedFiles` and `protectedFiles`, and in a ruling's
|
|
16
|
+
paths, `{src/,docs/*.md}` is `src/` or `docs/*.md`. The guard allows or
|
|
17
|
+
protects `src/deep/a.ts` as before, and no longer a path named `src`
|
|
18
|
+
itself.
|
|
19
|
+
- `context` and `start_round` ask spec-guard for the rules over `src` for
|
|
20
|
+
such a scope, where they asked over the whole repository, so a rule that
|
|
21
|
+
reaches only code outside the scope, one over `lib/` say, is no longer
|
|
22
|
+
in the packet.
|
|
23
|
+
- In `dependencies.manifests`, `{tools/,Gemfile}` names every file under
|
|
24
|
+
`tools/` at the root, where it named a file called `tools` at any depth.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- A pattern that spec-core's glob compiles to more than 65536 states is a
|
|
29
|
+
pattern that cannot be read, with spec-core's reason, `the pattern
|
|
30
|
+
compiles to more than 65536 states`, where the command stopped with an
|
|
31
|
+
uncaught `AutomatonTooLarge`. In a brief's `protectedFiles` the guard
|
|
32
|
+
refuses every write as `unreadable-protection`, naming the pattern and the
|
|
33
|
+
reason, as it does a malformed protection; the PreToolUse hook refused
|
|
34
|
+
every write with "cannot check this write" and now gives that refusal and
|
|
35
|
+
the fix. In `affectedFiles` the pattern is named among those that could
|
|
36
|
+
not be read, and the rest of the scope still counts. A ruling's path, a
|
|
37
|
+
name in `dependencies.manifests` and a pattern in spec-graph's
|
|
38
|
+
configuration are passed over as a malformed one is: no path is ruled by
|
|
39
|
+
it, no manifest is read by it, and `init` says spec-graph does not read
|
|
40
|
+
the briefs.
|
|
41
|
+
|
|
3
42
|
## 0.3.0
|
|
4
43
|
|
|
5
44
|
An interrupted `probe` stops its commands before it removes their
|
|
@@ -251,7 +251,10 @@ function readBrackets(layout, definitions, defined) {
|
|
|
251
251
|
// structure mask blanks, so those two tests shape the runs and change no
|
|
252
252
|
// link. A definition's line is no paragraph's: it holds a label, a
|
|
253
253
|
// destination and a title, none of them a link, and the text after it is a
|
|
254
|
-
// paragraph of its own, whose brackets pair with nothing before it.
|
|
254
|
+
// paragraph of its own, whose brackets pair with nothing before it. Past
|
|
255
|
+
// the last line there is no line, and `continues` holds nothing there, so
|
|
256
|
+
// no run reaches past it: the loop below could take one step more, and the
|
|
257
|
+
// test for a line that is not there could go.
|
|
255
258
|
const inParagraph = (i) => {
|
|
256
259
|
const line = lines[i];
|
|
257
260
|
return line !== undefined && isMarkdown(line) && !line.blank && !defined.has(i + 1);
|
|
@@ -393,6 +396,8 @@ function readBrackets(layout, definitions, defined) {
|
|
|
393
396
|
// when a pair lies inside it, or more than 999 characters; one that is
|
|
394
397
|
// not leaves the first bracket to be read as a shortcut.
|
|
395
398
|
const refClose = pairs.get(close + 1);
|
|
399
|
+
// With no second bracket the length is NaN and the comparison false,
|
|
400
|
+
// so the first test only narrows the type.
|
|
396
401
|
if (refClose !== undefined && refClose - close - 2 <= MAX_LABEL && !brackets.nested.has(close + 1)) {
|
|
397
402
|
// `[text][]` is read through its text; `[text][label]` through its label.
|
|
398
403
|
const collapsed = text.slice(close + 2, refClose).trim() === '';
|
|
@@ -425,6 +430,8 @@ function readBrackets(layout, definitions, defined) {
|
|
|
425
430
|
const link = passed ? null : bracket(at, at, image, line);
|
|
426
431
|
reach.push(Math.max(reach[reach.length - 1], link === null ? from : link.end));
|
|
427
432
|
const around = brackets.outer.get(at);
|
|
433
|
+
// `holding` is asked only about offsets, so the first test only
|
|
434
|
+
// narrows the type.
|
|
428
435
|
if (around !== undefined && (holding.has(at) || (link !== null && !image)))
|
|
429
436
|
holding.add(around);
|
|
430
437
|
}
|
|
@@ -434,7 +441,10 @@ function readBrackets(layout, definitions, defined) {
|
|
|
434
441
|
// `textEnd` is -1 or a `]` that closes a `[`, so never 0, and the `]` is
|
|
435
442
|
// read as no link. Leaving one step later, past it, resumes at the same
|
|
436
443
|
// place, or ends the paragraph where a shortcut link ended it anyway: the
|
|
437
|
-
// test below reads the same with `textEnd > 0` or `at > textEnd
|
|
444
|
+
// test below reads the same with `textEnd > 0` or `at > textEnd`, and so
|
|
445
|
+
// does the one further into the loop with `textEnd > 0`. `resume` is read
|
|
446
|
+
// only while `textEnd` is set, and the two are set together, so its first
|
|
447
|
+
// value is never read.
|
|
438
448
|
let textEnd = -1;
|
|
439
449
|
let resume = -1;
|
|
440
450
|
while (at < to) {
|
|
@@ -475,6 +485,9 @@ function readBrackets(layout, definitions, defined) {
|
|
|
475
485
|
if (!link.image && link.form !== 'wiki') {
|
|
476
486
|
textEnd = pairs.get(at);
|
|
477
487
|
resume = link.end;
|
|
488
|
+
// Into the text. A step back instead reads the character before
|
|
489
|
+
// the `[`, which opens nothing there - it opened no link before
|
|
490
|
+
// this one, or it is escaped - and comes back here.
|
|
478
491
|
at += 1;
|
|
479
492
|
}
|
|
480
493
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAe,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGpE,MAAM,IAAI,GAAG,EAAE,CAAC;AAChB,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM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,sEAAsE;gBACtE,kCAAkC;gBAClC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,OAAO,EAAE,CAAC;oBAC/E,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACf,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACN,EAAE,IAAI,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;iBAAM,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBACzB,EAAE,IAAI,CAAC,CAAC;YACV,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACf,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;oBACxC,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAW,CAAC;oBAClC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;oBAClB,EAAE,IAAI,CAAC,CAAC;gBACV,CAAC;qBAAM,CAAC;oBACN,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;gBAChB,CAAC;YACH,CAAC;QACH,CAAC;QACD,KAAK,GAAG,IAAI,CAAC;IACf,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Links, images and reference definitions, read from the structure mask so\n * that nothing in code or a comment is one.\n *\n * Six forms: inline `[text](dest \"title\")`, full and collapsed reference\n * `[text][label]` and `[label][]`, shortcut `[label]`, autolink `<https://x>`,\n * wiki `[[target|text]]`, and the definition `[label]: dest` the reference\n * forms are read through. Each may be an image, written with a leading `!`.\n * A link's text is read again for images, which CommonMark renders there - a\n * badge wrapped in a link has two destinations - and for nothing else; each\n * is listed after the link it lies in.\n *\n * Links may not contain links, as CommonMark has it: in\n * `[a [b](inner.md) c](outer.md)` the inner pair is the link, and the outer\n * brackets and `(outer.md)` are text. So before a paragraph is read its pairs\n * are read innermost first, as CommonMark reads them, to learn which `[`\n * holds a link at any depth.\n *\n * Brackets are paired once per paragraph with a stack, and the tables that\n * say where a destination or a title ends are built once per paragraph, so\n * no bracket searches the text again for its partner. A document of nothing\n * but brackets costs its length.\n *\n * A paragraph ends at `to`, and the character there is a line terminator,\n * which no loop here acts on; nor is any lookup made at the first three\n * offsets of a paragraph, before the shortest `[](` could end. Mutants that\n * move a bound onto those places change no answer, and are equivalent.\n */\n\nimport { inRanges, mergeRanges } from '../text/index.js';\nimport { isMarkdown, isSpaceOrTab, leadOffset, visibleLead, type Layout } from './layout.js';\nimport { atxLevel, isThematicBreak, listMarker } from './syntax.js';\nimport type { Heading, Link, ScannedLine } from './types.js';\n\nconst BANG = 33;\nconst DOUBLE_QUOTE = 34;\nconst SINGLE_QUOTE = 39;\nconst OPEN_PAREN = 40;\nconst CLOSE_PAREN = 41;\nconst LESS_THAN = 60;\nconst GREATER_THAN = 62;\nconst OPEN_BRACKET = 91;\nconst BACKSLASH = 92;\nconst CLOSE_BRACKET = 93;\nconst LF = 10;\nconst CR = 13;\n\n/** CommonMark: a link label holds at most 999 characters. */\nconst MAX_LABEL = 999;\n\n/**\n * A label holds no bracket but an escaped one. Its two alternatives never\n * start on the same character, so a label is read without backtracking.\n */\nconst DEFINITION = /^ {0,3}\\[(?!\\^)((?:[^[\\]\\\\]|\\\\.)+)\\]:[ \\t]*(<[^<>]*>|\\S+)/;\n/** What may follow a definition's destination: nothing, or a title after whitespace. */\nconst TITLE_ONLY = /^(?:[ \\t]+(?:\"[^\"]*\"|'[^']*'|\\([^)]*\\)))?[ \\t]*$/;\nconst AUTOLINK = /<((?:https?|ftp|mailto):[^<>\\s]+)>/g;\n\ninterface Definition {\n readonly target: string;\n readonly targetStart: number;\n readonly targetEnd: number;\n}\n\nexport function findLinks(layout: Layout, headings: readonly Heading[]): Link[] {\n const definitions = new Map<string, Definition>();\n const defined = readDefinitions(layout, headings, definitions);\n const bracketed = readBrackets(layout, definitions, new Set(defined.map((d) => d.line)));\n // `<https://x>` as a link's destination or text is part of that link.\n const taken = mergeRanges([...defined, ...bracketed]);\n const autolinks = readAutolinks(layout).filter((link) => !inRanges(taken, link.start));\n return [...defined, ...bracketed, ...autolinks].sort((a, b) => a.start - b.start);\n}\n\n/**\n * How labels compare: trimmed, whitespace collapsed, and case folded as\n * CommonMark's reference implementations fold it, down and then up, so that\n * `ẞ` and `SS` are one label.\n */\nfunction normalizeLabel(label: string): string {\n return label.trim().replace(/\\s+/g, ' ').toLowerCase().toUpperCase();\n}\n\n/**\n * Definitions come first: the reference forms are read through them, and a\n * definition is conventionally written at the foot of the file, after the\n * links that use it. The first definition of a label wins.\n *\n * `[Note]: this matters` is prose that looks like one, so a definition has\n * nothing after its destination but a title. `[^1]: text` is a footnote.\n *\n * A definition cannot interrupt a paragraph, as CommonMark has it: one\n * written on the line under a paragraph's text is that text. It opens a\n * paragraph, or follows a definition that did.\n */\nfunction readDefinitions(layout: Layout, headings: readonly Heading[], definitions: Map<string, Definition>): Link[] {\n const { text, structure, lines, continues } = layout;\n const closed = closingLines(layout, headings);\n const out: Link[] = [];\n for (const line of lines) {\n if (!isMarkdown(line) || !visibleLead(layout, line)) continue;\n const masked = structure.slice(line.contentStart, line.end);\n const match = DEFINITION.exec(masked);\n if (match === null || !TITLE_ONLY.test(masked.slice(match[0].length))) continue;\n // Under a definition the paragraph holds nothing else yet. `continues`\n // holds no first line, so there is a line above whenever it is asked about.\n const follows = out[out.length - 1]?.line === line.line - 1;\n if (!follows && continues.has(line.line) && paragraphOpen(lines[line.line - 2] as ScannedLine, closed)) continue;\n const between = (match[1] as string).length;\n const start = line.contentStart + match[0].indexOf('[');\n const label = text.slice(start + 1, start + 1 + between).trim();\n if (label.length === 0 || between > MAX_LABEL) continue;\n const written = match[2] as string;\n const end = line.contentStart + match[0].length;\n const angle = written.charCodeAt(0) === LESS_THAN ? 1 : 0;\n const targetStart = end - written.length + angle;\n const targetEnd = end - angle;\n const target = text.slice(targetStart, targetEnd);\n const key = normalizeLabel(label);\n if (!definitions.has(key)) definitions.set(key, { target, targetStart, targetEnd });\n out.push({ form: 'definition', image: false, text: label, target, label, start, end, targetStart, targetEnd, line: line.line });\n }\n return out;\n}\n\n/**\n * The lines after which no paragraph is open, though the line under one\n * would go on with a paragraph written there: the last line of a heading,\n * and of an HTML block a comment opens. Such a block starts where a comment\n * opens a line, after at most three columns, and ends on the line the\n * comment closes on.\n */\nfunction closingLines(layout: Layout, headings: readonly Heading[]): Set<number> {\n const closed = new Set<number>();\n for (const heading of headings) closed.add(heading.endLine);\n for (const comment of layout.comments) {\n const opened = layout.lines[comment.line - 1] as ScannedLine;\n if (opened.indent <= 3 && comment.start === leadOffset(opened)) closed.add(layout.index.positionAt(comment.end).line);\n }\n return closed;\n}\n\n/**\n * Whether a paragraph is open after a line, for the line under it to go on\n * with. None is after a blank line, code, a thematic break or a closing\n * line, and none is open in a list item whose marker has nothing after it,\n * or a heading or a thematic break.\n */\nfunction paragraphOpen(line: ScannedLine, closed: ReadonlySet<number>): boolean {\n if (!isMarkdown(line) || line.blank || closed.has(line.line) || isThematicBreak(line.content)) return false;\n const marker = listMarker(line.content);\n if (marker === null) return true;\n // The marker takes every space after it, so what is left is empty or text.\n const rest = line.content.slice(marker.offset + marker.width);\n return rest.length > 0 && atxLevel(rest) === 0 && !isThematicBreak(rest);\n}\n\nfunction readAutolinks(layout: Layout): Link[] {\n const out: Link[] = [];\n for (const match of layout.structure.matchAll(AUTOLINK)) {\n const start = match.index;\n const end = start + match[0].length;\n out.push({\n form: 'autolink',\n image: false,\n text: '',\n target: match[1] as string,\n label: null,\n start,\n end,\n targetStart: start + 1,\n targetEnd: end - 1,\n line: layout.index.positionAt(start).line,\n });\n }\n return out;\n}\n\n/** The brackets of a paragraph, `[` paired with `]` as a stack pairs them, escaped ones skipped. */\ninterface Brackets {\n /** Each `[` a `]` closes, to that `]`, in the order of the `]`s: every pair after the pairs inside it. */\n readonly pairs: Map<number, number>;\n /** Each paired `[` to the `[` still open around it, where there is one. */\n readonly outer: Map<number, number>;\n /** Each paired `[` to how many pairs had closed when it opened: the pairs wholly before it. */\n readonly before: Map<number, number>;\n /** Every `[` written after an unescaped `!`: an image's. */\n readonly images: Set<number>;\n /** Every `[` with a pair inside it: those whose text holds an unescaped bracket. */\n readonly nested: Set<number>;\n}\n\nfunction pairBrackets(structure: string, from: number, to: number): Brackets {\n const brackets: Brackets = { pairs: new Map(), outer: new Map(), before: new Map(), images: new Set(), nested: new Set() };\n const { pairs } = brackets;\n const open: { readonly at: number; readonly before: number }[] = [];\n let escaped = -1;\n for (let at = from; at < to; at += 1) {\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n escaped = at + 1;\n at += 1;\n } else if (ch === OPEN_BRACKET) {\n open.push({ at, before: pairs.size });\n if (structure.charCodeAt(at - 1) === BANG && escaped !== at - 1) brackets.images.add(at);\n } else if (ch === CLOSE_BRACKET) {\n // A `]` with nothing to close pairs with nothing; recorded under\n // `undefined` it would not be found either, so this test changes no\n // answer, only what the maps hold.\n const opened = open.pop();\n if (opened !== undefined) {\n pairs.set(opened.at, at);\n brackets.before.set(opened.at, opened.before);\n const around = open[open.length - 1];\n if (around !== undefined) {\n brackets.outer.set(opened.at, around.at);\n brackets.nested.add(around.at);\n }\n }\n }\n }\n return brackets;\n}\n\n/**\n * For every offset of a paragraph, where what starts there ends, or the end\n * of the paragraph when nothing does: a bare destination at the next space or\n * control character, or at the first `)` its own parentheses leave unmatched;\n * a title at its next unescaped closing quote or parenthesis. Filled from the\n * right in one pass, so every lookup is a read.\n */\ninterface Ends {\n readonly space: Int32Array;\n readonly paren: Int32Array;\n readonly doubleQuote: Int32Array;\n readonly singleQuote: Int32Array;\n readonly closeParen: Int32Array;\n readonly openParen: Int32Array;\n}\n\nfunction endsOf(structure: string, from: number, to: number): Ends {\n const length = to - from;\n const escaped = new Uint8Array(length + 1);\n for (let x = 0; x < length; x += 1) {\n if (escaped[x] === 0 && structure.charCodeAt(from + x) === BACKSLASH) escaped[x + 1] = 1;\n }\n // Two past the last offset: a `(` whose `)` is the paragraph's last\n // character looks one further for the next unmatched `)`, and finds none.\n const make = (): Int32Array => new Int32Array(length + 2).fill(to);\n const ends: Ends = { space: make(), paren: make(), doubleQuote: make(), singleQuote: make(), closeParen: make(), openParen: make() };\n for (let x = length - 1; x >= 0; x -= 1) {\n const at = from + x;\n const ch = structure.charCodeAt(at);\n const plain = escaped[x] === 0;\n ends.space[x] = ch <= 32 || ch === 127 ? at : (ends.space[x + 1] as number);\n // From a `(`, the first unmatched `)` is the first one after the `)` that\n // closes it, which is the first unmatched `)` after the `(`.\n const unmatched = ends.paren[x + 1] as number;\n if (plain && ch === CLOSE_PAREN) ends.paren[x] = at;\n else if (plain && ch === OPEN_PAREN) ends.paren[x] = ends.paren[unmatched + 1 - from] as number;\n else ends.paren[x] = unmatched;\n ends.doubleQuote[x] = plain && ch === DOUBLE_QUOTE ? at : (ends.doubleQuote[x + 1] as number);\n ends.singleQuote[x] = plain && ch === SINGLE_QUOTE ? at : (ends.singleQuote[x + 1] as number);\n ends.closeParen[x] = plain && ch === CLOSE_PAREN ? at : (ends.closeParen[x + 1] as number);\n ends.openParen[x] = plain && ch === OPEN_PAREN ? at : (ends.openParen[x + 1] as number);\n }\n return ends;\n}\n\ninterface Destination {\n readonly targetStart: number;\n readonly targetEnd: number;\n /** Offset just past the closing `)`. */\n readonly end: number;\n}\n\n/**\n * The bracket forms, a paragraph at a time. A paragraph here is a run of\n * Markdown lines, none blank or a definition, each continuing the one above:\n * a bracket never pairs across a blank line, a heading, a definition, or the\n * start of another block.\n */\nfunction readBrackets(layout: Layout, definitions: ReadonlyMap<string, Definition>, defined: ReadonlySet<number>): Link[] {\n const { lines, continues, structure, text } = layout;\n const out: Link[] = [];\n // The first `]]` at or after the last place one was looked for; the cursor\n // only moves forward, so each is found once.\n let doubleClose = -2;\n\n const lookup = (from: number, to: number): Definition | undefined =>\n to - from > MAX_LABEL ? undefined : definitions.get(normalizeLabel(text.slice(from, to)));\n\n // A blank or code line let into a paragraph would bring only characters the\n // structure mask blanks, so those two tests shape the runs and change no\n // link. A definition's line is no paragraph's: it holds a label, a\n // destination and a title, none of them a link, and the text after it is a\n // paragraph of its own, whose brackets pair with nothing before it.\n const inParagraph = (i: number): boolean => {\n const line = lines[i];\n return line !== undefined && isMarkdown(line) && !line.blank && !defined.has(i + 1);\n };\n\n for (let first = 0; first < lines.length; first += 1) {\n if (!inParagraph(first)) continue;\n let last = first;\n while (inParagraph(last + 1) && continues.has(last + 2)) last += 1;\n const from = (lines[first] as ScannedLine).start;\n const to = (lines[last] as ScannedLine).end;\n const brackets = pairBrackets(structure, from, to);\n const { pairs } = brackets;\n // Each `[` with a link inside it, at any depth.\n const holding = new Set<number>();\n let ends: Ends | null = null;\n\n // Spaces and tabs, and at most one line ending inside the paragraph. The\n // character at `to` ends the paragraph's last line and is none of these.\n const skipSpace = (start: number): number => {\n let at = start;\n while (isSpaceOrTab(structure, at)) at += 1;\n if (at < to) {\n if (structure.charCodeAt(at) === CR) at += 1;\n if (structure.charCodeAt(at) === LF) at += 1;\n while (isSpaceOrTab(structure, at)) at += 1;\n }\n return at;\n };\n\n const destination = (open: number): Destination | null => {\n const at = skipSpace(open);\n let targetStart: number;\n let targetEnd: number;\n let after: number;\n if (structure.charCodeAt(at) === LESS_THAN) {\n // `<dest>`: no line ending and no unescaped `<` inside.\n let close = at + 1;\n for (;;) {\n if (close >= to) return null;\n const ch = structure.charCodeAt(close);\n if (ch === GREATER_THAN) break;\n if (ch === LESS_THAN || ch === LF || ch === CR) return null;\n close += ch === BACKSLASH ? 2 : 1;\n }\n targetStart = at + 1;\n targetEnd = close;\n after = close + 1;\n } else {\n ends ??= endsOf(structure, from, to);\n const space = ends.space[at - from] as number;\n const paren = ends.paren[at - from] as number;\n targetStart = at;\n // The two are equal only when neither is found, at `to`.\n targetEnd = paren < space ? paren : space;\n after = targetEnd;\n // An empty destination points nowhere a reader can follow.\n if (targetEnd === at) return null;\n }\n let k = skipSpace(after);\n if (structure.charCodeAt(k) === CLOSE_PAREN) return { targetStart, targetEnd, end: k + 1 };\n // A title is separated from the destination by whitespace, and quoted.\n if (k === after) return null;\n ends ??= endsOf(structure, from, to);\n const x = k + 1 - from;\n const quote = structure.charCodeAt(k);\n let close: number;\n if (quote === DOUBLE_QUOTE) close = ends.doubleQuote[x] as number;\n else if (quote === SINGLE_QUOTE) close = ends.singleQuote[x] as number;\n // A title in parentheses may not hold an unescaped `(`.\n else if (quote === OPEN_PAREN) close = (ends.openParen[x] as number) < (ends.closeParen[x] as number) ? to : (ends.closeParen[x] as number);\n else return null;\n // Equal ends are `to`, where the title fails either way. Past `to` the\n // next line opens a block of its own, and none opens with `)`.\n if (close === to) return null;\n k = skipSpace(close + 1);\n return structure.charCodeAt(k) === CLOSE_PAREN ? { targetStart, targetEnd, end: k + 1 } : null;\n };\n\n const wiki = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n if (structure.charCodeAt(at + 1) !== OPEN_BRACKET) return null;\n if (doubleClose !== -1 && doubleClose < at + 2) doubleClose = structure.indexOf(']]', at + 2);\n const close = doubleClose;\n if (close < 0 || close + 2 > line.end) return null;\n const inner = text.slice(at + 2, close);\n const written = inner.trim();\n const pipe = written.indexOf('|');\n const target = (pipe < 0 ? written : written.slice(0, pipe)).trim();\n // `[[ ]]` and `[[|text]]` name nothing to link to.\n if (target.length === 0) return null;\n const targetStart = at + 2 + inner.length - inner.trimStart().length;\n return {\n form: 'wiki',\n image,\n text: written,\n target,\n label: null,\n start,\n end: close + 2,\n targetStart,\n targetEnd: targetStart + target.length,\n line: line.line,\n };\n };\n\n const bracket = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n const close = pairs.get(at);\n // A link holding a link is text; an image holding one is still an image.\n if (close === undefined || (!image && holding.has(at))) return null;\n const label = (): string => text.slice(at + 1, close).trim();\n if (structure.charCodeAt(close + 1) === OPEN_PAREN) {\n const dest = destination(close + 2);\n if (dest !== null) {\n const target = text.slice(dest.targetStart, dest.targetEnd);\n return { form: 'inline', image, text: label(), target, label: null, start, line: line.line, ...dest };\n }\n } else {\n // Only a `[` is paired, so a second bracket follows exactly when this\n // finds one. It is a label unless it holds a bracket, which it does\n // when a pair lies inside it, or more than 999 characters; one that is\n // not leaves the first bracket to be read as a shortcut.\n const refClose = pairs.get(close + 1);\n if (refClose !== undefined && refClose - close - 2 <= MAX_LABEL && !brackets.nested.has(close + 1)) {\n // `[text][]` is read through its text; `[text][label]` through its label.\n const collapsed = text.slice(close + 2, refClose).trim() === '';\n const found = collapsed ? lookup(at + 1, close) : lookup(close + 2, refClose);\n if (found === undefined) return null;\n const written = collapsed ? label() : text.slice(close + 2, refClose).trim();\n return { form: 'reference', image, text: label(), label: written, start, end: refClose + 1, line: line.line, ...found };\n }\n }\n // `[text](not a destination)` is a shortcut followed by text, as CommonMark reads it.\n const found = lookup(at + 1, close);\n if (found === undefined) return null;\n return { form: 'shortcut', image, text: label(), label: label(), start, end: close + 1, line: line.line, ...found };\n };\n\n const lineAt = (at: number): ScannedLine => lines[layout.index.positionAt(at).line - 1] as ScannedLine;\n\n // CommonMark reads each pair at its `]`, so the pairs inside a `[` are\n // read before it, and a link among them makes it text, and every `[`\n // open around it: the pairs come innermost first, and fill `holding` on\n // the way out. An image among them does not; a link may hold one. What a\n // link or an image reads past its `]` - a destination, a title, a second\n // label - is not read for links again: `reach` is the furthest any of the\n // first so many pairs read to, and a `[` short of it opens nothing.\n const reach = [from];\n for (const at of pairs.keys()) {\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const passed = (reach[brackets.before.get(at) as number] as number) > at;\n const link = passed ? null : bracket(at, at, image, line);\n reach.push(Math.max(reach[reach.length - 1] as number, link === null ? from : link.end));\n const around = brackets.outer.get(at);\n if (around !== undefined && (holding.has(at) || (link !== null && !image))) holding.add(around);\n }\n\n let at = from;\n // Inside a link's text, up to its `]`, where CommonMark reads an image -\n // a badge wrapped in a link - but no other link; then on past the link.\n // `textEnd` is -1 or a `]` that closes a `[`, so never 0, and the `]` is\n // read as no link. Leaving one step later, past it, resumes at the same\n // place, or ends the paragraph where a shortcut link ended it anyway: the\n // test below reads the same with `textEnd > 0` or `at > textEnd`.\n let textEnd = -1;\n let resume = -1;\n while (at < to) {\n if (textEnd >= 0 && at >= textEnd) {\n at = resume;\n textEnd = -1;\n continue;\n }\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n at += 2;\n continue;\n }\n if (ch !== OPEN_BRACKET) {\n at += 1;\n continue;\n }\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const start = image ? at - 1 : at;\n const link = wiki(at, start, image, line) ?? bracket(at, start, image, line);\n if (textEnd >= 0) {\n // An image that closes inside the text; its own text is alt text, and\n // holds nothing a reader follows.\n if (link !== null && link.image && link.form !== 'wiki' && link.end <= textEnd) {\n out.push(link);\n at = link.end;\n } else {\n at += 1;\n }\n } else if (link === null) {\n at += 1;\n } else {\n out.push(link);\n if (!link.image && link.form !== 'wiki') {\n textEnd = pairs.get(at) as number;\n resume = link.end;\n at += 1;\n } else {\n at = link.end;\n }\n }\n }\n first = last;\n }\n return out;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAe,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGpE,MAAM,IAAI,GAAG,EAAE,CAAC;AAChB,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,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,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YAC7E,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;gBACjB,sEAAsE;gBACtE,kCAAkC;gBAClC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,OAAO,EAAE,CAAC;oBAC/E,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACf,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACN,EAAE,IAAI,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;iBAAM,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBACzB,EAAE,IAAI,CAAC,CAAC;YACV,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACf,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;oBACxC,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAW,CAAC;oBAClC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;oBAClB,gEAAgE;oBAChE,gEAAgE;oBAChE,oDAAoD;oBACpD,EAAE,IAAI,CAAC,CAAC;gBACV,CAAC;qBAAM,CAAC;oBACN,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;gBAChB,CAAC;YACH,CAAC;QACH,CAAC;QACD,KAAK,GAAG,IAAI,CAAC;IACf,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Links, images and reference definitions, read from the structure mask so\n * that nothing in code or a comment is one.\n *\n * Six forms: inline `[text](dest \"title\")`, full and collapsed reference\n * `[text][label]` and `[label][]`, shortcut `[label]`, autolink `<https://x>`,\n * wiki `[[target|text]]`, and the definition `[label]: dest` the reference\n * forms are read through. Each may be an image, written with a leading `!`.\n * A link's text is read again for images, which CommonMark renders there - a\n * badge wrapped in a link has two destinations - and for nothing else; each\n * is listed after the link it lies in.\n *\n * Links may not contain links, as CommonMark has it: in\n * `[a [b](inner.md) c](outer.md)` the inner pair is the link, and the outer\n * brackets and `(outer.md)` are text. So before a paragraph is read its pairs\n * are read innermost first, as CommonMark reads them, to learn which `[`\n * holds a link at any depth.\n *\n * Brackets are paired once per paragraph with a stack, and the tables that\n * say where a destination or a title ends are built once per paragraph, so\n * no bracket searches the text again for its partner. A document of nothing\n * but brackets costs its length.\n *\n * A paragraph ends at `to`, and the character there is a line terminator,\n * which no loop here acts on; nor is any lookup made at the first three\n * offsets of a paragraph, before the shortest `[](` could end. Mutants that\n * move a bound onto those places change no answer, and are equivalent.\n */\n\nimport { inRanges, mergeRanges } from '../text/index.js';\nimport { isMarkdown, isSpaceOrTab, leadOffset, visibleLead, type Layout } from './layout.js';\nimport { atxLevel, isThematicBreak, listMarker } from './syntax.js';\nimport type { Heading, Link, ScannedLine } from './types.js';\n\nconst BANG = 33;\nconst DOUBLE_QUOTE = 34;\nconst SINGLE_QUOTE = 39;\nconst OPEN_PAREN = 40;\nconst CLOSE_PAREN = 41;\nconst LESS_THAN = 60;\nconst GREATER_THAN = 62;\nconst OPEN_BRACKET = 91;\nconst BACKSLASH = 92;\nconst CLOSE_BRACKET = 93;\nconst LF = 10;\nconst CR = 13;\n\n/** CommonMark: a link label holds at most 999 characters. */\nconst MAX_LABEL = 999;\n\n/**\n * A label holds no bracket but an escaped one. Its two alternatives never\n * start on the same character, so a label is read without backtracking.\n */\nconst DEFINITION = /^ {0,3}\\[(?!\\^)((?:[^[\\]\\\\]|\\\\.)+)\\]:[ \\t]*(<[^<>]*>|\\S+)/;\n/** What may follow a definition's destination: nothing, or a title after whitespace. */\nconst TITLE_ONLY = /^(?:[ \\t]+(?:\"[^\"]*\"|'[^']*'|\\([^)]*\\)))?[ \\t]*$/;\nconst AUTOLINK = /<((?:https?|ftp|mailto):[^<>\\s]+)>/g;\n\ninterface Definition {\n readonly target: string;\n readonly targetStart: number;\n readonly targetEnd: number;\n}\n\nexport function findLinks(layout: Layout, headings: readonly Heading[]): Link[] {\n const definitions = new Map<string, Definition>();\n const defined = readDefinitions(layout, headings, definitions);\n const bracketed = readBrackets(layout, definitions, new Set(defined.map((d) => d.line)));\n // `<https://x>` as a link's destination or text is part of that link.\n const taken = mergeRanges([...defined, ...bracketed]);\n const autolinks = readAutolinks(layout).filter((link) => !inRanges(taken, link.start));\n return [...defined, ...bracketed, ...autolinks].sort((a, b) => a.start - b.start);\n}\n\n/**\n * How labels compare: trimmed, whitespace collapsed, and case folded as\n * CommonMark's reference implementations fold it, down and then up, so that\n * `ẞ` and `SS` are one label.\n */\nfunction normalizeLabel(label: string): string {\n return label.trim().replace(/\\s+/g, ' ').toLowerCase().toUpperCase();\n}\n\n/**\n * Definitions come first: the reference forms are read through them, and a\n * definition is conventionally written at the foot of the file, after the\n * links that use it. The first definition of a label wins.\n *\n * `[Note]: this matters` is prose that looks like one, so a definition has\n * nothing after its destination but a title. `[^1]: text` is a footnote.\n *\n * A definition cannot interrupt a paragraph, as CommonMark has it: one\n * written on the line under a paragraph's text is that text. It opens a\n * paragraph, or follows a definition that did.\n */\nfunction readDefinitions(layout: Layout, headings: readonly Heading[], definitions: Map<string, Definition>): Link[] {\n const { text, structure, lines, continues } = layout;\n const closed = closingLines(layout, headings);\n const out: Link[] = [];\n for (const line of lines) {\n if (!isMarkdown(line) || !visibleLead(layout, line)) continue;\n const masked = structure.slice(line.contentStart, line.end);\n const match = DEFINITION.exec(masked);\n if (match === null || !TITLE_ONLY.test(masked.slice(match[0].length))) continue;\n // Under a definition the paragraph holds nothing else yet. `continues`\n // holds no first line, so there is a line above whenever it is asked about.\n const follows = out[out.length - 1]?.line === line.line - 1;\n if (!follows && continues.has(line.line) && paragraphOpen(lines[line.line - 2] as ScannedLine, closed)) continue;\n const between = (match[1] as string).length;\n const start = line.contentStart + match[0].indexOf('[');\n const label = text.slice(start + 1, start + 1 + between).trim();\n if (label.length === 0 || between > MAX_LABEL) continue;\n const written = match[2] as string;\n const end = line.contentStart + match[0].length;\n const angle = written.charCodeAt(0) === LESS_THAN ? 1 : 0;\n const targetStart = end - written.length + angle;\n const targetEnd = end - angle;\n const target = text.slice(targetStart, targetEnd);\n const key = normalizeLabel(label);\n if (!definitions.has(key)) definitions.set(key, { target, targetStart, targetEnd });\n out.push({ form: 'definition', image: false, text: label, target, label, start, end, targetStart, targetEnd, line: line.line });\n }\n return out;\n}\n\n/**\n * The lines after which no paragraph is open, though the line under one\n * would go on with a paragraph written there: the last line of a heading,\n * and of an HTML block a comment opens. Such a block starts where a comment\n * opens a line, after at most three columns, and ends on the line the\n * comment closes on.\n */\nfunction closingLines(layout: Layout, headings: readonly Heading[]): Set<number> {\n const closed = new Set<number>();\n for (const heading of headings) closed.add(heading.endLine);\n for (const comment of layout.comments) {\n const opened = layout.lines[comment.line - 1] as ScannedLine;\n if (opened.indent <= 3 && comment.start === leadOffset(opened)) closed.add(layout.index.positionAt(comment.end).line);\n }\n return closed;\n}\n\n/**\n * Whether a paragraph is open after a line, for the line under it to go on\n * with. None is after a blank line, code, a thematic break or a closing\n * line, and none is open in a list item whose marker has nothing after it,\n * or a heading or a thematic break.\n */\nfunction paragraphOpen(line: ScannedLine, closed: ReadonlySet<number>): boolean {\n if (!isMarkdown(line) || line.blank || closed.has(line.line) || isThematicBreak(line.content)) return false;\n const marker = listMarker(line.content);\n if (marker === null) return true;\n // The marker takes every space after it, so what is left is empty or text.\n const rest = line.content.slice(marker.offset + marker.width);\n return rest.length > 0 && atxLevel(rest) === 0 && !isThematicBreak(rest);\n}\n\nfunction readAutolinks(layout: Layout): Link[] {\n const out: Link[] = [];\n for (const match of layout.structure.matchAll(AUTOLINK)) {\n const start = match.index;\n const end = start + match[0].length;\n out.push({\n form: 'autolink',\n image: false,\n text: '',\n target: match[1] as string,\n label: null,\n start,\n end,\n targetStart: start + 1,\n targetEnd: end - 1,\n line: layout.index.positionAt(start).line,\n });\n }\n return out;\n}\n\n/** The brackets of a paragraph, `[` paired with `]` as a stack pairs them, escaped ones skipped. */\ninterface Brackets {\n /** Each `[` a `]` closes, to that `]`, in the order of the `]`s: every pair after the pairs inside it. */\n readonly pairs: Map<number, number>;\n /** Each paired `[` to the `[` still open around it, where there is one. */\n readonly outer: Map<number, number>;\n /** Each paired `[` to how many pairs had closed when it opened: the pairs wholly before it. */\n readonly before: Map<number, number>;\n /** Every `[` written after an unescaped `!`: an image's. */\n readonly images: Set<number>;\n /** Every `[` with a pair inside it: those whose text holds an unescaped bracket. */\n readonly nested: Set<number>;\n}\n\nfunction pairBrackets(structure: string, from: number, to: number): Brackets {\n const brackets: Brackets = { pairs: new Map(), outer: new Map(), before: new Map(), images: new Set(), nested: new Set() };\n const { pairs } = brackets;\n const open: { readonly at: number; readonly before: number }[] = [];\n let escaped = -1;\n for (let at = from; at < to; at += 1) {\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n escaped = at + 1;\n at += 1;\n } else if (ch === OPEN_BRACKET) {\n open.push({ at, before: pairs.size });\n if (structure.charCodeAt(at - 1) === BANG && escaped !== at - 1) brackets.images.add(at);\n } else if (ch === CLOSE_BRACKET) {\n // A `]` with nothing to close pairs with nothing; recorded under\n // `undefined` it would not be found either, so this test changes no\n // answer, only what the maps hold.\n const opened = open.pop();\n if (opened !== undefined) {\n pairs.set(opened.at, at);\n brackets.before.set(opened.at, opened.before);\n const around = open[open.length - 1];\n if (around !== undefined) {\n brackets.outer.set(opened.at, around.at);\n brackets.nested.add(around.at);\n }\n }\n }\n }\n return brackets;\n}\n\n/**\n * For every offset of a paragraph, where what starts there ends, or the end\n * of the paragraph when nothing does: a bare destination at the next space or\n * control character, or at the first `)` its own parentheses leave unmatched;\n * a title at its next unescaped closing quote or parenthesis. Filled from the\n * right in one pass, so every lookup is a read.\n */\ninterface Ends {\n readonly space: Int32Array;\n readonly paren: Int32Array;\n readonly doubleQuote: Int32Array;\n readonly singleQuote: Int32Array;\n readonly closeParen: Int32Array;\n readonly openParen: Int32Array;\n}\n\nfunction endsOf(structure: string, from: number, to: number): Ends {\n const length = to - from;\n const escaped = new Uint8Array(length + 1);\n for (let x = 0; x < length; x += 1) {\n if (escaped[x] === 0 && structure.charCodeAt(from + x) === BACKSLASH) escaped[x + 1] = 1;\n }\n // Two past the last offset: a `(` whose `)` is the paragraph's last\n // character looks one further for the next unmatched `)`, and finds none.\n const make = (): Int32Array => new Int32Array(length + 2).fill(to);\n const ends: Ends = { space: make(), paren: make(), doubleQuote: make(), singleQuote: make(), closeParen: make(), openParen: make() };\n for (let x = length - 1; x >= 0; x -= 1) {\n const at = from + x;\n const ch = structure.charCodeAt(at);\n const plain = escaped[x] === 0;\n ends.space[x] = ch <= 32 || ch === 127 ? at : (ends.space[x + 1] as number);\n // From a `(`, the first unmatched `)` is the first one after the `)` that\n // closes it, which is the first unmatched `)` after the `(`.\n const unmatched = ends.paren[x + 1] as number;\n if (plain && ch === CLOSE_PAREN) ends.paren[x] = at;\n else if (plain && ch === OPEN_PAREN) ends.paren[x] = ends.paren[unmatched + 1 - from] as number;\n else ends.paren[x] = unmatched;\n ends.doubleQuote[x] = plain && ch === DOUBLE_QUOTE ? at : (ends.doubleQuote[x + 1] as number);\n ends.singleQuote[x] = plain && ch === SINGLE_QUOTE ? at : (ends.singleQuote[x + 1] as number);\n ends.closeParen[x] = plain && ch === CLOSE_PAREN ? at : (ends.closeParen[x + 1] as number);\n ends.openParen[x] = plain && ch === OPEN_PAREN ? at : (ends.openParen[x + 1] as number);\n }\n return ends;\n}\n\ninterface Destination {\n readonly targetStart: number;\n readonly targetEnd: number;\n /** Offset just past the closing `)`. */\n readonly end: number;\n}\n\n/**\n * The bracket forms, a paragraph at a time. A paragraph here is a run of\n * Markdown lines, none blank or a definition, each continuing the one above:\n * a bracket never pairs across a blank line, a heading, a definition, or the\n * start of another block.\n */\nfunction readBrackets(layout: Layout, definitions: ReadonlyMap<string, Definition>, defined: ReadonlySet<number>): Link[] {\n const { lines, continues, structure, text } = layout;\n const out: Link[] = [];\n // The first `]]` at or after the last place one was looked for; the cursor\n // only moves forward, so each is found once.\n let doubleClose = -2;\n\n const lookup = (from: number, to: number): Definition | undefined =>\n to - from > MAX_LABEL ? undefined : definitions.get(normalizeLabel(text.slice(from, to)));\n\n // A blank or code line let into a paragraph would bring only characters the\n // structure mask blanks, so those two tests shape the runs and change no\n // link. A definition's line is no paragraph's: it holds a label, a\n // destination and a title, none of them a link, and the text after it is a\n // paragraph of its own, whose brackets pair with nothing before it. Past\n // the last line there is no line, and `continues` holds nothing there, so\n // no run reaches past it: the loop below could take one step more, and the\n // test for a line that is not there could go.\n const inParagraph = (i: number): boolean => {\n const line = lines[i];\n return line !== undefined && isMarkdown(line) && !line.blank && !defined.has(i + 1);\n };\n\n for (let first = 0; first < lines.length; first += 1) {\n if (!inParagraph(first)) continue;\n let last = first;\n while (inParagraph(last + 1) && continues.has(last + 2)) last += 1;\n const from = (lines[first] as ScannedLine).start;\n const to = (lines[last] as ScannedLine).end;\n const brackets = pairBrackets(structure, from, to);\n const { pairs } = brackets;\n // Each `[` with a link inside it, at any depth.\n const holding = new Set<number>();\n let ends: Ends | null = null;\n\n // Spaces and tabs, and at most one line ending inside the paragraph. The\n // character at `to` ends the paragraph's last line and is none of these.\n const skipSpace = (start: number): number => {\n let at = start;\n while (isSpaceOrTab(structure, at)) at += 1;\n if (at < to) {\n if (structure.charCodeAt(at) === CR) at += 1;\n if (structure.charCodeAt(at) === LF) at += 1;\n while (isSpaceOrTab(structure, at)) at += 1;\n }\n return at;\n };\n\n const destination = (open: number): Destination | null => {\n const at = skipSpace(open);\n let targetStart: number;\n let targetEnd: number;\n let after: number;\n if (structure.charCodeAt(at) === LESS_THAN) {\n // `<dest>`: no line ending and no unescaped `<` inside.\n let close = at + 1;\n for (;;) {\n if (close >= to) return null;\n const ch = structure.charCodeAt(close);\n if (ch === GREATER_THAN) break;\n if (ch === LESS_THAN || ch === LF || ch === CR) return null;\n close += ch === BACKSLASH ? 2 : 1;\n }\n targetStart = at + 1;\n targetEnd = close;\n after = close + 1;\n } else {\n ends ??= endsOf(structure, from, to);\n const space = ends.space[at - from] as number;\n const paren = ends.paren[at - from] as number;\n targetStart = at;\n // The two are equal only when neither is found, at `to`.\n targetEnd = paren < space ? paren : space;\n after = targetEnd;\n // An empty destination points nowhere a reader can follow.\n if (targetEnd === at) return null;\n }\n let k = skipSpace(after);\n if (structure.charCodeAt(k) === CLOSE_PAREN) return { targetStart, targetEnd, end: k + 1 };\n // A title is separated from the destination by whitespace, and quoted.\n if (k === after) return null;\n ends ??= endsOf(structure, from, to);\n const x = k + 1 - from;\n const quote = structure.charCodeAt(k);\n let close: number;\n if (quote === DOUBLE_QUOTE) close = ends.doubleQuote[x] as number;\n else if (quote === SINGLE_QUOTE) close = ends.singleQuote[x] as number;\n // A title in parentheses may not hold an unescaped `(`.\n else if (quote === OPEN_PAREN) close = (ends.openParen[x] as number) < (ends.closeParen[x] as number) ? to : (ends.closeParen[x] as number);\n else return null;\n // Equal ends are `to`, where the title fails either way. Past `to` the\n // next line opens a block of its own, and none opens with `)`.\n if (close === to) return null;\n k = skipSpace(close + 1);\n return structure.charCodeAt(k) === CLOSE_PAREN ? { targetStart, targetEnd, end: k + 1 } : null;\n };\n\n const wiki = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n if (structure.charCodeAt(at + 1) !== OPEN_BRACKET) return null;\n if (doubleClose !== -1 && doubleClose < at + 2) doubleClose = structure.indexOf(']]', at + 2);\n const close = doubleClose;\n if (close < 0 || close + 2 > line.end) return null;\n const inner = text.slice(at + 2, close);\n const written = inner.trim();\n const pipe = written.indexOf('|');\n const target = (pipe < 0 ? written : written.slice(0, pipe)).trim();\n // `[[ ]]` and `[[|text]]` name nothing to link to.\n if (target.length === 0) return null;\n const targetStart = at + 2 + inner.length - inner.trimStart().length;\n return {\n form: 'wiki',\n image,\n text: written,\n target,\n label: null,\n start,\n end: close + 2,\n targetStart,\n targetEnd: targetStart + target.length,\n line: line.line,\n };\n };\n\n const bracket = (at: number, start: number, image: boolean, line: ScannedLine): Link | null => {\n const close = pairs.get(at);\n // A link holding a link is text; an image holding one is still an image.\n if (close === undefined || (!image && holding.has(at))) return null;\n const label = (): string => text.slice(at + 1, close).trim();\n if (structure.charCodeAt(close + 1) === OPEN_PAREN) {\n const dest = destination(close + 2);\n if (dest !== null) {\n const target = text.slice(dest.targetStart, dest.targetEnd);\n return { form: 'inline', image, text: label(), target, label: null, start, line: line.line, ...dest };\n }\n } else {\n // Only a `[` is paired, so a second bracket follows exactly when this\n // finds one. It is a label unless it holds a bracket, which it does\n // when a pair lies inside it, or more than 999 characters; one that is\n // not leaves the first bracket to be read as a shortcut.\n const refClose = pairs.get(close + 1);\n // With no second bracket the length is NaN and the comparison false,\n // so the first test only narrows the type.\n if (refClose !== undefined && refClose - close - 2 <= MAX_LABEL && !brackets.nested.has(close + 1)) {\n // `[text][]` is read through its text; `[text][label]` through its label.\n const collapsed = text.slice(close + 2, refClose).trim() === '';\n const found = collapsed ? lookup(at + 1, close) : lookup(close + 2, refClose);\n if (found === undefined) return null;\n const written = collapsed ? label() : text.slice(close + 2, refClose).trim();\n return { form: 'reference', image, text: label(), label: written, start, end: refClose + 1, line: line.line, ...found };\n }\n }\n // `[text](not a destination)` is a shortcut followed by text, as CommonMark reads it.\n const found = lookup(at + 1, close);\n if (found === undefined) return null;\n return { form: 'shortcut', image, text: label(), label: label(), start, end: close + 1, line: line.line, ...found };\n };\n\n const lineAt = (at: number): ScannedLine => lines[layout.index.positionAt(at).line - 1] as ScannedLine;\n\n // CommonMark reads each pair at its `]`, so the pairs inside a `[` are\n // read before it, and a link among them makes it text, and every `[`\n // open around it: the pairs come innermost first, and fill `holding` on\n // the way out. An image among them does not; a link may hold one. What a\n // link or an image reads past its `]` - a destination, a title, a second\n // label - is not read for links again: `reach` is the furthest any of the\n // first so many pairs read to, and a `[` short of it opens nothing.\n const reach = [from];\n for (const at of pairs.keys()) {\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const passed = (reach[brackets.before.get(at) as number] as number) > at;\n const link = passed ? null : bracket(at, at, image, line);\n reach.push(Math.max(reach[reach.length - 1] as number, link === null ? from : link.end));\n const around = brackets.outer.get(at);\n // `holding` is asked only about offsets, so the first test only\n // narrows the type.\n if (around !== undefined && (holding.has(at) || (link !== null && !image))) holding.add(around);\n }\n\n let at = from;\n // Inside a link's text, up to its `]`, where CommonMark reads an image -\n // a badge wrapped in a link - but no other link; then on past the link.\n // `textEnd` is -1 or a `]` that closes a `[`, so never 0, and the `]` is\n // read as no link. Leaving one step later, past it, resumes at the same\n // place, or ends the paragraph where a shortcut link ended it anyway: the\n // test below reads the same with `textEnd > 0` or `at > textEnd`, and so\n // does the one further into the loop with `textEnd > 0`. `resume` is read\n // only while `textEnd` is set, and the two are set together, so its first\n // value is never read.\n let textEnd = -1;\n let resume = -1;\n while (at < to) {\n if (textEnd >= 0 && at >= textEnd) {\n at = resume;\n textEnd = -1;\n continue;\n }\n const ch = structure.charCodeAt(at);\n if (ch === BACKSLASH) {\n at += 2;\n continue;\n }\n if (ch !== OPEN_BRACKET) {\n at += 1;\n continue;\n }\n const line = lineAt(at);\n const image = brackets.images.has(at);\n const start = image ? at - 1 : at;\n const link = wiki(at, start, image, line) ?? bracket(at, start, image, line);\n if (textEnd >= 0) {\n // An image that closes inside the text; its own text is alt text, and\n // holds nothing a reader follows.\n if (link !== null && link.image && link.form !== 'wiki' && link.end <= textEnd) {\n out.push(link);\n at = link.end;\n } else {\n at += 1;\n }\n } else if (link === null) {\n at += 1;\n } else {\n out.push(link);\n if (!link.image && link.form !== 'wiki') {\n textEnd = pairs.get(at) as number;\n resume = link.end;\n // Into the text. A step back instead reads the character before\n // the `[`, which opens nothing there - it opened no link before\n // this one, or it is escaped - and comes back here.\n at += 1;\n } else {\n at = link.end;\n }\n }\n }\n first = last;\n }\n return out;\n}\n"]}
|
|
@@ -29,6 +29,9 @@ export function findTables(layout, atx) {
|
|
|
29
29
|
return layout.covered.has(line.line) || heading.has(line.line) ? null : line;
|
|
30
30
|
};
|
|
31
31
|
const out = [];
|
|
32
|
+
// A header needs a line under it. `row` answers null for a line past the
|
|
33
|
+
// last, so a bound that lets `i` reach one or two further finds the same
|
|
34
|
+
// tables.
|
|
32
35
|
for (let i = 0; i + 1 < lines.length; i += 1) {
|
|
33
36
|
const header = row(i);
|
|
34
37
|
const delimiter = row(i + 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAGlE,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,GAAqC;IAC9E,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,qEAAqE;IACrE,wDAAwD;IACxD,MAAM,GAAG,GAAG,CAAC,CAAS,EAAsB,EAAE;QAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QACvF,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC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AG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IACjG,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QACtC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,2EAA2E;IAC3E,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7F,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;IACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC;IACpD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAC1F,CAAC","sourcesContent":["/**\n * GFM pipe tables, with an offset for every cell.\n *\n * Cell offsets are the point: a register kept as a table needs findings that\n * name the cell declaring a relation, not the row and not the file. Rows are\n * split on the structure mask, so a pipe inside a code span or a comment\n * cannot invent a column, and the text of each cell comes from the original.\n *\n * Reading one line past the last, or one character past a line's end, finds\n * no row and no pipe, so mutants that move those bounds are equivalent.\n */\n\nimport { isMarkdown, leadOffset, type Layout } from './layout.js';\nimport type { Heading, ScannedLine, Table, TableCell, TableRow } from './types.js';\n\nconst PIPE = 124;\nconst BACKSLASH = 92;\nconst DELIMITER_CELL = /^:?-+:?$/;\n\n/**\n * A header line, a delimiter row with as many cells, and the rows under them\n * up to a line that is blank, holds no pipe, or is not Markdown.\n */\nexport function findTables(layout: Layout, atx: readonly Pick<Heading, 'line'>[]): Table[] {\n const { lines } = layout;\n const heading = new Set(atx.map((h) => h.line));\n // A line starting in a comment is not a row, and neither is one that\n // continues a code span or comment from the line above.\n const row = (i: number): ScannedLine | null => {\n const line = lines[i];\n if (line === undefined || !isMarkdown(line) || line.blank || line.comment) return null;\n return layout.covered.has(line.line) || heading.has(line.line) ? null : line;\n };\n\n const out: Table[] = [];\n for (let i = 0; i + 1 < lines.length; i += 1) {\n const header = row(i);\n const delimiter = row(i + 1);\n if (header === null || delimiter === null) continue;\n const headers = splitRow(layout, header);\n if (headers.length === 0) continue;\n const marks = splitRow(layout, delimiter);\n if (marks.length !== headers.length || !marks.every((cell) => DELIMITER_CELL.test(cell.text))) continue;\n\n const rows: TableRow[] = [];\n let last = delimiter;\n for (let line = row(i + 2); line !== null; line = row(line.line)) {\n const cells = splitRow(layout, line);\n if (cells.length === 0) break;\n rows.push({ cells, start: line.contentStart, end: line.end, line: line.line });\n last = line;\n }\n out.push({ start: header.contentStart, end: last.end, line: header.line, endLine: last.line, headers, rows });\n i = last.line - 1;\n }\n return out;\n}\n\n/** Splits a row into cells, keeping each cell's offsets. A row without a pipe has none. */\nfunction splitRow(layout: Layout, line: ScannedLine): TableCell[] {\n const { text, structure } = layout;\n const bounds: number[] = [];\n for (let at = line.contentStart; at < line.end; at += 1) {\n // A pipe escaped with a backslash is content, not a column edge.\n if (structure.charCodeAt(at) === PIPE && text.charCodeAt(at - 1) !== BACKSLASH) bounds.push(at);\n }\n if (bounds.length === 0) return [];\n\n const cells: TableCell[] = [];\n // A pipe opening the row is a border, not the edge of an empty first cell.\n let cursor = bounds[0] === leadOffset(line) ? (bounds.shift() as number) + 1 : line.contentStart;\n for (const bound of bounds) {\n cells.push(cell(text, cursor, bound));\n cursor = bound + 1;\n }\n // What follows the last pipe is a cell unless the row ended with a border.\n if (text.slice(cursor, line.end).trim().length > 0) cells.push(cell(text, cursor, line.end));\n return cells;\n}\n\nfunction cell(text: string, start: number, end: number): TableCell {\n const raw = text.slice(start, end);\n const leading = raw.length - raw.trimStart().length;\n const trimmed = raw.trim();\n return { text: trimmed, start: start + leading, end: start + leading + trimmed.length };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAGlE,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,GAAqC;IAC9E,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,qEAAqE;IACrE,wDAAwD;IACxD,MAAM,GAAG,GAAG,CAAC,CAAS,EAAsB,EAAE;QAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QACvF,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CA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AC,YAAY,CAAC;IACjG,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QACtC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,2EAA2E;IAC3E,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7F,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;IACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC;IACpD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAC1F,CAAC","sourcesContent":["/**\n * GFM pipe tables, with an offset for every cell.\n *\n * Cell offsets are the point: a register kept as a table needs findings that\n * name the cell declaring a relation, not the row and not the file. Rows are\n * split on the structure mask, so a pipe inside a code span or a comment\n * cannot invent a column, and the text of each cell comes from the original.\n *\n * Reading one line past the last, or one character past a line's end, finds\n * no row and no pipe, so mutants that move those bounds are equivalent.\n */\n\nimport { isMarkdown, leadOffset, type Layout } from './layout.js';\nimport type { Heading, ScannedLine, Table, TableCell, TableRow } from './types.js';\n\nconst PIPE = 124;\nconst BACKSLASH = 92;\nconst DELIMITER_CELL = /^:?-+:?$/;\n\n/**\n * A header line, a delimiter row with as many cells, and the rows under them\n * up to a line that is blank, holds no pipe, or is not Markdown.\n */\nexport function findTables(layout: Layout, atx: readonly Pick<Heading, 'line'>[]): Table[] {\n const { lines } = layout;\n const heading = new Set(atx.map((h) => h.line));\n // A line starting in a comment is not a row, and neither is one that\n // continues a code span or comment from the line above.\n const row = (i: number): ScannedLine | null => {\n const line = lines[i];\n if (line === undefined || !isMarkdown(line) || line.blank || line.comment) return null;\n return layout.covered.has(line.line) || heading.has(line.line) ? null : line;\n };\n\n const out: Table[] = [];\n // A header needs a line under it. `row` answers null for a line past the\n // last, so a bound that lets `i` reach one or two further finds the same\n // tables.\n for (let i = 0; i + 1 < lines.length; i += 1) {\n const header = row(i);\n const delimiter = row(i + 1);\n if (header === null || delimiter === null) continue;\n const headers = splitRow(layout, header);\n if (headers.length === 0) continue;\n const marks = splitRow(layout, delimiter);\n if (marks.length !== headers.length || !marks.every((cell) => DELIMITER_CELL.test(cell.text))) continue;\n\n const rows: TableRow[] = [];\n let last = delimiter;\n for (let line = row(i + 2); line !== null; line = row(line.line)) {\n const cells = splitRow(layout, line);\n if (cells.length === 0) break;\n rows.push({ cells, start: line.contentStart, end: line.end, line: line.line });\n last = line;\n }\n out.push({ start: header.contentStart, end: last.end, line: header.line, endLine: last.line, headers, rows });\n i = last.line - 1;\n }\n return out;\n}\n\n/** Splits a row into cells, keeping each cell's offsets. A row without a pipe has none. */\nfunction splitRow(layout: Layout, line: ScannedLine): TableCell[] {\n const { text, structure } = layout;\n const bounds: number[] = [];\n for (let at = line.contentStart; at < line.end; at += 1) {\n // A pipe escaped with a backslash is content, not a column edge.\n if (structure.charCodeAt(at) === PIPE && text.charCodeAt(at - 1) !== BACKSLASH) bounds.push(at);\n }\n if (bounds.length === 0) return [];\n\n const cells: TableCell[] = [];\n // A pipe opening the row is a border, not the edge of an empty first cell.\n let cursor = bounds[0] === leadOffset(line) ? (bounds.shift() as number) + 1 : line.contentStart;\n for (const bound of bounds) {\n cells.push(cell(text, cursor, bound));\n cursor = bound + 1;\n }\n // What follows the last pipe is a cell unless the row ended with a border.\n if (text.slice(cursor, line.end).trim().length > 0) cells.push(cell(text, cursor, line.end));\n return cells;\n}\n\nfunction cell(text: string, start: number, end: number): TableCell {\n const raw = text.slice(start, end);\n const leading = raw.length - raw.trimStart().length;\n const trimmed = raw.trim();\n return { text: trimmed, start: start + leading, end: start + leading + trimmed.length };\n}\n"]}
|
|
@@ -46,10 +46,22 @@ interface Hole {
|
|
|
46
46
|
* matched slowly.
|
|
47
47
|
*/
|
|
48
48
|
export declare const MAX_STATES = 65536;
|
|
49
|
+
/**
|
|
50
|
+
* Thrown by the builder past {@link MAX_STATES}. `parseGlob` answers it as a
|
|
51
|
+
* refusal and `compileGlob` as a `GlobError`, so no function the pattern
|
|
52
|
+
* module exports lets it out; it stays exported for callers written when
|
|
53
|
+
* `parseGlob` did.
|
|
54
|
+
*/
|
|
49
55
|
export declare class AutomatonTooLarge extends Error {
|
|
50
56
|
constructor();
|
|
51
57
|
}
|
|
52
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Thompson's construction, one fragment at a time.
|
|
60
|
+
*
|
|
61
|
+
* An arrow written as -1 is a hole that `patch` aims before `finish` returns,
|
|
62
|
+
* or one nothing follows: a CHAR's second and both of a MATCH's. What it
|
|
63
|
+
* starts as is never read, so any other start gives the same automaton.
|
|
64
|
+
*/
|
|
53
65
|
export declare class Builder {
|
|
54
66
|
private readonly kinds;
|
|
55
67
|
private readonly first;
|
|
@@ -78,7 +90,8 @@ export declare class Builder {
|
|
|
78
90
|
* A reusable matcher over one automaton.
|
|
79
91
|
*
|
|
80
92
|
* Holds its buffers between subjects; it is not reentrant, and nothing needs
|
|
81
|
-
* it to be - matching calls out to nothing.
|
|
93
|
+
* it to be - matching calls out to nothing. `test` empties each buffer before
|
|
94
|
+
* it reads one, so what a buffer starts with is never read.
|
|
82
95
|
*/
|
|
83
96
|
export declare class Matcher {
|
|
84
97
|
private readonly automaton;
|
|
@@ -29,13 +29,25 @@ const MATCH = 3;
|
|
|
29
29
|
* matched slowly.
|
|
30
30
|
*/
|
|
31
31
|
export const MAX_STATES = 65_536;
|
|
32
|
+
/**
|
|
33
|
+
* Thrown by the builder past {@link MAX_STATES}. `parseGlob` answers it as a
|
|
34
|
+
* refusal and `compileGlob` as a `GlobError`, so no function the pattern
|
|
35
|
+
* module exports lets it out; it stays exported for callers written when
|
|
36
|
+
* `parseGlob` did.
|
|
37
|
+
*/
|
|
32
38
|
export class AutomatonTooLarge extends Error {
|
|
33
39
|
constructor() {
|
|
34
40
|
super(`the pattern compiles to more than ${MAX_STATES} states`);
|
|
35
41
|
this.name = 'AutomatonTooLarge';
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Thompson's construction, one fragment at a time.
|
|
46
|
+
*
|
|
47
|
+
* An arrow written as -1 is a hole that `patch` aims before `finish` returns,
|
|
48
|
+
* or one nothing follows: a CHAR's second and both of a MATCH's. What it
|
|
49
|
+
* starts as is never read, so any other start gives the same automaton.
|
|
50
|
+
*/
|
|
39
51
|
export class Builder {
|
|
40
52
|
kinds = [];
|
|
41
53
|
first = [];
|
|
@@ -70,6 +82,10 @@ export class Builder {
|
|
|
70
82
|
}
|
|
71
83
|
/** Each fragment after the one before it. */
|
|
72
84
|
sequence(parts) {
|
|
85
|
+
// A glob never asks for an empty sequence, nor below for an empty
|
|
86
|
+
// alternation: a segment holds a token, a pattern an alternative. The two
|
|
87
|
+
// guards change no answer the module gives; they meet a misuse where it
|
|
88
|
+
// happens rather than in whatever reads the fragment next.
|
|
73
89
|
if (parts.length === 0)
|
|
74
90
|
return this.empty();
|
|
75
91
|
let current = parts[0];
|
|
@@ -151,7 +167,8 @@ function close(automaton, stack, visited, stamp, into) {
|
|
|
151
167
|
* A reusable matcher over one automaton.
|
|
152
168
|
*
|
|
153
169
|
* Holds its buffers between subjects; it is not reentrant, and nothing needs
|
|
154
|
-
* it to be - matching calls out to nothing.
|
|
170
|
+
* it to be - matching calls out to nothing. `test` empties each buffer before
|
|
171
|
+
* it reads one, so what a buffer starts with is never read.
|
|
155
172
|
*/
|
|
156
173
|
export class Matcher {
|
|
157
174
|
automaton;
|
|
@@ -187,6 +204,8 @@ export class Matcher {
|
|
|
187
204
|
this.stack.push(automaton.first[state]);
|
|
188
205
|
close(automaton, this.stack, this.visited, this.stamp, this.next);
|
|
189
206
|
}
|
|
207
|
+
// With no live state the rest of the subject changes nothing, and the
|
|
208
|
+
// answer is false either way; this only stops early.
|
|
190
209
|
if (this.next.length === 0)
|
|
191
210
|
return false;
|
|
192
211
|
const spent = this.live;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaton.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/pattern/automaton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,GAAG,EAAE,KAAK,EAAgB,MAAM,cAAc,CAAC;AAEtG,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,CAAC;AA0BhB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAEjC,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C;QACE,KAAK,CAAC,qCAAqC,UAAU,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,uDAAuD;AACvD,MAAM,OAAO,OAAO;IACD,KAAK,GAAa,EAAE,CAAC;IACrB,KAAK,GAAa,EAAE,CAAC;IACrB,MAAM,GAAa,EAAE,CAAC;IACtB,IAAI,GAAuB,EAA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,CAAC,KAA4B,EAAE,KAAa;IACxD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,KAAK,EAAG,KAAK,CAAC,CAAC,CAAgB,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,GAAI,KAAK,CAAC,CAAC,CAAgB,CAAC,MAAM,EAAE,CAAC;QAC9F,MAAM,CAAC,IAAI,CAAE,KAAK,CAAC,CAAC,CAAgB,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/**\n * Non-deterministic finite automata over code points: built by Thompson's\n * construction, run by keeping a set of live states, and searched for a\n * shortest string several of them accept and several others refuse.\n *\n * Why an automaton rather than a `RegExp`: a glob such as `*-*-*-*-*-*x`\n * handed to a backtracking engine tries every way of dividing a long name\n * between its stars, and one spec-* tool measured 28 seconds for one path. A\n * set of live states visits each state at most once per character, so a match\n * costs at most the pattern's size times the path's length, whatever the\n * pattern says.\n *\n * Why the same automaton for the witness: whether two scopes can name the same\n * file, and whether one lies wholly inside another, are questions about the\n * languages the patterns accept. Asked of the automata that do the matching,\n * the answers cannot drift from what matching does.\n */\n\nimport { accepts, acceptsIgnoringCase, boundaryPoints, DOT, SLASH, type CharSet } from './charset.js';\n\nconst CHAR = 0;\nconst SPLIT = 1;\nconst JUMP = 2;\nconst MATCH = 3;\n\n/** A compiled automaton. Immutable once built, and safe to share. */\nexport interface Automaton {\n readonly kinds: Uint8Array;\n /** A CHAR's next state, a SPLIT's first branch, a JUMP's target. */\n readonly first: Int32Array;\n /** A SPLIT's second branch. */\n readonly second: Int32Array;\n /** A CHAR's set; unused for the others. */\n readonly sets: readonly (CharSet | null)[];\n readonly start: number;\n readonly caseSensitive: boolean;\n}\n\n/** A piece of an automaton under construction: where it starts, and the arrows still unaimed. */\nexport interface Fragment {\n readonly start: number;\n readonly holes: readonly Hole[];\n}\n\ninterface Hole {\n readonly state: number;\n readonly slot: 1 | 2;\n}\n\n/**\n * Ceiling on the size of one automaton.\n *\n * Brace alternatives are compiled side by side, so a pattern's size is the\n * sum of its alternatives'. Far above anything a scope list says; it exists\n * so that a pathological pattern is refused while compiling rather than\n * matched slowly.\n */\nexport const MAX_STATES = 65_536;\n\nexport class AutomatonTooLarge extends Error {\n constructor() {\n super(`the pattern compiles to more than ${MAX_STATES} states`);\n this.name = 'AutomatonTooLarge';\n }\n}\n\n/** Thompson's construction, one fragment at a time. */\nexport class Builder {\n private readonly kinds: number[] = [];\n private readonly first: number[] = [];\n private readonly second: number[] = [];\n private readonly sets: (CharSet | null)[] = [];\n\n private add(kind: number, set: CharSet | null, first: number, second: number): number {\n if (this.kinds.length >= MAX_STATES) throw new AutomatonTooLarge();\n this.kinds.push(kind);\n this.first.push(first);\n this.second.push(second);\n this.sets.push(set);\n return this.kinds.length - 1;\n }\n\n private patch(holes: readonly Hole[], target: number): void {\n for (const hole of holes) {\n if (hole.slot === 1) this.first[hole.state] = target;\n else this.second[hole.state] = target;\n }\n }\n\n /** One character from a set. */\n char(set: CharSet): Fragment {\n const state = this.add(CHAR, set, -1, -1);\n return { start: state, holes: [{ state, slot: 1 }] };\n }\n\n /** The empty string. */\n empty(): Fragment {\n const state = this.add(JUMP, null, -1, -1);\n return { start: state, holes: [{ state, slot: 1 }] };\n }\n\n /** Each fragment after the one before it. */\n sequence(parts: readonly Fragment[]): Fragment {\n if (parts.length === 0) return this.empty();\n let current = parts[0] as Fragment;\n for (let i = 1; i < parts.length; i += 1) {\n const next = parts[i] as Fragment;\n this.patch(current.holes, next.start);\n current = { start: current.start, holes: next.holes };\n }\n return current;\n }\n\n /** Any one of the fragments. */\n either(options: readonly Fragment[]): Fragment {\n if (options.length === 0) throw new Error('an alternation needs at least one option');\n let current = options[options.length - 1] as Fragment;\n for (let i = options.length - 2; i >= 0; i -= 1) {\n const option = options[i] as Fragment;\n const split = this.add(SPLIT, null, option.start, current.start);\n current = { start: split, holes: [...option.holes, ...current.holes] };\n }\n return current;\n }\n\n /** Zero or more of a fragment. */\n star(body: Fragment): Fragment {\n const split = this.add(SPLIT, null, body.start, -1);\n this.patch(body.holes, split);\n return { start: split, holes: [{ state: split, slot: 2 }] };\n }\n\n /** One or more of a fragment. */\n plus(body: Fragment): Fragment {\n const split = this.add(SPLIT, null, body.start, -1);\n this.patch(body.holes, split);\n return { start: body.start, holes: [{ state: split, slot: 2 }] };\n }\n\n /** Zero or one of a fragment. */\n optional(body: Fragment): Fragment {\n const empty = this.empty();\n return this.either([body, empty]);\n }\n\n /** Closes the automaton: every unaimed arrow reaches acceptance. */\n finish(body: Fragment, caseSensitive: boolean): Automaton {\n const match = this.add(MATCH, null, -1, -1);\n this.patch(body.holes, match);\n return {\n kinds: Uint8Array.from(this.kinds),\n first: Int32Array.from(this.first),\n second: Int32Array.from(this.second),\n sets: [...this.sets],\n start: body.start,\n caseSensitive,\n };\n }\n}\n\n/**\n * Follows every empty arrow out of the states on a stack, appending each\n * CHAR or MATCH state reached to `into`. `visited[state] === stamp` marks a\n * state already taken this round, which is what bounds the work.\n */\nfunction close(\n automaton: Automaton,\n stack: number[],\n visited: Int32Array,\n stamp: number,\n into: number[],\n): void {\n const { kinds, first, second } = automaton;\n while (stack.length > 0) {\n const state = stack.pop() as number;\n if (visited[state] === stamp) continue;\n visited[state] = stamp;\n switch (kinds[state]) {\n case SPLIT:\n stack.push(second[state] as number, first[state] as number);\n break;\n case JUMP:\n stack.push(first[state] as number);\n break;\n default:\n into.push(state);\n }\n }\n}\n\n/**\n * A reusable matcher over one automaton.\n *\n * Holds its buffers between subjects; it is not reentrant, and nothing needs\n * it to be - matching calls out to nothing.\n */\nexport class Matcher {\n private readonly automaton: Automaton;\n private readonly visited: Int32Array;\n private stamp = 0;\n private readonly stack: number[] = [];\n private live: number[] = [];\n private next: number[] = [];\n\n constructor(automaton: Automaton) {\n this.automaton = automaton;\n this.visited = new Int32Array(automaton.kinds.length).fill(-1);\n }\n\n /** Whether the automaton accepts the whole of a subject. */\n test(subject: string): boolean {\n const { automaton } = this;\n const accept = automaton.caseSensitive ? accepts : acceptsIgnoringCase;\n this.live.length = 0;\n this.stack.length = 0;\n this.stack.push(automaton.start);\n this.stamp += 1;\n close(automaton, this.stack, this.visited, this.stamp, this.live);\n\n for (let i = 0; i < subject.length; i += 1) {\n const point = subject.codePointAt(i) as number;\n if (point > 0xffff) i += 1;\n this.next.length = 0;\n this.stamp += 1;\n for (const state of this.live) {\n if (automaton.kinds[state] !== CHAR) continue;\n if (!accept(automaton.sets[state] as CharSet, point)) continue;\n this.stack.push(automaton.first[state] as number);\n close(automaton, this.stack, this.visited, this.stamp, this.next);\n }\n if (this.next.length === 0) return false;\n const spent = this.live;\n this.live = this.next;\n this.next = spent;\n }\n return this.live.some((state) => automaton.kinds[state] === MATCH);\n }\n}\n\n/** The answer to a witness search. */\nexport type Witness =\n | { readonly kind: 'found'; readonly path: string }\n | { readonly kind: 'none' }\n /** The search met its budget before deciding. Rare, and never a guess either way. */\n | { readonly kind: 'undecided' };\n\n/**\n * How many distinct search states a witness search may visit. The search is\n * polynomial in the sizes of the automata it must satisfy and, for the ones\n * it must avoid, bounded by the subsets of their states it reaches; scope\n * patterns reach a handful. The bound turns a pathological input into an\n * `undecided` rather than a hang.\n */\nexport const WITNESS_BUDGET = 200_000;\n\n/**\n * Path validity as a four-state machine: at the start of a segment, inside a\n * segment reading `.` or `..` so far, or inside a segment that is a name. A\n * witness must end inside a name, and a `/` is only legal after one, so no\n * witness has an empty segment, a `.` or `..` segment, or a slash at either\n * end - which a pattern such as `a/*\\/b` would otherwise produce as `a//b`.\n * NUL is refused outright: no filesystem and no git tree holds a path with one.\n */\nconst SEGMENT_START = 0;\nconst ONE_DOT = 1;\nconst TWO_DOTS = 2;\nconst IN_NAME = 3;\nconst INVALID = -1;\nconst NUL = 0;\n\nfunction stepValidity(state: number, point: number): number {\n if (point === NUL) return INVALID;\n if (point === SLASH) return state === IN_NAME ? SEGMENT_START : INVALID;\n if (point === DOT) return state === SEGMENT_START ? ONE_DOT : state === ONE_DOT ? TWO_DOTS : IN_NAME;\n return IN_NAME;\n}\n\ninterface SearchNode {\n /** One live CHAR/MATCH state per automaton that must accept. */\n readonly positive: readonly number[];\n /** Every live state, sorted, per automaton that must refuse. */\n readonly negative: readonly (readonly number[])[];\n readonly validity: number;\n readonly parent: number;\n readonly point: number;\n}\n\nfunction closureOf(automaton: Automaton, seeds: readonly number[]): number[] {\n const visited = new Int32Array(automaton.kinds.length).fill(-1);\n const out: number[] = [];\n close(automaton, [...seeds], visited, 0, out);\n return out;\n}\n\nfunction stepSet(automaton: Automaton, states: readonly number[], point: number): number[] {\n const seeds: number[] = [];\n for (const state of states) {\n if (automaton.kinds[state] === CHAR && accepts(automaton.sets[state] as CharSet, point)) {\n seeds.push(automaton.first[state] as number);\n }\n }\n return closureOf(automaton, seeds).sort((a, b) => a - b);\n}\n\n/** Every way of choosing one element from each list. */\nfunction combinations(lists: readonly (readonly number[])[]): number[][] {\n let out: number[][] = [[]];\n for (const list of lists) {\n const grown: number[][] = [];\n for (const prefix of out) for (const state of list) grown.push([...prefix, state]);\n out = grown;\n }\n return out;\n}\n\nfunction isMatch(automaton: Automaton, state: number): boolean {\n return automaton.kinds[state] === MATCH;\n}\n\n/**\n * A shortest path every automaton in `include` accepts and none in `exclude`\n * does, spelled with readable characters where there is a choice.\n *\n * Breadth-first over the product of one live state per included automaton\n * (existential: some run of each must accept) and the whole live set per\n * excluded one (universal: no run of it may). Characters are tried at the\n * boundary points of every set in play, which meets every combination of\n * answers those sets can give, so the search is exact: `none` means no path\n * exists, not that none was found. The first path reached is a shortest one.\n *\n * Case-sensitive automata only. Every scope comparison in the family is\n * case-sensitive, and folding case exactly would need every set's closure\n * under case mapping.\n */\nexport function findWitness(\n include: readonly Automaton[],\n exclude: readonly Automaton[] = [],\n budget: number = WITNESS_BUDGET,\n): Witness {\n if (include.length === 0) throw new Error('a witness search needs at least one automaton to satisfy');\n for (const automaton of [...include, ...exclude]) {\n if (!automaton.caseSensitive) throw new Error('a witness search is defined for case-sensitive patterns only');\n }\n\n const startPositive = include.map((automaton) => closureOf(automaton, [automaton.start]));\n const startNegative = exclude.map((automaton) => closureOf(automaton, [automaton.start]).sort((a, b) => a - b));\n\n const nodes: SearchNode[] = [];\n const seen = new Set<string>();\n const key = (positive: readonly number[], negative: readonly (readonly number[])[], validity: number): string =>\n `${positive.join(',')}|${validity}|${negative.map((set) => set.join(',')).join('|')}`;\n\n const enqueue = (\n positive: readonly number[],\n negative: readonly (readonly number[])[],\n validity: number,\n parent: number,\n point: number,\n ): void => {\n const id = key(positive, negative, validity);\n if (seen.has(id)) return;\n seen.add(id);\n nodes.push({ positive, negative, validity, parent, point });\n };\n\n for (const positive of combinations(startPositive)) enqueue(positive, startNegative, SEGMENT_START, -1, 0);\n\n for (let cursor = 0; cursor < nodes.length; cursor += 1) {\n if (cursor >= budget) return { kind: 'undecided' };\n const node = nodes[cursor] as SearchNode;\n\n const accepted = node.positive.every((state, i) => isMatch(include[i] as Automaton, state));\n const refused = node.negative.every((set, i) => !set.some((state) => isMatch(exclude[i] as Automaton, state)));\n if (accepted && refused && node.validity === IN_NAME) return { kind: 'found', path: spell(nodes, cursor) };\n\n // A MATCH state reads nothing more: an included automaton sitting on one\n // can only accept here, so no longer path extends this node.\n if (node.positive.some((state, i) => (include[i] as Automaton).kinds[state] !== CHAR)) continue;\n\n const sets: CharSet[] = [];\n node.positive.forEach((state, i) => sets.push((include[i] as Automaton).sets[state] as CharSet));\n node.negative.forEach((set, i) => {\n const automaton = exclude[i] as Automaton;\n for (const state of set) if (automaton.kinds[state] === CHAR) sets.push(automaton.sets[state] as CharSet);\n });\n\n // Where each included automaton goes next does not depend on the\n // character, only whether it may go; what the excluded ones reach does.\n const successors = combinations(\n node.positive.map((state, i) => closureOf(include[i] as Automaton, [(include[i] as Automaton).first[state] as number])),\n );\n for (const point of boundaryPoints(sets)) {\n const validity = stepValidity(node.validity, point);\n if (validity === INVALID) continue;\n if (!node.positive.every((state, i) => accepts((include[i] as Automaton).sets[state] as CharSet, point))) {\n continue;\n }\n const negative = node.negative.map((set, i) => stepSet(exclude[i] as Automaton, set, point));\n for (const positive of successors) enqueue(positive, negative, validity, cursor, point);\n }\n }\n return { kind: 'none' };\n}\n\nfunction spell(nodes: readonly SearchNode[], index: number): string {\n const points: number[] = [];\n for (let i = index; (nodes[i] as SearchNode).parent >= 0; i = (nodes[i] as SearchNode).parent) {\n points.push((nodes[i] as SearchNode).point);\n }\n return String.fromCodePoint(...points.reverse());\n}\n"]}
|
|
1
|
+
{"version":3,"file":"automaton.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/pattern/automaton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,GAAG,EAAE,KAAK,EAAgB,MAAM,cAAc,CAAC;AAEtG,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,CAAC;AA0BhB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C;QACE,KAAK,CAAC,qCAAqC,UAAU,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,OAAO;IACD,KAAK,GAAa,EAAE,CAAC;IACrB,KAAK,GAAa,EAAE,CAAC;IACrB,MAAM,GAAa,EAAE,CAAC;IACtB,IAAI,GAAuB,EAAE,CAAC;IAEvC,GAAG,CAAC,IAAY,EAAE,GAAmB,EAAE,KAAa,EAAE,MAAc;QAC1E,IAAI,IAA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AK,CAAC,KAA4B,EAAE,KAAa;IACxD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,KAAK,EAAG,KAAK,CAAC,CAAC,CAAgB,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,GAAI,KAAK,CAAC,CAAC,CAAgB,CAAC,MAAM,EAAE,CAAC;QAC9F,MAAM,CAAC,IAAI,CAAE,KAAK,CAAC,CAAC,CAAgB,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/**\n * Non-deterministic finite automata over code points: built by Thompson's\n * construction, run by keeping a set of live states, and searched for a\n * shortest string several of them accept and several others refuse.\n *\n * Why an automaton rather than a `RegExp`: a glob such as `*-*-*-*-*-*x`\n * handed to a backtracking engine tries every way of dividing a long name\n * between its stars, and one spec-* tool measured 28 seconds for one path. A\n * set of live states visits each state at most once per character, so a match\n * costs at most the pattern's size times the path's length, whatever the\n * pattern says.\n *\n * Why the same automaton for the witness: whether two scopes can name the same\n * file, and whether one lies wholly inside another, are questions about the\n * languages the patterns accept. Asked of the automata that do the matching,\n * the answers cannot drift from what matching does.\n */\n\nimport { accepts, acceptsIgnoringCase, boundaryPoints, DOT, SLASH, type CharSet } from './charset.js';\n\nconst CHAR = 0;\nconst SPLIT = 1;\nconst JUMP = 2;\nconst MATCH = 3;\n\n/** A compiled automaton. Immutable once built, and safe to share. */\nexport interface Automaton {\n readonly kinds: Uint8Array;\n /** A CHAR's next state, a SPLIT's first branch, a JUMP's target. */\n readonly first: Int32Array;\n /** A SPLIT's second branch. */\n readonly second: Int32Array;\n /** A CHAR's set; unused for the others. */\n readonly sets: readonly (CharSet | null)[];\n readonly start: number;\n readonly caseSensitive: boolean;\n}\n\n/** A piece of an automaton under construction: where it starts, and the arrows still unaimed. */\nexport interface Fragment {\n readonly start: number;\n readonly holes: readonly Hole[];\n}\n\ninterface Hole {\n readonly state: number;\n readonly slot: 1 | 2;\n}\n\n/**\n * Ceiling on the size of one automaton.\n *\n * Brace alternatives are compiled side by side, so a pattern's size is the\n * sum of its alternatives'. Far above anything a scope list says; it exists\n * so that a pathological pattern is refused while compiling rather than\n * matched slowly.\n */\nexport const MAX_STATES = 65_536;\n\n/**\n * Thrown by the builder past {@link MAX_STATES}. `parseGlob` answers it as a\n * refusal and `compileGlob` as a `GlobError`, so no function the pattern\n * module exports lets it out; it stays exported for callers written when\n * `parseGlob` did.\n */\nexport class AutomatonTooLarge extends Error {\n constructor() {\n super(`the pattern compiles to more than ${MAX_STATES} states`);\n this.name = 'AutomatonTooLarge';\n }\n}\n\n/**\n * Thompson's construction, one fragment at a time.\n *\n * An arrow written as -1 is a hole that `patch` aims before `finish` returns,\n * or one nothing follows: a CHAR's second and both of a MATCH's. What it\n * starts as is never read, so any other start gives the same automaton.\n */\nexport class Builder {\n private readonly kinds: number[] = [];\n private readonly first: number[] = [];\n private readonly second: number[] = [];\n private readonly sets: (CharSet | null)[] = [];\n\n private add(kind: number, set: CharSet | null, first: number, second: number): number {\n if (this.kinds.length >= MAX_STATES) throw new AutomatonTooLarge();\n this.kinds.push(kind);\n this.first.push(first);\n this.second.push(second);\n this.sets.push(set);\n return this.kinds.length - 1;\n }\n\n private patch(holes: readonly Hole[], target: number): void {\n for (const hole of holes) {\n if (hole.slot === 1) this.first[hole.state] = target;\n else this.second[hole.state] = target;\n }\n }\n\n /** One character from a set. */\n char(set: CharSet): Fragment {\n const state = this.add(CHAR, set, -1, -1);\n return { start: state, holes: [{ state, slot: 1 }] };\n }\n\n /** The empty string. */\n empty(): Fragment {\n const state = this.add(JUMP, null, -1, -1);\n return { start: state, holes: [{ state, slot: 1 }] };\n }\n\n /** Each fragment after the one before it. */\n sequence(parts: readonly Fragment[]): Fragment {\n // A glob never asks for an empty sequence, nor below for an empty\n // alternation: a segment holds a token, a pattern an alternative. The two\n // guards change no answer the module gives; they meet a misuse where it\n // happens rather than in whatever reads the fragment next.\n if (parts.length === 0) return this.empty();\n let current = parts[0] as Fragment;\n for (let i = 1; i < parts.length; i += 1) {\n const next = parts[i] as Fragment;\n this.patch(current.holes, next.start);\n current = { start: current.start, holes: next.holes };\n }\n return current;\n }\n\n /** Any one of the fragments. */\n either(options: readonly Fragment[]): Fragment {\n if (options.length === 0) throw new Error('an alternation needs at least one option');\n let current = options[options.length - 1] as Fragment;\n for (let i = options.length - 2; i >= 0; i -= 1) {\n const option = options[i] as Fragment;\n const split = this.add(SPLIT, null, option.start, current.start);\n current = { start: split, holes: [...option.holes, ...current.holes] };\n }\n return current;\n }\n\n /** Zero or more of a fragment. */\n star(body: Fragment): Fragment {\n const split = this.add(SPLIT, null, body.start, -1);\n this.patch(body.holes, split);\n return { start: split, holes: [{ state: split, slot: 2 }] };\n }\n\n /** One or more of a fragment. */\n plus(body: Fragment): Fragment {\n const split = this.add(SPLIT, null, body.start, -1);\n this.patch(body.holes, split);\n return { start: body.start, holes: [{ state: split, slot: 2 }] };\n }\n\n /** Zero or one of a fragment. */\n optional(body: Fragment): Fragment {\n const empty = this.empty();\n return this.either([body, empty]);\n }\n\n /** Closes the automaton: every unaimed arrow reaches acceptance. */\n finish(body: Fragment, caseSensitive: boolean): Automaton {\n const match = this.add(MATCH, null, -1, -1);\n this.patch(body.holes, match);\n return {\n kinds: Uint8Array.from(this.kinds),\n first: Int32Array.from(this.first),\n second: Int32Array.from(this.second),\n sets: [...this.sets],\n start: body.start,\n caseSensitive,\n };\n }\n}\n\n/**\n * Follows every empty arrow out of the states on a stack, appending each\n * CHAR or MATCH state reached to `into`. `visited[state] === stamp` marks a\n * state already taken this round, which is what bounds the work.\n */\nfunction close(\n automaton: Automaton,\n stack: number[],\n visited: Int32Array,\n stamp: number,\n into: number[],\n): void {\n const { kinds, first, second } = automaton;\n while (stack.length > 0) {\n const state = stack.pop() as number;\n if (visited[state] === stamp) continue;\n visited[state] = stamp;\n switch (kinds[state]) {\n case SPLIT:\n stack.push(second[state] as number, first[state] as number);\n break;\n case JUMP:\n stack.push(first[state] as number);\n break;\n default:\n into.push(state);\n }\n }\n}\n\n/**\n * A reusable matcher over one automaton.\n *\n * Holds its buffers between subjects; it is not reentrant, and nothing needs\n * it to be - matching calls out to nothing. `test` empties each buffer before\n * it reads one, so what a buffer starts with is never read.\n */\nexport class Matcher {\n private readonly automaton: Automaton;\n private readonly visited: Int32Array;\n private stamp = 0;\n private readonly stack: number[] = [];\n private live: number[] = [];\n private next: number[] = [];\n\n constructor(automaton: Automaton) {\n this.automaton = automaton;\n this.visited = new Int32Array(automaton.kinds.length).fill(-1);\n }\n\n /** Whether the automaton accepts the whole of a subject. */\n test(subject: string): boolean {\n const { automaton } = this;\n const accept = automaton.caseSensitive ? accepts : acceptsIgnoringCase;\n this.live.length = 0;\n this.stack.length = 0;\n this.stack.push(automaton.start);\n this.stamp += 1;\n close(automaton, this.stack, this.visited, this.stamp, this.live);\n\n for (let i = 0; i < subject.length; i += 1) {\n const point = subject.codePointAt(i) as number;\n if (point > 0xffff) i += 1;\n this.next.length = 0;\n this.stamp += 1;\n for (const state of this.live) {\n if (automaton.kinds[state] !== CHAR) continue;\n if (!accept(automaton.sets[state] as CharSet, point)) continue;\n this.stack.push(automaton.first[state] as number);\n close(automaton, this.stack, this.visited, this.stamp, this.next);\n }\n // With no live state the rest of the subject changes nothing, and the\n // answer is false either way; this only stops early.\n if (this.next.length === 0) return false;\n const spent = this.live;\n this.live = this.next;\n this.next = spent;\n }\n return this.live.some((state) => automaton.kinds[state] === MATCH);\n }\n}\n\n/** The answer to a witness search. */\nexport type Witness =\n | { readonly kind: 'found'; readonly path: string }\n | { readonly kind: 'none' }\n /** The search met its budget before deciding. Rare, and never a guess either way. */\n | { readonly kind: 'undecided' };\n\n/**\n * How many distinct search states a witness search may visit. The search is\n * polynomial in the sizes of the automata it must satisfy and, for the ones\n * it must avoid, bounded by the subsets of their states it reaches; scope\n * patterns reach a handful. The bound turns a pathological input into an\n * `undecided` rather than a hang.\n */\nexport const WITNESS_BUDGET = 200_000;\n\n/**\n * Path validity as a four-state machine: at the start of a segment, inside a\n * segment reading `.` or `..` so far, or inside a segment that is a name. A\n * witness must end inside a name, and a `/` is only legal after one, so no\n * witness has an empty segment, a `.` or `..` segment, or a slash at either\n * end - which a pattern such as `a/*\\/b` would otherwise produce as `a//b`.\n * NUL is refused outright: no filesystem and no git tree holds a path with one.\n */\nconst SEGMENT_START = 0;\nconst ONE_DOT = 1;\nconst TWO_DOTS = 2;\nconst IN_NAME = 3;\nconst INVALID = -1;\nconst NUL = 0;\n\nfunction stepValidity(state: number, point: number): number {\n if (point === NUL) return INVALID;\n if (point === SLASH) return state === IN_NAME ? SEGMENT_START : INVALID;\n if (point === DOT) return state === SEGMENT_START ? ONE_DOT : state === ONE_DOT ? TWO_DOTS : IN_NAME;\n return IN_NAME;\n}\n\ninterface SearchNode {\n /** One live CHAR/MATCH state per automaton that must accept. */\n readonly positive: readonly number[];\n /** Every live state, sorted, per automaton that must refuse. */\n readonly negative: readonly (readonly number[])[];\n readonly validity: number;\n readonly parent: number;\n readonly point: number;\n}\n\nfunction closureOf(automaton: Automaton, seeds: readonly number[]): number[] {\n const visited = new Int32Array(automaton.kinds.length).fill(-1);\n const out: number[] = [];\n close(automaton, [...seeds], visited, 0, out);\n return out;\n}\n\nfunction stepSet(automaton: Automaton, states: readonly number[], point: number): number[] {\n const seeds: number[] = [];\n for (const state of states) {\n if (automaton.kinds[state] === CHAR && accepts(automaton.sets[state] as CharSet, point)) {\n seeds.push(automaton.first[state] as number);\n }\n }\n return closureOf(automaton, seeds).sort((a, b) => a - b);\n}\n\n/** Every way of choosing one element from each list. */\nfunction combinations(lists: readonly (readonly number[])[]): number[][] {\n let out: number[][] = [[]];\n for (const list of lists) {\n const grown: number[][] = [];\n for (const prefix of out) for (const state of list) grown.push([...prefix, state]);\n out = grown;\n }\n return out;\n}\n\nfunction isMatch(automaton: Automaton, state: number): boolean {\n return automaton.kinds[state] === MATCH;\n}\n\n/**\n * A shortest path every automaton in `include` accepts and none in `exclude`\n * does, spelled with readable characters where there is a choice.\n *\n * Breadth-first over the product of one live state per included automaton\n * (existential: some run of each must accept) and the whole live set per\n * excluded one (universal: no run of it may). Characters are tried at the\n * boundary points of every set in play, which meets every combination of\n * answers those sets can give, so the search is exact: `none` means no path\n * exists, not that none was found. The first path reached is a shortest one.\n *\n * Case-sensitive automata only. Every scope comparison in the family is\n * case-sensitive, and folding case exactly would need every set's closure\n * under case mapping.\n */\nexport function findWitness(\n include: readonly Automaton[],\n exclude: readonly Automaton[] = [],\n budget: number = WITNESS_BUDGET,\n): Witness {\n if (include.length === 0) throw new Error('a witness search needs at least one automaton to satisfy');\n for (const automaton of [...include, ...exclude]) {\n if (!automaton.caseSensitive) throw new Error('a witness search is defined for case-sensitive patterns only');\n }\n\n const startPositive = include.map((automaton) => closureOf(automaton, [automaton.start]));\n const startNegative = exclude.map((automaton) => closureOf(automaton, [automaton.start]).sort((a, b) => a - b));\n\n const nodes: SearchNode[] = [];\n const seen = new Set<string>();\n const key = (positive: readonly number[], negative: readonly (readonly number[])[], validity: number): string =>\n `${positive.join(',')}|${validity}|${negative.map((set) => set.join(',')).join('|')}`;\n\n const enqueue = (\n positive: readonly number[],\n negative: readonly (readonly number[])[],\n validity: number,\n parent: number,\n point: number,\n ): void => {\n const id = key(positive, negative, validity);\n if (seen.has(id)) return;\n seen.add(id);\n nodes.push({ positive, negative, validity, parent, point });\n };\n\n for (const positive of combinations(startPositive)) enqueue(positive, startNegative, SEGMENT_START, -1, 0);\n\n for (let cursor = 0; cursor < nodes.length; cursor += 1) {\n if (cursor >= budget) return { kind: 'undecided' };\n const node = nodes[cursor] as SearchNode;\n\n const accepted = node.positive.every((state, i) => isMatch(include[i] as Automaton, state));\n const refused = node.negative.every((set, i) => !set.some((state) => isMatch(exclude[i] as Automaton, state)));\n if (accepted && refused && node.validity === IN_NAME) return { kind: 'found', path: spell(nodes, cursor) };\n\n // A MATCH state reads nothing more: an included automaton sitting on one\n // can only accept here, so no longer path extends this node.\n if (node.positive.some((state, i) => (include[i] as Automaton).kinds[state] !== CHAR)) continue;\n\n const sets: CharSet[] = [];\n node.positive.forEach((state, i) => sets.push((include[i] as Automaton).sets[state] as CharSet));\n node.negative.forEach((set, i) => {\n const automaton = exclude[i] as Automaton;\n for (const state of set) if (automaton.kinds[state] === CHAR) sets.push(automaton.sets[state] as CharSet);\n });\n\n // Where each included automaton goes next does not depend on the\n // character, only whether it may go; what the excluded ones reach does.\n const successors = combinations(\n node.positive.map((state, i) => closureOf(include[i] as Automaton, [(include[i] as Automaton).first[state] as number])),\n );\n for (const point of boundaryPoints(sets)) {\n const validity = stepValidity(node.validity, point);\n if (validity === INVALID) continue;\n if (!node.positive.every((state, i) => accepts((include[i] as Automaton).sets[state] as CharSet, point))) {\n continue;\n }\n const negative = node.negative.map((set, i) => stepSet(exclude[i] as Automaton, set, point));\n for (const positive of successors) enqueue(positive, negative, validity, cursor, point);\n }\n }\n return { kind: 'none' };\n}\n\nfunction spell(nodes: readonly SearchNode[], index: number): string {\n const points: number[] = [];\n for (let i = index; (nodes[i] as SearchNode).parent >= 0; i = (nodes[i] as SearchNode).parent) {\n points.push((nodes[i] as SearchNode).point);\n }\n return String.fromCodePoint(...points.reverse());\n}\n"]}
|
|
@@ -21,7 +21,11 @@ export interface CharSet {
|
|
|
21
21
|
export declare const SLASH = 47;
|
|
22
22
|
export declare const DOT = 46;
|
|
23
23
|
export declare const MAX_CODE_POINT = 1114111;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The separator, and nothing else. `separator` is what `accepts` asks; the
|
|
26
|
+
* range is read only for the points a witness search tries, and `/` and `0`,
|
|
27
|
+
* the point after it, are tried whatever the sets hold.
|
|
28
|
+
*/
|
|
25
29
|
export declare const SEPARATOR: CharSet;
|
|
26
30
|
/** Any character but the separator: `?`, and the body of `*`. */
|
|
27
31
|
export declare const ANY: CharSet;
|
|
@@ -13,11 +13,18 @@
|
|
|
13
13
|
export const SLASH = 0x2f;
|
|
14
14
|
export const DOT = 0x2e;
|
|
15
15
|
export const MAX_CODE_POINT = 0x10ffff;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The separator, and nothing else. `separator` is what `accepts` asks; the
|
|
18
|
+
* range is read only for the points a witness search tries, and `/` and `0`,
|
|
19
|
+
* the point after it, are tried whatever the sets hold.
|
|
20
|
+
*/
|
|
17
21
|
export const SEPARATOR = { negated: false, ranges: [[SLASH, SLASH]], separator: true };
|
|
18
22
|
/** Any character but the separator: `?`, and the body of `*`. */
|
|
19
23
|
export const ANY = { negated: true, ranges: [], separator: false };
|
|
20
24
|
export function literalSet(point) {
|
|
25
|
+
// A glob's literals are read from inside one segment, so none is `/` and
|
|
26
|
+
// `separator` is false for every one compiled; it is computed so the set
|
|
27
|
+
// holds true for any point it is given.
|
|
21
28
|
return { negated: false, ranges: [[point, point]], separator: point === SLASH };
|
|
22
29
|
}
|
|
23
30
|
export function classSet(ranges, negated) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charset.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/pattern/charset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAYH,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC;AAC1B,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC;AACxB,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"charset.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/pattern/charset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAYH,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC;AAC1B,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC;AACxB,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,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CAAC;QAAE,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAW,CAAC,CAAC;IAC3G,OAAO,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAU,CAAC;AAEvF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,IAAwB;IACrD,kFAAkF;IAClF,MAAM,MAAM,GAAa,CAAC,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC1C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,IAAI,IAAI,GAAG,cAAc;gBAAE,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,SAAS;QAC9B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Sets of characters a glob position accepts, over Unicode code points.\n *\n * A glob matches a path one character at a time, and a character is a code\n * point: `?` matches `é` whether it is stored as one UTF-16 unit or not, and an\n * emoji as one. That is what a person counting characters in a file name\n * expects, and it is the same on every host.\n *\n * No set but the separator's accepts `/`. A path is matched a segment at a\n * time, and a `*` or a `[!a]` that swallowed a slash would let one segment of\n * a pattern match two of a path.\n */\n\n/** An inclusive range of code points. */\nexport type CodeRange = readonly [number, number];\n\nexport interface CharSet {\n readonly negated: boolean;\n readonly ranges: readonly CodeRange[];\n /** True only for the path separator itself. */\n readonly separator: boolean;\n}\n\nexport const SLASH = 0x2f;\nexport const DOT = 0x2e;\nexport const MAX_CODE_POINT = 0x10ffff;\n\n/**\n * The separator, and nothing else. `separator` is what `accepts` asks; the\n * range is read only for the points a witness search tries, and `/` and `0`,\n * the point after it, are tried whatever the sets hold.\n */\nexport const SEPARATOR: CharSet = { negated: false, ranges: [[SLASH, SLASH]], separator: true };\n\n/** Any character but the separator: `?`, and the body of `*`. */\nexport const ANY: CharSet = { negated: true, ranges: [], separator: false };\n\nexport function literalSet(point: number): CharSet {\n // A glob's literals are read from inside one segment, so none is `/` and\n // `separator` is false for every one compiled; it is computed so the set\n // holds true for any point it is given.\n return { negated: false, ranges: [[point, point]], separator: point === SLASH };\n}\n\nexport function classSet(ranges: readonly CodeRange[], negated: boolean): CharSet {\n return { negated, ranges, separator: false };\n}\n\nfunction within(ranges: readonly CodeRange[], point: number): boolean {\n for (let i = 0; i < ranges.length; i += 1) {\n const range = ranges[i] as CodeRange;\n if (point >= range[0] && point <= range[1]) return true;\n }\n return false;\n}\n\n/** Whether a set accepts a code point as written. */\nexport function accepts(set: CharSet, point: number): boolean {\n if (point === SLASH) return set.separator;\n return within(set.ranges, point) !== set.negated;\n}\n\n/**\n * The code points a code point is the same letter as, ignoring case: itself,\n * and its lower- and upper-case forms where each is a single code point.\n *\n * Simple case mapping, which is what `toLowerCase` and `toUpperCase` give one\n * character at a time. It is locale-free, so two hosts agree; `ß` has no single\n * upper-case code point and so matches only itself.\n */\nexport function caseVariants(point: number): readonly number[] {\n if (point < 0x80) {\n if (point >= 0x41 && point <= 0x5a) return [point, point + 32];\n if (point >= 0x61 && point <= 0x7a) return [point, point - 32];\n return [point];\n }\n const char = String.fromCodePoint(point);\n const out = [point];\n for (const variant of [char.toLowerCase(), char.toUpperCase()]) {\n const code = variant.codePointAt(0) as number;\n if (variant.length === String.fromCodePoint(code).length && !out.includes(code)) out.push(code);\n }\n return out;\n}\n\n/**\n * Whether a set accepts a code point with case ignored: whether it accepts\n * the point or one of its case variants. A negated set is negated over the\n * same question, so `[!a]` refuses `A` as well as `a`.\n */\nexport function acceptsIgnoringCase(set: CharSet, point: number): boolean {\n if (point === SLASH) return set.separator;\n const variants = caseVariants(point);\n let inside = false;\n for (let i = 0; i < variants.length && !inside; i += 1) inside = within(set.ranges, variants[i] as number);\n return inside !== set.negated;\n}\n\n/**\n * Characters a witness is spelled with when any of them will do, in order of\n * preference. A witness is read by a person deciding whether two scopes really\n * overlap, and `src/x.ts` reads better than `src/\\u0000.ts`.\n */\nconst READABLE = [0x78, 0x61, 0x62, 0x30, 0x5f, 0x2d, 0x7e, 0x21, DOT, SLASH] as const;\n\n/**\n * Every code point at which the answer \"which of these sets accept it\" can\n * change, readable ones first.\n *\n * Each set accepts a union of intervals, so the sets' memberships are constant\n * between consecutive interval ends. The start of each interval and the point\n * after its end therefore meet every distinct combination of answers, and\n * trying them all decides every question a witness search can ask of one\n * character. The separator and the dot are always included: path validity\n * turns on them.\n */\nexport function boundaryPoints(sets: readonly CharSet[]): number[] {\n // 1, not 0: no path holds a NUL, so the least character worth trying is the next.\n const points: number[] = [...READABLE, 1];\n for (const set of sets) {\n for (const [low, high] of set.ranges) {\n points.push(low);\n if (high < MAX_CODE_POINT) points.push(high + 1);\n }\n }\n const seen = new Set<number>();\n const out: number[] = [];\n for (const point of points) {\n if (seen.has(point)) continue;\n seen.add(point);\n out.push(point);\n }\n return out;\n}\n"]}
|
|
@@ -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 `{`,
|
|
@@ -46,7 +49,8 @@ export interface GlobOptions {
|
|
|
46
49
|
* `path` dialect only: how a pattern with no glob syntax is read - as a
|
|
47
50
|
* file, as a directory and everything beneath it, or as either. A function
|
|
48
51
|
* is asked per literal path, for a caller that knows the tree. `either` when
|
|
49
|
-
* unset. A trailing
|
|
52
|
+
* unset. A trailing `/`, on the pattern or on one of its brace alternatives,
|
|
53
|
+
* always means a directory's contents, and is never asked about.
|
|
50
54
|
*/
|
|
51
55
|
readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;
|
|
52
56
|
/**
|
|
@@ -85,9 +89,16 @@ export declare class GlobError extends Error {
|
|
|
85
89
|
export declare const MAX_ALTERNATIVES = 256;
|
|
86
90
|
/** Whether a string uses glob syntax at all. */
|
|
87
91
|
export declare function isGlobSyntax(source: string): boolean;
|
|
88
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Parses and compiles a glob, or says why it cannot: malformed, or too large
|
|
94
|
+
* to compile, past {@link MAX_ALTERNATIVES} alternatives or `MAX_STATES`
|
|
95
|
+
* states. It throws only what a `literal` function throws.
|
|
96
|
+
*/
|
|
89
97
|
export declare function parseGlob(source: string, options: GlobOptions): GlobParse;
|
|
90
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Parses and compiles a glob, throwing {@link GlobError} for every reason
|
|
100
|
+
* {@link parseGlob} gives, and what a `literal` function throws.
|
|
101
|
+
*/
|
|
91
102
|
export declare function compileGlob(source: string, options: GlobOptions): Glob;
|
|
92
103
|
/**
|
|
93
104
|
* A shortest path every glob in `include` matches and no glob in `exclude`
|
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EACL,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;AA2CpF,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,MAAM,CAAS;IACxB,YAAY,MAAc,EAAE,MAAc;QACxC,KAAK,CAAC,iBAAiB,MAAM,MAAM,MAAM,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAgBpC,gDAAgD;AAChD,MAAM,UAAU,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,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC;AAC9E,CAAC;AAYD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAA2B,EAAE,OAAoB;IAC7E,MAAM,OAAO,GAAuC,EAAE,CAAC;IACvD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,OAAO,MAAM,MAAM,CAAC,KAAK,EAAE,EAAE,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,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAgBpC,gDAAgD;AAChD,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,OAAoB;IAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,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O,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC;AAC9E,CAAC;AAYD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAA2B,EAAE,OAAoB;IAC7E,MAAM,OAAO,GAAuC,EAAE,CAAC;IACvD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,OAAO,MAAM,MAAM,CAAC,KAAK,EAAE,EAAE,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 * - 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
|
-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,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,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,4EAA4E;IAC5E,mCAAmC;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,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,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;QAC7D,MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IACD,OAAO,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9D,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACvE,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 // 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.3.
|
|
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",
|