@descent-vtt/spec-harness 0.0.0 → 0.1.0
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 +16 -0
- package/.claude-plugin/plugin.json +17 -0
- package/.mcp.json +12 -0
- package/CHANGELOG.md +46 -0
- package/README.md +127 -9
- package/bin/spec-harness.js +19 -0
- package/dist/audit.d.ts +69 -0
- package/dist/audit.js +93 -0
- package/dist/audit.js.map +1 -0
- package/dist/branch.d.ts +26 -0
- package/dist/branch.js +100 -0
- package/dist/branch.js.map +1 -0
- package/dist/briefs.d.ts +49 -0
- package/dist/briefs.js +111 -0
- package/dist/briefs.js.map +1 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.js +245 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +18 -0
- package/dist/commands.js +224 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +57 -0
- package/dist/config.js +167 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +56 -0
- package/dist/context.js +125 -0
- package/dist/context.js.map +1 -0
- package/dist/document.d.ts +33 -0
- package/dist/document.js +9 -0
- package/dist/document.js.map +1 -0
- package/dist/fs.d.ts +29 -0
- package/dist/fs.js +85 -0
- package/dist/fs.js.map +1 -0
- package/dist/git.d.ts +57 -0
- package/dist/git.js +129 -0
- package/dist/git.js.map +1 -0
- package/dist/guard.d.ts +43 -0
- package/dist/guard.js +120 -0
- package/dist/guard.js.map +1 -0
- package/dist/hooks.d.ts +50 -0
- package/dist/hooks.js +109 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/junit.d.ts +30 -0
- package/dist/junit.js +166 -0
- package/dist/junit.js.map +1 -0
- package/dist/manifests.d.ts +52 -0
- package/dist/manifests.js +346 -0
- package/dist/manifests.js.map +1 -0
- package/dist/plugin.d.ts +45 -0
- package/dist/plugin.js +79 -0
- package/dist/plugin.js.map +1 -0
- package/dist/premises.d.ts +16 -0
- package/dist/premises.js +71 -0
- package/dist/premises.js.map +1 -0
- package/dist/probe.d.ts +108 -0
- package/dist/probe.js +203 -0
- package/dist/probe.js.map +1 -0
- package/dist/reader.d.ts +8 -0
- package/dist/reader.js +105 -0
- package/dist/reader.js.map +1 -0
- package/dist/round.d.ts +68 -0
- package/dist/round.js +339 -0
- package/dist/round.js.map +1 -0
- package/dist/rulings.d.ts +92 -0
- package/dist/rulings.js +160 -0
- package/dist/rulings.js.map +1 -0
- package/dist/sandbox.d.ts +28 -0
- package/dist/sandbox.js +110 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +212 -0
- package/dist/server.js.map +1 -0
- package/dist/setup.d.ts +32 -0
- package/dist/setup.js +218 -0
- package/dist/setup.js.map +1 -0
- package/dist/siblings.d.ts +66 -0
- package/dist/siblings.js +134 -0
- package/dist/siblings.js.map +1 -0
- package/dist/types.d.ts +38 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/vendor/spec-core/jsonrpc/index.d.ts +2 -0
- package/dist/vendor/spec-core/jsonrpc/index.js +2 -0
- package/dist/vendor/spec-core/jsonrpc/index.js.map +1 -0
- package/dist/vendor/spec-core/jsonrpc/mcp.d.ts +157 -0
- package/dist/vendor/spec-core/jsonrpc/mcp.js +353 -0
- package/dist/vendor/spec-core/jsonrpc/mcp.js.map +1 -0
- package/dist/vendor/spec-core/markdown/frontmatter.d.ts +103 -0
- package/dist/vendor/spec-core/markdown/frontmatter.js +459 -0
- package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -0
- package/dist/vendor/spec-core/markdown/headings.d.ts +45 -0
- package/dist/vendor/spec-core/markdown/headings.js +199 -0
- package/dist/vendor/spec-core/markdown/headings.js.map +1 -0
- package/dist/vendor/spec-core/markdown/index.d.ts +5 -0
- package/dist/vendor/spec-core/markdown/index.js +4 -0
- package/dist/vendor/spec-core/markdown/index.js.map +1 -0
- package/dist/vendor/spec-core/markdown/layout.d.ts +39 -0
- package/dist/vendor/spec-core/markdown/layout.js +28 -0
- package/dist/vendor/spec-core/markdown/layout.js.map +1 -0
- package/dist/vendor/spec-core/markdown/links.d.ts +22 -0
- package/dist/vendor/spec-core/markdown/links.js +364 -0
- package/dist/vendor/spec-core/markdown/links.js.map +1 -0
- package/dist/vendor/spec-core/markdown/lists.d.ts +22 -0
- package/dist/vendor/spec-core/markdown/lists.js +127 -0
- package/dist/vendor/spec-core/markdown/lists.js.map +1 -0
- package/dist/vendor/spec-core/markdown/scan.d.ts +36 -0
- package/dist/vendor/spec-core/markdown/scan.js +439 -0
- package/dist/vendor/spec-core/markdown/scan.js.map +1 -0
- package/dist/vendor/spec-core/markdown/syntax.d.ts +75 -0
- package/dist/vendor/spec-core/markdown/syntax.js +181 -0
- package/dist/vendor/spec-core/markdown/syntax.js.map +1 -0
- package/dist/vendor/spec-core/markdown/tables.d.ts +18 -0
- package/dist/vendor/spec-core/markdown/tables.js +86 -0
- package/dist/vendor/spec-core/markdown/tables.js.map +1 -0
- package/dist/vendor/spec-core/markdown/types.d.ts +287 -0
- package/dist/vendor/spec-core/markdown/types.js +9 -0
- package/dist/vendor/spec-core/markdown/types.js.map +1 -0
- package/dist/vendor/spec-core/path/index.d.ts +1 -0
- package/dist/vendor/spec-core/path/index.js +2 -0
- package/dist/vendor/spec-core/path/index.js.map +1 -0
- package/dist/vendor/spec-core/path/posix.d.ts +83 -0
- package/dist/vendor/spec-core/path/posix.js +150 -0
- package/dist/vendor/spec-core/path/posix.js.map +1 -0
- package/dist/vendor/spec-core/pattern/automaton.d.ts +129 -0
- package/dist/vendor/spec-core/pattern/automaton.js +340 -0
- package/dist/vendor/spec-core/pattern/automaton.js.map +1 -0
- package/dist/vendor/spec-core/pattern/charset.d.ts +58 -0
- package/dist/vendor/spec-core/pattern/charset.js +116 -0
- package/dist/vendor/spec-core/pattern/charset.js.map +1 -0
- package/dist/vendor/spec-core/pattern/glob.d.ts +121 -0
- package/dist/vendor/spec-core/pattern/glob.js +481 -0
- package/dist/vendor/spec-core/pattern/glob.js.map +1 -0
- package/dist/vendor/spec-core/pattern/index.d.ts +6 -0
- package/dist/vendor/spec-core/pattern/index.js +4 -0
- package/dist/vendor/spec-core/pattern/index.js.map +1 -0
- package/dist/vendor/spec-core/pattern/regex.d.ts +67 -0
- package/dist/vendor/spec-core/pattern/regex.js +813 -0
- package/dist/vendor/spec-core/pattern/regex.js.map +1 -0
- package/dist/vendor/spec-core/text/index.d.ts +2 -0
- package/dist/vendor/spec-core/text/index.js +2 -0
- package/dist/vendor/spec-core/text/index.js.map +1 -0
- package/dist/vendor/spec-core/text/lines.d.ts +72 -0
- package/dist/vendor/spec-core/text/lines.js +156 -0
- package/dist/vendor/spec-core/text/lines.js.map +1 -0
- package/dist/versions.d.ts +42 -0
- package/dist/versions.js +57 -0
- package/dist/versions.js.map +1 -0
- package/dist/workspace.d.ts +77 -0
- package/dist/workspace.js +138 -0
- package/dist/workspace.js.map +1 -0
- package/hooks/hooks.json +28 -0
- package/package.json +86 -6
- package/skills/close-round/SKILL.md +38 -0
- package/skills/draft-brief/SKILL.md +64 -0
- package/skills/run-round/SKILL.md +46 -0
- package/skills/split-goal/SKILL.md +42 -0
- package/src/vendor/spec-core/LICENSE +21 -0
- package/src/vendor/spec-core/README.md +8 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A reader and editor for the front matter the spec-* tools use: a flat bag
|
|
3
|
+
* of YAML scalars and lists, and optionally one level of nested mapping.
|
|
4
|
+
*
|
|
5
|
+
* Supported: `key: value` lines; plain, single-quoted and double-quoted
|
|
6
|
+
* scalars; inline `[a, b]` sequences; block `- item` sequences; `#` comments.
|
|
7
|
+
* Plain scalars follow the YAML 1.2 core schema, so `yes` is a word and `035`
|
|
8
|
+
* keeps its leading zero for whoever reads it as text. With `nested`, a key
|
|
9
|
+
* whose value is an indented block of keys is read as `parent.child` entries.
|
|
10
|
+
*
|
|
11
|
+
* Anything richer - deeper nesting, block scalars, anchors, tags, a value
|
|
12
|
+
* continued onto the next line - is recognised and reported as unsupported
|
|
13
|
+
* rather than guessed at. A YAML library would parse more, but it would not
|
|
14
|
+
* give back the line and the offset of every value, and a report has to point
|
|
15
|
+
* at the value it is about, and an edit has to leave every other line of the
|
|
16
|
+
* file as it was.
|
|
17
|
+
*/
|
|
18
|
+
import type { FrontMatterKind } from './types.js';
|
|
19
|
+
export interface YamlScalar {
|
|
20
|
+
readonly text: string;
|
|
21
|
+
readonly quoted: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type YamlValue = {
|
|
24
|
+
readonly kind: 'scalar';
|
|
25
|
+
readonly scalar: YamlScalar;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'list';
|
|
28
|
+
readonly items: readonly YamlScalar[];
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'unsupported';
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
};
|
|
33
|
+
export interface FrontMatterEntry {
|
|
34
|
+
/** The key as written; a nested key is its parent's and its own, joined by a dot. */
|
|
35
|
+
readonly key: string;
|
|
36
|
+
/** The key compared: {@link keyName} of `key`, so `depends-on` is `dependsOn`. */
|
|
37
|
+
readonly name: string;
|
|
38
|
+
/** The parent key as written, for a nested key; `null` at the top level. */
|
|
39
|
+
readonly parent: string | null;
|
|
40
|
+
/** 0-based line of the key. */
|
|
41
|
+
readonly line: number;
|
|
42
|
+
/** 0-based line after the entry's last line. */
|
|
43
|
+
readonly end: number;
|
|
44
|
+
/** Offset of the key in the text read. */
|
|
45
|
+
readonly keyStart: number;
|
|
46
|
+
/**
|
|
47
|
+
* Offsets of the value as written: a quoted scalar with its quotes, an
|
|
48
|
+
* inline list with its brackets, a block list from its first item's text to
|
|
49
|
+
* its last item's. An empty value is the empty range just past the colon.
|
|
50
|
+
*/
|
|
51
|
+
readonly valueStart: number;
|
|
52
|
+
readonly valueEnd: number;
|
|
53
|
+
readonly value: YamlValue;
|
|
54
|
+
}
|
|
55
|
+
export interface FrontMatterProblem {
|
|
56
|
+
/** 0-based line. */
|
|
57
|
+
readonly line: number;
|
|
58
|
+
readonly message: string;
|
|
59
|
+
}
|
|
60
|
+
export interface FrontMatter {
|
|
61
|
+
readonly kind: FrontMatterKind;
|
|
62
|
+
/** 0-based line of the closing delimiter, or -1 when the block is never closed. */
|
|
63
|
+
readonly close: number;
|
|
64
|
+
readonly entries: readonly FrontMatterEntry[];
|
|
65
|
+
readonly problems: readonly FrontMatterProblem[];
|
|
66
|
+
}
|
|
67
|
+
export interface ReadOptions {
|
|
68
|
+
/**
|
|
69
|
+
* Read one level of nested mapping as `parent.child` entries, instead of
|
|
70
|
+
* reporting the parent's value as unsupported.
|
|
71
|
+
*/
|
|
72
|
+
readonly nested?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** The kind of front matter a document's first line opens, or `null` when it opens none. */
|
|
75
|
+
export declare function frontMatterKind(firstLine: string): FrontMatterKind | null;
|
|
76
|
+
/** Whether a line closes front matter of a kind: `---` or `...` for YAML, `+++` for TOML. */
|
|
77
|
+
export declare function frontMatterCloses(line: string, kind: FrontMatterKind): boolean;
|
|
78
|
+
export declare function keyName(key: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Reads the front matter at the top of a text, or `null` when there is none.
|
|
81
|
+
*
|
|
82
|
+
* A leading byte-order mark is not part of the text read: offsets count from
|
|
83
|
+
* the character after it, as a scan's do.
|
|
84
|
+
*/
|
|
85
|
+
export declare function readFrontMatter(source: string, options?: ReadOptions): FrontMatter | null;
|
|
86
|
+
/** Parses a value written on the key's own line. `text` is trimmed and non-empty. */
|
|
87
|
+
export declare function parseInline(text: string): YamlValue;
|
|
88
|
+
/** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */
|
|
89
|
+
export declare function isNull(scalar: YamlScalar): boolean;
|
|
90
|
+
/** Renders a string as a scalar that reads back as the same string. */
|
|
91
|
+
export declare function renderScalar(value: string): string;
|
|
92
|
+
export declare function findEntry(frontMatter: FrontMatter | null, key: string): FrontMatterEntry | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Sets one key, leaving every other line as it was.
|
|
95
|
+
*
|
|
96
|
+
* `lines` are the lines of the text the front matter was read from, as
|
|
97
|
+
* `splitLines` gives them. An existing entry keeps the spelling and the
|
|
98
|
+
* indentation of its key; a new one goes last, at the top level. A text with
|
|
99
|
+
* no front matter gains a block.
|
|
100
|
+
*/
|
|
101
|
+
export declare function setEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string, rendered: string): string[];
|
|
102
|
+
/** Removes one key and its value lines; a key that is absent changes nothing. */
|
|
103
|
+
export declare function removeEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string): string[];
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A reader and editor for the front matter the spec-* tools use: a flat bag
|
|
3
|
+
* of YAML scalars and lists, and optionally one level of nested mapping.
|
|
4
|
+
*
|
|
5
|
+
* Supported: `key: value` lines; plain, single-quoted and double-quoted
|
|
6
|
+
* scalars; inline `[a, b]` sequences; block `- item` sequences; `#` comments.
|
|
7
|
+
* Plain scalars follow the YAML 1.2 core schema, so `yes` is a word and `035`
|
|
8
|
+
* keeps its leading zero for whoever reads it as text. With `nested`, a key
|
|
9
|
+
* whose value is an indented block of keys is read as `parent.child` entries.
|
|
10
|
+
*
|
|
11
|
+
* Anything richer - deeper nesting, block scalars, anchors, tags, a value
|
|
12
|
+
* continued onto the next line - is recognised and reported as unsupported
|
|
13
|
+
* rather than guessed at. A YAML library would parse more, but it would not
|
|
14
|
+
* give back the line and the offset of every value, and a report has to point
|
|
15
|
+
* at the value it is about, and an edit has to leave every other line of the
|
|
16
|
+
* file as it was.
|
|
17
|
+
*/
|
|
18
|
+
import { lineStarts, splitLines, stripBom } from '../text/index.js';
|
|
19
|
+
import { leadIndex } from './syntax.js';
|
|
20
|
+
const YAML_OPEN = /^---[ \t]*$/;
|
|
21
|
+
const YAML_CLOSE = /^(?:---|\.\.\.)[ \t]*$/;
|
|
22
|
+
const TOML_FENCE = /^\+\+\+[ \t]*$/;
|
|
23
|
+
/** The kind of front matter a document's first line opens, or `null` when it opens none. */
|
|
24
|
+
export function frontMatterKind(firstLine) {
|
|
25
|
+
if (YAML_OPEN.test(firstLine))
|
|
26
|
+
return 'yaml';
|
|
27
|
+
return TOML_FENCE.test(firstLine) ? 'toml' : null;
|
|
28
|
+
}
|
|
29
|
+
/** Whether a line closes front matter of a kind: `---` or `...` for YAML, `+++` for TOML. */
|
|
30
|
+
export function frontMatterCloses(line, kind) {
|
|
31
|
+
return (kind === 'yaml' ? YAML_CLOSE : TOML_FENCE).test(line);
|
|
32
|
+
}
|
|
33
|
+
const KEY = /^([A-Za-z_][\w.-]*)[ \t]*:(?:[ \t]+(.*))?$/;
|
|
34
|
+
const SEQUENCE_ITEM = /^([ \t]*)-(?:[ \t]+(.*))?$/;
|
|
35
|
+
const BLANK_OR_COMMENT = /^[ \t]*(?:#.*)?$/;
|
|
36
|
+
export function keyName(key) {
|
|
37
|
+
return key.toLowerCase().replace(/[-_]/g, '');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reads the front matter at the top of a text, or `null` when there is none.
|
|
41
|
+
*
|
|
42
|
+
* A leading byte-order mark is not part of the text read: offsets count from
|
|
43
|
+
* the character after it, as a scan's do.
|
|
44
|
+
*/
|
|
45
|
+
export function readFrontMatter(source, options = {}) {
|
|
46
|
+
const text = stripBom(source);
|
|
47
|
+
const lines = splitLines(text);
|
|
48
|
+
const kind = frontMatterKind(lines[0]);
|
|
49
|
+
if (kind === null)
|
|
50
|
+
return null;
|
|
51
|
+
const close = lines.findIndex((line, i) => i > 0 && frontMatterCloses(line, kind));
|
|
52
|
+
if (close === -1) {
|
|
53
|
+
return { kind, close, entries: [], problems: [{ line: 0, message: 'the front matter opened on line 1 is never closed' }] };
|
|
54
|
+
}
|
|
55
|
+
if (kind === 'toml') {
|
|
56
|
+
return { kind, close, entries: [], problems: [{ line: 0, message: 'TOML front matter is not read; write YAML between "---" lines' }] };
|
|
57
|
+
}
|
|
58
|
+
const reader = {
|
|
59
|
+
lines,
|
|
60
|
+
starts: lineStarts(text),
|
|
61
|
+
nested: options.nested === true,
|
|
62
|
+
entries: [],
|
|
63
|
+
problems: [],
|
|
64
|
+
seen: new Map(),
|
|
65
|
+
};
|
|
66
|
+
let i = 1;
|
|
67
|
+
while (i < close) {
|
|
68
|
+
const line = lines[i];
|
|
69
|
+
if (BLANK_OR_COMMENT.test(line)) {
|
|
70
|
+
i += 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const match = KEY.exec(line);
|
|
74
|
+
if (match === null) {
|
|
75
|
+
reader.problems.push({
|
|
76
|
+
line: i,
|
|
77
|
+
message: /^\s/.test(line) ? 'an indented line belongs to no key' : 'not a "key: value" line',
|
|
78
|
+
});
|
|
79
|
+
i += 1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
// The closing delimiter belongs to no value, so the block stops there.
|
|
83
|
+
let end = i + 1;
|
|
84
|
+
while (belongsToBlock(lines[end]))
|
|
85
|
+
end += 1;
|
|
86
|
+
end = trimBlock(lines, end);
|
|
87
|
+
readEntry(reader, { key: match[1], parent: null, line: i, column: 0, inline: match[2] ?? '', end });
|
|
88
|
+
i = end;
|
|
89
|
+
}
|
|
90
|
+
return { kind, close, entries: reader.entries, problems: reader.problems };
|
|
91
|
+
}
|
|
92
|
+
/** A line under a top-level key is part of its value when it is indented or starts a sequence item. */
|
|
93
|
+
function belongsToBlock(line) {
|
|
94
|
+
return /^[ \t]/.test(line) || /^-(?:[ \t]|$)/.test(line) || line.trim() === '';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Takes trailing blank and comment lines off a value's block: they belong to
|
|
98
|
+
* no key. The key's own line is neither, so the walk stops there at the latest.
|
|
99
|
+
*/
|
|
100
|
+
function trimBlock(lines, end) {
|
|
101
|
+
let at = end;
|
|
102
|
+
while (BLANK_OR_COMMENT.test(lines[at - 1]))
|
|
103
|
+
at -= 1;
|
|
104
|
+
return at;
|
|
105
|
+
}
|
|
106
|
+
function note(reader, key, line) {
|
|
107
|
+
const name = keyName(key);
|
|
108
|
+
const previous = reader.seen.get(name);
|
|
109
|
+
if (previous === undefined)
|
|
110
|
+
reader.seen.set(name, line);
|
|
111
|
+
else
|
|
112
|
+
reader.problems.push({ line, message: `"${key}" is declared twice (first on line ${previous + 1})` });
|
|
113
|
+
return name;
|
|
114
|
+
}
|
|
115
|
+
function readEntry(reader, at) {
|
|
116
|
+
const { lines, starts } = reader;
|
|
117
|
+
const text = lines[at.line];
|
|
118
|
+
const lineStart = starts[at.line];
|
|
119
|
+
const key = at.parent === null ? at.key : `${at.parent}.${at.key}`;
|
|
120
|
+
// A key holds no colon and nothing before it does, so the first is its own.
|
|
121
|
+
const colon = lineStart + text.indexOf(':') + 1;
|
|
122
|
+
// What follows the colon starts after its whitespace; what ends it is
|
|
123
|
+
// trimmed by whichever reader takes it.
|
|
124
|
+
const inline = stripLeadingComment(at.inline);
|
|
125
|
+
let read;
|
|
126
|
+
if (inline.length > 0) {
|
|
127
|
+
const valueStart = lineStart + text.length - at.inline.length;
|
|
128
|
+
const continued = contentLines(lines, at.line + 1, at.end).length > 0;
|
|
129
|
+
const parsed = continued
|
|
130
|
+
? rough(unsupported('the value continues on the next line; keep it on one line, or quote it'), inline)
|
|
131
|
+
: readInline(inline);
|
|
132
|
+
read = { value: parsed.value, valueStart, valueEnd: valueStart + parsed.length };
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const content = contentLines(lines, at.line + 1, at.end);
|
|
136
|
+
const first = content[0];
|
|
137
|
+
if (first !== undefined && at.parent === null && reader.nested && KEY.test(lines[first].trim())) {
|
|
138
|
+
note(reader, at.key, at.line);
|
|
139
|
+
readChildren(reader, at.key, at.line + 1, at.end);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
read = readBlock(reader, content, colon, at.parent === null);
|
|
143
|
+
}
|
|
144
|
+
reader.entries.push({
|
|
145
|
+
key,
|
|
146
|
+
name: note(reader, key, at.line),
|
|
147
|
+
parent: at.parent,
|
|
148
|
+
line: at.line,
|
|
149
|
+
end: at.end,
|
|
150
|
+
keyStart: lineStart + at.column,
|
|
151
|
+
...read,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** One level of keys under a parent, all at the indentation of the first. */
|
|
155
|
+
function readChildren(reader, parent, from, end) {
|
|
156
|
+
const { lines } = reader;
|
|
157
|
+
const first = lines[contentLines(lines, from, end)[0]];
|
|
158
|
+
const lead = first.slice(0, leadIndex(first));
|
|
159
|
+
let i = from;
|
|
160
|
+
while (i < end) {
|
|
161
|
+
const line = lines[i];
|
|
162
|
+
if (BLANK_OR_COMMENT.test(line)) {
|
|
163
|
+
i += 1;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
// A line deeper than the keys is always taken by the key above it, so only
|
|
167
|
+
// one at their indentation or shallower reaches here.
|
|
168
|
+
const match = line.startsWith(lead) ? KEY.exec(line.slice(lead.length)) : null;
|
|
169
|
+
if (match === null) {
|
|
170
|
+
reader.problems.push({ line: i, message: 'not a "key: value" line at the indentation of the keys before it' });
|
|
171
|
+
i += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
// Past the parent's value, a line belongs to a child only when it is blank
|
|
175
|
+
// or a comment, and those are trimmed off again.
|
|
176
|
+
let childEnd = i + 1;
|
|
177
|
+
while (belongsToChild(lines[childEnd], lead))
|
|
178
|
+
childEnd += 1;
|
|
179
|
+
childEnd = trimBlock(lines, childEnd);
|
|
180
|
+
readEntry(reader, { key: match[1], parent, line: i, column: lead.length, inline: match[2] ?? '', end: childEnd });
|
|
181
|
+
i = childEnd;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** A line under a nested key is part of its value when it is deeper, or a sequence item at the key's indentation. */
|
|
185
|
+
function belongsToChild(line, lead) {
|
|
186
|
+
if (line.trim() === '')
|
|
187
|
+
return true;
|
|
188
|
+
if (!line.startsWith(lead))
|
|
189
|
+
return false;
|
|
190
|
+
return /^(?:[ \t]|-(?:[ \t]|$))/.test(line.slice(lead.length));
|
|
191
|
+
}
|
|
192
|
+
/** Indices of the lines in a range that are neither blank nor a comment. */
|
|
193
|
+
function contentLines(lines, from, end) {
|
|
194
|
+
const out = [];
|
|
195
|
+
for (let i = from; i < end; i += 1)
|
|
196
|
+
if (!BLANK_OR_COMMENT.test(lines[i]))
|
|
197
|
+
out.push(i);
|
|
198
|
+
return out;
|
|
199
|
+
}
|
|
200
|
+
/** A value written on the lines under its key. */
|
|
201
|
+
function readBlock(reader, content, colon, topLevel) {
|
|
202
|
+
const { lines, starts } = reader;
|
|
203
|
+
const first = content[0];
|
|
204
|
+
if (first === undefined)
|
|
205
|
+
return { value: { kind: 'scalar', scalar: { text: '', quoted: false } }, valueStart: colon, valueEnd: colon };
|
|
206
|
+
// An unsupported block is reported over all of its content lines.
|
|
207
|
+
const firstText = lines[first];
|
|
208
|
+
const last = content[content.length - 1];
|
|
209
|
+
const whole = (value) => ({
|
|
210
|
+
value,
|
|
211
|
+
valueStart: starts[first] + leadIndex(firstText),
|
|
212
|
+
valueEnd: starts[last] + lines[last].trimEnd().length,
|
|
213
|
+
});
|
|
214
|
+
const head = SEQUENCE_ITEM.exec(firstText);
|
|
215
|
+
if (head === null) {
|
|
216
|
+
// Quoting a list would make it a string, so a list gets its own advice.
|
|
217
|
+
if (firstText.trim().startsWith('['))
|
|
218
|
+
return whole(unsupported('an inline list starts on the line after its key; write it after the colon'));
|
|
219
|
+
if (!KEY.test(firstText.trim()))
|
|
220
|
+
return whole(unsupported('the value continues on the next line; keep it on one line, or quote it'));
|
|
221
|
+
return whole(unsupported(topLevel ? 'nested mappings are not supported; flatten the key' : 'only one level of nesting is read; flatten the key'));
|
|
222
|
+
}
|
|
223
|
+
const indent = head[1].length;
|
|
224
|
+
const items = [];
|
|
225
|
+
const spans = [];
|
|
226
|
+
for (const index of content) {
|
|
227
|
+
const line = lines[index];
|
|
228
|
+
const item = SEQUENCE_ITEM.exec(line);
|
|
229
|
+
if (item === null || item[1].length !== indent) {
|
|
230
|
+
return whole(unsupported('a list item is continued or nested; keep each item on one line'));
|
|
231
|
+
}
|
|
232
|
+
// The item's text starts after its whitespace, as a key's value does.
|
|
233
|
+
const written = item[2] ?? '';
|
|
234
|
+
const text = stripLeadingComment(written);
|
|
235
|
+
if (text.length === 0)
|
|
236
|
+
return whole(unsupported('a list item is empty'));
|
|
237
|
+
const parsed = readInline(text);
|
|
238
|
+
if (parsed.value.kind !== 'scalar') {
|
|
239
|
+
return whole(parsed.value.kind === 'list' ? unsupported('nested lists are not supported') : parsed.value);
|
|
240
|
+
}
|
|
241
|
+
const start = starts[index] + line.length - written.length;
|
|
242
|
+
spans.push([start, start + parsed.length]);
|
|
243
|
+
items.push(parsed.value.scalar);
|
|
244
|
+
}
|
|
245
|
+
return { value: { kind: 'list', items }, valueStart: spans[0][0], valueEnd: spans[spans.length - 1][1] };
|
|
246
|
+
}
|
|
247
|
+
function stripLeadingComment(text) {
|
|
248
|
+
return text.startsWith('#') ? '' : text;
|
|
249
|
+
}
|
|
250
|
+
function unsupported(reason) {
|
|
251
|
+
return { kind: 'unsupported', reason };
|
|
252
|
+
}
|
|
253
|
+
/** An unsupported value spans its text up to any comment. */
|
|
254
|
+
function rough(value, text) {
|
|
255
|
+
return { value, length: stripTrailingComment(text).length };
|
|
256
|
+
}
|
|
257
|
+
/** Parses a value written on the key's own line. `text` is trimmed and non-empty. */
|
|
258
|
+
export function parseInline(text) {
|
|
259
|
+
return readInline(text).value;
|
|
260
|
+
}
|
|
261
|
+
/** `text` starts with the value; whitespace after it is allowed. */
|
|
262
|
+
function readInline(text) {
|
|
263
|
+
const head = text.charAt(0);
|
|
264
|
+
if (head === '"' || head === "'") {
|
|
265
|
+
const quoted = head === '"' ? readDoubleQuoted(text) : readSingleQuoted(text);
|
|
266
|
+
if (typeof quoted === 'string')
|
|
267
|
+
return rough(unsupported(quoted), text);
|
|
268
|
+
return trailingIsComment(text.slice(quoted.next))
|
|
269
|
+
? { value: { kind: 'scalar', scalar: { text: quoted.text, quoted: true } }, length: quoted.next }
|
|
270
|
+
: rough(unsupported('text follows a closing quote'), text);
|
|
271
|
+
}
|
|
272
|
+
if (head === '[')
|
|
273
|
+
return parseFlowSequence(text);
|
|
274
|
+
if (head === '{')
|
|
275
|
+
return rough(unsupported('inline mappings are not supported'), text);
|
|
276
|
+
if (head === '|' || head === '>')
|
|
277
|
+
return rough(unsupported('block scalars are not supported; keep the value on one line'), text);
|
|
278
|
+
if (head === '&' || head === '*' || head === '!')
|
|
279
|
+
return rough(unsupported('anchors, aliases and tags are not supported'), text);
|
|
280
|
+
if (head === '@' || head === '`')
|
|
281
|
+
return rough(unsupported(`a plain value cannot start with "${head}"; quote it`), text);
|
|
282
|
+
const plain = stripTrailingComment(text);
|
|
283
|
+
if (/:(?:\s|$)/.test(plain))
|
|
284
|
+
return rough(unsupported('a plain value cannot contain ": "; quote it'), text);
|
|
285
|
+
if (/^-(?:\s|$)/.test(plain))
|
|
286
|
+
return rough(unsupported('a list must start on the line after its key'), text);
|
|
287
|
+
return { value: { kind: 'scalar', scalar: { text: plain, quoted: false } }, length: plain.length };
|
|
288
|
+
}
|
|
289
|
+
/** A comment starts at a `#` after whitespace; a `#` inside a word is text. */
|
|
290
|
+
function stripTrailingComment(text) {
|
|
291
|
+
return text.split(/\s#/, 1)[0].trim();
|
|
292
|
+
}
|
|
293
|
+
/** Nothing after a closing quote or bracket, or whitespace and then a comment. */
|
|
294
|
+
function trailingIsComment(rest) {
|
|
295
|
+
return /^(?:\s+(?:#.*)?)?$/.test(rest);
|
|
296
|
+
}
|
|
297
|
+
const ESCAPES = {
|
|
298
|
+
'"': '"',
|
|
299
|
+
'\\': '\\',
|
|
300
|
+
'/': '/',
|
|
301
|
+
'0': '\u0000',
|
|
302
|
+
b: '\b',
|
|
303
|
+
f: '\f',
|
|
304
|
+
n: '\n',
|
|
305
|
+
r: '\r',
|
|
306
|
+
t: '\t',
|
|
307
|
+
};
|
|
308
|
+
const HEX_ESCAPE_LENGTH = { x: 2, u: 4, U: 8 };
|
|
309
|
+
/** Reads a double-quoted scalar starting at index 0, or returns why it cannot. */
|
|
310
|
+
function readDoubleQuoted(text) {
|
|
311
|
+
let out = '';
|
|
312
|
+
for (let i = 1;; i += 1) {
|
|
313
|
+
const ch = text.charAt(i);
|
|
314
|
+
if (ch === '')
|
|
315
|
+
return 'a double-quoted value is never closed';
|
|
316
|
+
if (ch === '"')
|
|
317
|
+
return { text: out, next: i + 1 };
|
|
318
|
+
if (ch !== '\\') {
|
|
319
|
+
out += ch;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const code = text.charAt(i + 1);
|
|
323
|
+
const simple = ESCAPES[code];
|
|
324
|
+
if (simple !== undefined) {
|
|
325
|
+
out += simple;
|
|
326
|
+
i += 1;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
// An escape this reader does not know has no digits to read, and no
|
|
330
|
+
// digits are not a number.
|
|
331
|
+
const width = HEX_ESCAPE_LENGTH[code] ?? 0;
|
|
332
|
+
const hex = text.slice(i + 2, i + 2 + width);
|
|
333
|
+
if (hex.length !== width || !/^[0-9A-Fa-f]+$/.test(hex))
|
|
334
|
+
return `"\\${code}" is not an escape this reader knows`;
|
|
335
|
+
const point = Number.parseInt(hex, 16);
|
|
336
|
+
if (point > 0x10ffff)
|
|
337
|
+
return `"\\${code}${hex}" is not a character`;
|
|
338
|
+
out += String.fromCodePoint(point);
|
|
339
|
+
i += 1 + width;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function readSingleQuoted(text) {
|
|
343
|
+
let out = '';
|
|
344
|
+
for (let i = 1;; i += 1) {
|
|
345
|
+
const ch = text.charAt(i);
|
|
346
|
+
if (ch === '')
|
|
347
|
+
return 'a single-quoted value is never closed';
|
|
348
|
+
if (ch !== "'") {
|
|
349
|
+
out += ch;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (text.charAt(i + 1) !== "'")
|
|
353
|
+
return { text: out, next: i + 1 };
|
|
354
|
+
out += "'";
|
|
355
|
+
i += 1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/** The first index at or after `from` that is not whitespace. */
|
|
359
|
+
function skipSpace(text, from) {
|
|
360
|
+
let i = from;
|
|
361
|
+
while (/\s/.test(text.charAt(i)))
|
|
362
|
+
i += 1;
|
|
363
|
+
return i;
|
|
364
|
+
}
|
|
365
|
+
function parseFlowSequence(text) {
|
|
366
|
+
const items = [];
|
|
367
|
+
const fail = (reason) => rough(unsupported(reason), text);
|
|
368
|
+
let i = 1;
|
|
369
|
+
for (;;) {
|
|
370
|
+
i = skipSpace(text, i);
|
|
371
|
+
const ch = text.charAt(i);
|
|
372
|
+
if (ch === '')
|
|
373
|
+
return fail('an inline list is never closed; keep it on one line');
|
|
374
|
+
if (ch === ']') {
|
|
375
|
+
return trailingIsComment(text.slice(i + 1))
|
|
376
|
+
? { value: { kind: 'list', items }, length: i + 1 }
|
|
377
|
+
: fail('text follows the end of an inline list');
|
|
378
|
+
}
|
|
379
|
+
if (ch === '[' || ch === '{')
|
|
380
|
+
return fail('nested lists and mappings are not supported');
|
|
381
|
+
if (ch === ',')
|
|
382
|
+
return fail('an inline list has an empty item');
|
|
383
|
+
if (ch === '"' || ch === "'") {
|
|
384
|
+
const rest = text.slice(i);
|
|
385
|
+
const quoted = ch === '"' ? readDoubleQuoted(rest) : readSingleQuoted(rest);
|
|
386
|
+
if (typeof quoted === 'string')
|
|
387
|
+
return fail(quoted);
|
|
388
|
+
items.push({ text: quoted.text, quoted: true });
|
|
389
|
+
i += quoted.next;
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
let j = i;
|
|
393
|
+
// One step past the end reads nothing and slices nothing more, so the
|
|
394
|
+
// bound could be one further and still stop the walk.
|
|
395
|
+
while (j < text.length && text.charAt(j) !== ',' && text.charAt(j) !== ']')
|
|
396
|
+
j += 1;
|
|
397
|
+
const plain = text.slice(i, j).trim();
|
|
398
|
+
if (/[[{]/.test(plain) || /:(?:\s|$)/.test(plain) || plain.includes(' #')) {
|
|
399
|
+
return fail(`"${plain}" needs quoting inside an inline list`);
|
|
400
|
+
}
|
|
401
|
+
items.push({ text: plain, quoted: false });
|
|
402
|
+
i = j;
|
|
403
|
+
}
|
|
404
|
+
i = skipSpace(text, i);
|
|
405
|
+
// After a comma the next pass reads an item or, legally in YAML, the
|
|
406
|
+
// bracket; at the end of the text it says the list is never closed.
|
|
407
|
+
const next = text.charAt(i);
|
|
408
|
+
if (next === ',')
|
|
409
|
+
i += 1;
|
|
410
|
+
else if (next !== ']' && next !== '')
|
|
411
|
+
return fail('inline list items must be separated by commas');
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */
|
|
415
|
+
export function isNull(scalar) {
|
|
416
|
+
return !scalar.quoted && ['', '~', 'null', 'Null', 'NULL'].includes(scalar.text);
|
|
417
|
+
}
|
|
418
|
+
/** Renders a string as a scalar that reads back as the same string. */
|
|
419
|
+
export function renderScalar(value) {
|
|
420
|
+
const reserved = /^(?:true|false|null|yes|no|on|off|~)$/i.test(value);
|
|
421
|
+
const plain = /^[A-Za-z][A-Za-z0-9 ._/+-]*$/.test(value) && !value.endsWith(' ');
|
|
422
|
+
return plain && !reserved ? value : JSON.stringify(value);
|
|
423
|
+
}
|
|
424
|
+
export function findEntry(frontMatter, key) {
|
|
425
|
+
const name = keyName(key);
|
|
426
|
+
return frontMatter?.entries.find((entry) => entry.name === name);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Sets one key, leaving every other line as it was.
|
|
430
|
+
*
|
|
431
|
+
* `lines` are the lines of the text the front matter was read from, as
|
|
432
|
+
* `splitLines` gives them. An existing entry keeps the spelling and the
|
|
433
|
+
* indentation of its key; a new one goes last, at the top level. A text with
|
|
434
|
+
* no front matter gains a block.
|
|
435
|
+
*/
|
|
436
|
+
export function setEntry(lines, frontMatter, key, rendered) {
|
|
437
|
+
if (frontMatter === null)
|
|
438
|
+
return ['---', `${key}: ${rendered}`, '---', ...lines];
|
|
439
|
+
if (frontMatter.close === -1)
|
|
440
|
+
throw new Error('cannot edit front matter that is never closed');
|
|
441
|
+
if (frontMatter.kind === 'toml')
|
|
442
|
+
throw new Error('cannot edit TOML front matter');
|
|
443
|
+
const entry = findEntry(frontMatter, key);
|
|
444
|
+
if (entry === undefined) {
|
|
445
|
+
return [...lines.slice(0, frontMatter.close), `${key}: ${rendered}`, ...lines.slice(frontMatter.close)];
|
|
446
|
+
}
|
|
447
|
+
const written = entry.parent === null
|
|
448
|
+
? `${entry.key}: ${rendered}`
|
|
449
|
+
: `${lines[entry.line].slice(0, leadIndex(lines[entry.line]))}${entry.key.slice(entry.parent.length + 1)}: ${rendered}`;
|
|
450
|
+
return [...lines.slice(0, entry.line), written, ...lines.slice(entry.end)];
|
|
451
|
+
}
|
|
452
|
+
/** Removes one key and its value lines; a key that is absent changes nothing. */
|
|
453
|
+
export function removeEntry(lines, frontMatter, key) {
|
|
454
|
+
const entry = findEntry(frontMatter, key);
|
|
455
|
+
if (entry === undefined)
|
|
456
|
+
return [...lines];
|
|
457
|
+
return [...lines.slice(0, entry.line), ...lines.slice(entry.end)];
|
|
458
|
+
}
|
|
459
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA0DxC,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K,CAAC,KAAK,CAAC,IAAI,CAAW,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;IAClJ,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,WAAW,CAAC,KAAwB,EAAE,WAA+B,EAAE,GAAW;IAChG,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["/**\n * A reader and editor for the front matter the spec-* tools use: a flat bag\n * of YAML scalars and lists, and optionally one level of nested mapping.\n *\n * Supported: `key: value` lines; plain, single-quoted and double-quoted\n * scalars; inline `[a, b]` sequences; block `- item` sequences; `#` comments.\n * Plain scalars follow the YAML 1.2 core schema, so `yes` is a word and `035`\n * keeps its leading zero for whoever reads it as text. With `nested`, a key\n * whose value is an indented block of keys is read as `parent.child` entries.\n *\n * Anything richer - deeper nesting, block scalars, anchors, tags, a value\n * continued onto the next line - is recognised and reported as unsupported\n * rather than guessed at. A YAML library would parse more, but it would not\n * give back the line and the offset of every value, and a report has to point\n * at the value it is about, and an edit has to leave every other line of the\n * file as it was.\n */\n\nimport { lineStarts, splitLines, stripBom } from '../text/index.js';\nimport { leadIndex } from './syntax.js';\nimport type { FrontMatterKind } from './types.js';\n\nexport interface YamlScalar {\n readonly text: string;\n readonly quoted: boolean;\n}\n\nexport type YamlValue =\n | { readonly kind: 'scalar'; readonly scalar: YamlScalar }\n | { readonly kind: 'list'; readonly items: readonly YamlScalar[] }\n | { readonly kind: 'unsupported'; readonly reason: string };\n\nexport interface FrontMatterEntry {\n /** The key as written; a nested key is its parent's and its own, joined by a dot. */\n readonly key: string;\n /** The key compared: {@link keyName} of `key`, so `depends-on` is `dependsOn`. */\n readonly name: string;\n /** The parent key as written, for a nested key; `null` at the top level. */\n readonly parent: string | null;\n /** 0-based line of the key. */\n readonly line: number;\n /** 0-based line after the entry's last line. */\n readonly end: number;\n /** Offset of the key in the text read. */\n readonly keyStart: number;\n /**\n * Offsets of the value as written: a quoted scalar with its quotes, an\n * inline list with its brackets, a block list from its first item's text to\n * its last item's. An empty value is the empty range just past the colon.\n */\n readonly valueStart: number;\n readonly valueEnd: number;\n readonly value: YamlValue;\n}\n\nexport interface FrontMatterProblem {\n /** 0-based line. */\n readonly line: number;\n readonly message: string;\n}\n\nexport interface FrontMatter {\n readonly kind: FrontMatterKind;\n /** 0-based line of the closing delimiter, or -1 when the block is never closed. */\n readonly close: number;\n readonly entries: readonly FrontMatterEntry[];\n readonly problems: readonly FrontMatterProblem[];\n}\n\nexport interface ReadOptions {\n /**\n * Read one level of nested mapping as `parent.child` entries, instead of\n * reporting the parent's value as unsupported.\n */\n readonly nested?: boolean;\n}\n\nconst YAML_OPEN = /^---[ \\t]*$/;\nconst YAML_CLOSE = /^(?:---|\\.\\.\\.)[ \\t]*$/;\nconst TOML_FENCE = /^\\+\\+\\+[ \\t]*$/;\n\n/** The kind of front matter a document's first line opens, or `null` when it opens none. */\nexport function frontMatterKind(firstLine: string): FrontMatterKind | null {\n if (YAML_OPEN.test(firstLine)) return 'yaml';\n return TOML_FENCE.test(firstLine) ? 'toml' : null;\n}\n\n/** Whether a line closes front matter of a kind: `---` or `...` for YAML, `+++` for TOML. */\nexport function frontMatterCloses(line: string, kind: FrontMatterKind): boolean {\n return (kind === 'yaml' ? YAML_CLOSE : TOML_FENCE).test(line);\n}\n\nconst KEY = /^([A-Za-z_][\\w.-]*)[ \\t]*:(?:[ \\t]+(.*))?$/;\nconst SEQUENCE_ITEM = /^([ \\t]*)-(?:[ \\t]+(.*))?$/;\nconst BLANK_OR_COMMENT = /^[ \\t]*(?:#.*)?$/;\n\nexport function keyName(key: string): string {\n return key.toLowerCase().replace(/[-_]/g, '');\n}\n\n/**\n * Reads the front matter at the top of a text, or `null` when there is none.\n *\n * A leading byte-order mark is not part of the text read: offsets count from\n * the character after it, as a scan's do.\n */\nexport function readFrontMatter(source: string, options: ReadOptions = {}): FrontMatter | null {\n const text = stripBom(source);\n const lines = splitLines(text);\n const kind = frontMatterKind(lines[0] as string);\n if (kind === null) return null;\n const close = lines.findIndex((line, i) => i > 0 && frontMatterCloses(line, kind));\n if (close === -1) {\n return { kind, close, entries: [], problems: [{ line: 0, message: 'the front matter opened on line 1 is never closed' }] };\n }\n if (kind === 'toml') {\n return { kind, close, entries: [], problems: [{ line: 0, message: 'TOML front matter is not read; write YAML between \"---\" lines' }] };\n }\n\n const reader: Reader = {\n lines,\n starts: lineStarts(text),\n nested: options.nested === true,\n entries: [],\n problems: [],\n seen: new Map(),\n };\n let i = 1;\n while (i < close) {\n const line = lines[i] as string;\n if (BLANK_OR_COMMENT.test(line)) {\n i += 1;\n continue;\n }\n const match = KEY.exec(line);\n if (match === null) {\n reader.problems.push({\n line: i,\n message: /^\\s/.test(line) ? 'an indented line belongs to no key' : 'not a \"key: value\" line',\n });\n i += 1;\n continue;\n }\n // The closing delimiter belongs to no value, so the block stops there.\n let end = i + 1;\n while (belongsToBlock(lines[end] as string)) end += 1;\n end = trimBlock(lines, end);\n readEntry(reader, { key: match[1] as string, parent: null, line: i, column: 0, inline: match[2] ?? '', end });\n i = end;\n }\n return { kind, close, entries: reader.entries, problems: reader.problems };\n}\n\ninterface Reader {\n readonly lines: readonly string[];\n readonly starts: readonly number[];\n readonly nested: boolean;\n readonly entries: FrontMatterEntry[];\n readonly problems: FrontMatterProblem[];\n readonly seen: Map<string, number>;\n}\n\ninterface KeyLine {\n /** The key as written on its line, without a parent. */\n readonly key: string;\n readonly parent: string | null;\n readonly line: number;\n /** Column of the key. */\n readonly column: number;\n /** What follows the colon and its whitespace, as written. */\n readonly inline: string;\n /** 0-based line after the key's value. */\n readonly end: number;\n}\n\n/** A line under a top-level key is part of its value when it is indented or starts a sequence item. */\nfunction belongsToBlock(line: string): boolean {\n return /^[ \\t]/.test(line) || /^-(?:[ \\t]|$)/.test(line) || line.trim() === '';\n}\n\n/**\n * Takes trailing blank and comment lines off a value's block: they belong to\n * no key. The key's own line is neither, so the walk stops there at the latest.\n */\nfunction trimBlock(lines: readonly string[], end: number): number {\n let at = end;\n while (BLANK_OR_COMMENT.test(lines[at - 1] as string)) at -= 1;\n return at;\n}\n\nfunction note(reader: Reader, key: string, line: number): string {\n const name = keyName(key);\n const previous = reader.seen.get(name);\n if (previous === undefined) reader.seen.set(name, line);\n else reader.problems.push({ line, message: `\"${key}\" is declared twice (first on line ${previous + 1})` });\n return name;\n}\n\nfunction readEntry(reader: Reader, at: KeyLine): void {\n const { lines, starts } = reader;\n const text = lines[at.line] as string;\n const lineStart = starts[at.line] as number;\n const key = at.parent === null ? at.key : `${at.parent}.${at.key}`;\n // A key holds no colon and nothing before it does, so the first is its own.\n const colon = lineStart + text.indexOf(':') + 1;\n // What follows the colon starts after its whitespace; what ends it is\n // trimmed by whichever reader takes it.\n const inline = stripLeadingComment(at.inline);\n\n let read: Read;\n if (inline.length > 0) {\n const valueStart = lineStart + text.length - at.inline.length;\n const continued = contentLines(lines, at.line + 1, at.end).length > 0;\n const parsed = continued\n ? rough(unsupported('the value continues on the next line; keep it on one line, or quote it'), inline)\n : readInline(inline);\n read = { value: parsed.value, valueStart, valueEnd: valueStart + parsed.length };\n } else {\n const content = contentLines(lines, at.line + 1, at.end);\n const first = content[0];\n if (first !== undefined && at.parent === null && reader.nested && KEY.test((lines[first] as string).trim())) {\n note(reader, at.key, at.line);\n readChildren(reader, at.key, at.line + 1, at.end);\n return;\n }\n read = readBlock(reader, content, colon, at.parent === null);\n }\n\n reader.entries.push({\n key,\n name: note(reader, key, at.line),\n parent: at.parent,\n line: at.line,\n end: at.end,\n keyStart: lineStart + at.column,\n ...read,\n });\n}\n\n/** One level of keys under a parent, all at the indentation of the first. */\nfunction readChildren(reader: Reader, parent: string, from: number, end: number): void {\n const { lines } = reader;\n const first = lines[contentLines(lines, from, end)[0] as number] as string;\n const lead = first.slice(0, leadIndex(first));\n let i = from;\n while (i < end) {\n const line = lines[i] as string;\n if (BLANK_OR_COMMENT.test(line)) {\n i += 1;\n continue;\n }\n // A line deeper than the keys is always taken by the key above it, so only\n // one at their indentation or shallower reaches here.\n const match = line.startsWith(lead) ? KEY.exec(line.slice(lead.length)) : null;\n if (match === null) {\n reader.problems.push({ line: i, message: 'not a \"key: value\" line at the indentation of the keys before it' });\n i += 1;\n continue;\n }\n // Past the parent's value, a line belongs to a child only when it is blank\n // or a comment, and those are trimmed off again.\n let childEnd = i + 1;\n while (belongsToChild(lines[childEnd] as string, lead)) childEnd += 1;\n childEnd = trimBlock(lines, childEnd);\n readEntry(reader, { key: match[1] as string, parent, line: i, column: lead.length, inline: match[2] ?? '', end: childEnd });\n i = childEnd;\n }\n}\n\n/** A line under a nested key is part of its value when it is deeper, or a sequence item at the key's indentation. */\nfunction belongsToChild(line: string, lead: string): boolean {\n if (line.trim() === '') return true;\n if (!line.startsWith(lead)) return false;\n return /^(?:[ \\t]|-(?:[ \\t]|$))/.test(line.slice(lead.length));\n}\n\ninterface Read {\n readonly value: YamlValue;\n readonly valueStart: number;\n readonly valueEnd: number;\n}\n\n/** Indices of the lines in a range that are neither blank nor a comment. */\nfunction contentLines(lines: readonly string[], from: number, end: number): number[] {\n const out: number[] = [];\n for (let i = from; i < end; i += 1) if (!BLANK_OR_COMMENT.test(lines[i] as string)) out.push(i);\n return out;\n}\n\n/** A value written on the lines under its key. */\nfunction readBlock(reader: Reader, content: readonly number[], colon: number, topLevel: boolean): Read {\n const { lines, starts } = reader;\n const first = content[0];\n if (first === undefined) return { value: { kind: 'scalar', scalar: { text: '', quoted: false } }, valueStart: colon, valueEnd: colon };\n\n // An unsupported block is reported over all of its content lines.\n const firstText = lines[first] as string;\n const last = content[content.length - 1] as number;\n const whole = (value: YamlValue): Read => ({\n value,\n valueStart: (starts[first] as number) + leadIndex(firstText),\n valueEnd: (starts[last] as number) + (lines[last] as string).trimEnd().length,\n });\n\n const head = SEQUENCE_ITEM.exec(firstText);\n if (head === null) {\n // Quoting a list would make it a string, so a list gets its own advice.\n if (firstText.trim().startsWith('[')) return whole(unsupported('an inline list starts on the line after its key; write it after the colon'));\n if (!KEY.test(firstText.trim())) return whole(unsupported('the value continues on the next line; keep it on one line, or quote it'));\n return whole(\n unsupported(topLevel ? 'nested mappings are not supported; flatten the key' : 'only one level of nesting is read; flatten the key'),\n );\n }\n const indent = (head[1] as string).length;\n const items: YamlScalar[] = [];\n const spans: [number, number][] = [];\n for (const index of content) {\n const line = lines[index] as string;\n const item = SEQUENCE_ITEM.exec(line);\n if (item === null || (item[1] as string).length !== indent) {\n return whole(unsupported('a list item is continued or nested; keep each item on one line'));\n }\n // The item's text starts after its whitespace, as a key's value does.\n const written = item[2] ?? '';\n const text = stripLeadingComment(written);\n if (text.length === 0) return whole(unsupported('a list item is empty'));\n const parsed = readInline(text);\n if (parsed.value.kind !== 'scalar') {\n return whole(parsed.value.kind === 'list' ? unsupported('nested lists are not supported') : parsed.value);\n }\n const start = (starts[index] as number) + line.length - written.length;\n spans.push([start, start + parsed.length]);\n items.push(parsed.value.scalar);\n }\n return { value: { kind: 'list', items }, valueStart: (spans[0] as [number, number])[0], valueEnd: (spans[spans.length - 1] as [number, number])[1] };\n}\n\nfunction stripLeadingComment(text: string): string {\n return text.startsWith('#') ? '' : text;\n}\n\nfunction unsupported(reason: string): YamlValue {\n return { kind: 'unsupported', reason };\n}\n\ninterface Parsed {\n readonly value: YamlValue;\n /** Characters of the text the value spans. */\n readonly length: number;\n}\n\n/** An unsupported value spans its text up to any comment. */\nfunction rough(value: YamlValue, text: string): Parsed {\n return { value, length: stripTrailingComment(text).length };\n}\n\n/** Parses a value written on the key's own line. `text` is trimmed and non-empty. */\nexport function parseInline(text: string): YamlValue {\n return readInline(text).value;\n}\n\n/** `text` starts with the value; whitespace after it is allowed. */\nfunction readInline(text: string): Parsed {\n const head = text.charAt(0);\n if (head === '\"' || head === \"'\") {\n const quoted = head === '\"' ? readDoubleQuoted(text) : readSingleQuoted(text);\n if (typeof quoted === 'string') return rough(unsupported(quoted), text);\n return trailingIsComment(text.slice(quoted.next))\n ? { value: { kind: 'scalar', scalar: { text: quoted.text, quoted: true } }, length: quoted.next }\n : rough(unsupported('text follows a closing quote'), text);\n }\n if (head === '[') return parseFlowSequence(text);\n if (head === '{') return rough(unsupported('inline mappings are not supported'), text);\n if (head === '|' || head === '>') return rough(unsupported('block scalars are not supported; keep the value on one line'), text);\n if (head === '&' || head === '*' || head === '!') return rough(unsupported('anchors, aliases and tags are not supported'), text);\n if (head === '@' || head === '`') return rough(unsupported(`a plain value cannot start with \"${head}\"; quote it`), text);\n const plain = stripTrailingComment(text);\n if (/:(?:\\s|$)/.test(plain)) return rough(unsupported('a plain value cannot contain \": \"; quote it'), text);\n if (/^-(?:\\s|$)/.test(plain)) return rough(unsupported('a list must start on the line after its key'), text);\n return { value: { kind: 'scalar', scalar: { text: plain, quoted: false } }, length: plain.length };\n}\n\n/** A comment starts at a `#` after whitespace; a `#` inside a word is text. */\nfunction stripTrailingComment(text: string): string {\n return (text.split(/\\s#/, 1)[0] as string).trim();\n}\n\n/** Nothing after a closing quote or bracket, or whitespace and then a comment. */\nfunction trailingIsComment(rest: string): boolean {\n return /^(?:\\s+(?:#.*)?)?$/.test(rest);\n}\n\ninterface Quoted {\n readonly text: string;\n /** Index just past the closing quote. */\n readonly next: number;\n}\n\nconst ESCAPES: Readonly<Record<string, string>> = {\n '\"': '\"',\n '\\\\': '\\\\',\n '/': '/',\n '0': '\\u0000',\n b: '\\b',\n f: '\\f',\n n: '\\n',\n r: '\\r',\n t: '\\t',\n};\n\nconst HEX_ESCAPE_LENGTH: Readonly<Record<string, number>> = { x: 2, u: 4, U: 8 };\n\n/** Reads a double-quoted scalar starting at index 0, or returns why it cannot. */\nfunction readDoubleQuoted(text: string): Quoted | string {\n let out = '';\n for (let i = 1; ; i += 1) {\n const ch = text.charAt(i);\n if (ch === '') return 'a double-quoted value is never closed';\n if (ch === '\"') return { text: out, next: i + 1 };\n if (ch !== '\\\\') {\n out += ch;\n continue;\n }\n const code = text.charAt(i + 1);\n const simple = ESCAPES[code];\n if (simple !== undefined) {\n out += simple;\n i += 1;\n continue;\n }\n // An escape this reader does not know has no digits to read, and no\n // digits are not a number.\n const width = HEX_ESCAPE_LENGTH[code] ?? 0;\n const hex = text.slice(i + 2, i + 2 + width);\n if (hex.length !== width || !/^[0-9A-Fa-f]+$/.test(hex)) return `\"\\\\${code}\" is not an escape this reader knows`;\n const point = Number.parseInt(hex, 16);\n if (point > 0x10ffff) return `\"\\\\${code}${hex}\" is not a character`;\n out += String.fromCodePoint(point);\n i += 1 + width;\n }\n}\n\nfunction readSingleQuoted(text: string): Quoted | string {\n let out = '';\n for (let i = 1; ; i += 1) {\n const ch = text.charAt(i);\n if (ch === '') return 'a single-quoted value is never closed';\n if (ch !== \"'\") {\n out += ch;\n continue;\n }\n if (text.charAt(i + 1) !== \"'\") return { text: out, next: i + 1 };\n out += \"'\";\n i += 1;\n }\n}\n\n/** The first index at or after `from` that is not whitespace. */\nfunction skipSpace(text: string, from: number): number {\n let i = from;\n while (/\\s/.test(text.charAt(i))) i += 1;\n return i;\n}\n\nfunction parseFlowSequence(text: string): Parsed {\n const items: YamlScalar[] = [];\n const fail = (reason: string): Parsed => rough(unsupported(reason), text);\n let i = 1;\n for (;;) {\n i = skipSpace(text, i);\n const ch = text.charAt(i);\n if (ch === '') return fail('an inline list is never closed; keep it on one line');\n if (ch === ']') {\n return trailingIsComment(text.slice(i + 1))\n ? { value: { kind: 'list', items }, length: i + 1 }\n : fail('text follows the end of an inline list');\n }\n if (ch === '[' || ch === '{') return fail('nested lists and mappings are not supported');\n if (ch === ',') return fail('an inline list has an empty item');\n if (ch === '\"' || ch === \"'\") {\n const rest = text.slice(i);\n const quoted = ch === '\"' ? readDoubleQuoted(rest) : readSingleQuoted(rest);\n if (typeof quoted === 'string') return fail(quoted);\n items.push({ text: quoted.text, quoted: true });\n i += quoted.next;\n } else {\n let j = i;\n // One step past the end reads nothing and slices nothing more, so the\n // bound could be one further and still stop the walk.\n while (j < text.length && text.charAt(j) !== ',' && text.charAt(j) !== ']') j += 1;\n const plain = text.slice(i, j).trim();\n if (/[[{]/.test(plain) || /:(?:\\s|$)/.test(plain) || plain.includes(' #')) {\n return fail(`\"${plain}\" needs quoting inside an inline list`);\n }\n items.push({ text: plain, quoted: false });\n i = j;\n }\n i = skipSpace(text, i);\n // After a comma the next pass reads an item or, legally in YAML, the\n // bracket; at the end of the text it says the list is never closed.\n const next = text.charAt(i);\n if (next === ',') i += 1;\n else if (next !== ']' && next !== '') return fail('inline list items must be separated by commas');\n }\n}\n\n/** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */\nexport function isNull(scalar: YamlScalar): boolean {\n return !scalar.quoted && ['', '~', 'null', 'Null', 'NULL'].includes(scalar.text);\n}\n\n/** Renders a string as a scalar that reads back as the same string. */\nexport function renderScalar(value: string): string {\n const reserved = /^(?:true|false|null|yes|no|on|off|~)$/i.test(value);\n const plain = /^[A-Za-z][A-Za-z0-9 ._/+-]*$/.test(value) && !value.endsWith(' ');\n return plain && !reserved ? value : JSON.stringify(value);\n}\n\nexport function findEntry(frontMatter: FrontMatter | null, key: string): FrontMatterEntry | undefined {\n const name = keyName(key);\n return frontMatter?.entries.find((entry) => entry.name === name);\n}\n\n/**\n * Sets one key, leaving every other line as it was.\n *\n * `lines` are the lines of the text the front matter was read from, as\n * `splitLines` gives them. An existing entry keeps the spelling and the\n * indentation of its key; a new one goes last, at the top level. A text with\n * no front matter gains a block.\n */\nexport function setEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string, rendered: string): string[] {\n if (frontMatter === null) return ['---', `${key}: ${rendered}`, '---', ...lines];\n if (frontMatter.close === -1) throw new Error('cannot edit front matter that is never closed');\n if (frontMatter.kind === 'toml') throw new Error('cannot edit TOML front matter');\n const entry = findEntry(frontMatter, key);\n if (entry === undefined) {\n return [...lines.slice(0, frontMatter.close), `${key}: ${rendered}`, ...lines.slice(frontMatter.close)];\n }\n const written =\n entry.parent === null\n ? `${entry.key}: ${rendered}`\n : `${(lines[entry.line] as string).slice(0, leadIndex(lines[entry.line] as string))}${entry.key.slice(entry.parent.length + 1)}: ${rendered}`;\n return [...lines.slice(0, entry.line), written, ...lines.slice(entry.end)];\n}\n\n/** Removes one key and its value lines; a key that is absent changes nothing. */\nexport function removeEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string): string[] {\n const entry = findEntry(frontMatter, key);\n if (entry === undefined) return [...lines];\n return [...lines.slice(0, entry.line), ...lines.slice(entry.end)];\n}\n"]}
|