@aftertext/compiler 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +68 -2
- package/dist/ast/expression.d.ts +55 -0
- package/dist/ast/expression.d.ts.map +1 -0
- package/dist/ast/expression.js +2 -0
- package/dist/ast/expression.js.map +1 -0
- package/dist/ast/index.d.ts +6 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +2 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/ast/inline.d.ts +39 -0
- package/dist/ast/inline.d.ts.map +1 -0
- package/dist/ast/inline.js +2 -0
- package/dist/ast/inline.js.map +1 -0
- package/dist/ast/presentation.d.ts +41 -0
- package/dist/ast/presentation.d.ts.map +1 -0
- package/dist/ast/presentation.js +8 -0
- package/dist/ast/presentation.js.map +1 -0
- package/dist/ast/span.d.ts +19 -0
- package/dist/ast/span.d.ts.map +1 -0
- package/dist/ast/span.js +2 -0
- package/dist/ast/span.js.map +1 -0
- package/dist/ast/story.d.ts +354 -0
- package/dist/ast/story.d.ts.map +1 -0
- package/dist/ast/story.js +2 -0
- package/dist/ast/story.js.map +1 -0
- package/dist/compile.d.ts +25 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +19 -0
- package/dist/compile.js.map +1 -0
- package/dist/diagnostics/codes.d.ts +26 -0
- package/dist/diagnostics/codes.d.ts.map +1 -0
- package/dist/diagnostics/codes.js +69 -0
- package/dist/diagnostics/codes.js.map +1 -0
- package/dist/diagnostics/index.d.ts +3 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +2 -0
- package/dist/diagnostics/index.js.map +1 -0
- package/dist/diagnostics/types.d.ts +19 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +2 -0
- package/dist/diagnostics/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/blocks.d.ts +40 -0
- package/dist/parser/blocks.d.ts.map +1 -0
- package/dist/parser/blocks.js +927 -0
- package/dist/parser/blocks.js.map +1 -0
- package/dist/parser/directive-line.d.ts +21 -0
- package/dist/parser/directive-line.d.ts.map +1 -0
- package/dist/parser/directive-line.js +50 -0
- package/dist/parser/directive-line.js.map +1 -0
- package/dist/parser/document.d.ts +13 -0
- package/dist/parser/document.d.ts.map +1 -0
- package/dist/parser/document.js +28 -0
- package/dist/parser/document.js.map +1 -0
- package/dist/parser/expression-lexer.d.ts +44 -0
- package/dist/parser/expression-lexer.d.ts.map +1 -0
- package/dist/parser/expression-lexer.js +166 -0
- package/dist/parser/expression-lexer.js.map +1 -0
- package/dist/parser/expression-parser.d.ts +13 -0
- package/dist/parser/expression-parser.d.ts.map +1 -0
- package/dist/parser/expression-parser.js +201 -0
- package/dist/parser/expression-parser.js.map +1 -0
- package/dist/parser/frontmatter.d.ts +23 -0
- package/dist/parser/frontmatter.d.ts.map +1 -0
- package/dist/parser/frontmatter.js +158 -0
- package/dist/parser/frontmatter.js.map +1 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +2 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/lexical-primitives.d.ts +38 -0
- package/dist/parser/lexical-primitives.d.ts.map +1 -0
- package/dist/parser/lexical-primitives.js +46 -0
- package/dist/parser/lexical-primitives.js.map +1 -0
- package/dist/parser/lines.d.ts +32 -0
- package/dist/parser/lines.d.ts.map +1 -0
- package/dist/parser/lines.js +60 -0
- package/dist/parser/lines.js.map +1 -0
- package/dist/parser/markdown.d.ts +19 -0
- package/dist/parser/markdown.d.ts.map +1 -0
- package/dist/parser/markdown.js +221 -0
- package/dist/parser/markdown.js.map +1 -0
- package/dist/parser/serializer-safety.d.ts +57 -0
- package/dist/parser/serializer-safety.d.ts.map +1 -0
- package/dist/parser/serializer-safety.js +66 -0
- package/dist/parser/serializer-safety.js.map +1 -0
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +2 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/validate.d.ts +4 -0
- package/dist/validation/validate.d.ts.map +1 -0
- package/dist/validation/validate.js +221 -0
- package/dist/validation/validate.js.map +1 -0
- package/package.json +43 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-parser.js","sourceRoot":"","sources":["../../src/parser/expression-parser.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAEnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,MAAM,iBAAiB,GAAqC;IAC1D,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;CACP,CAAC;AAEF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAE5C;;;;GAIG;AACH,MAAM,gBAAgB;IAMD;IALF,MAAM,CAA6B;IAC5C,GAAG,GAAG,CAAC,CAAC;IAEhB,YACE,MAAc,EACG,YAA4B;QAA5B,iBAAY,GAAZ,YAAY,CAAgB;QAE7C,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,YAAY;QACV,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACrC,MAAM,QAAQ,GA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MAAM,IAAI,qBAAqB,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,IAAI,gBAAgB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,YAAY,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StoryMetadata, StoryStateDefinition } from "../ast/story.js";
|
|
2
|
+
import type { Diagnostic } from "../diagnostics/types.js";
|
|
3
|
+
import { type SourceLine } from "./lines.js";
|
|
4
|
+
export interface FrontmatterResult {
|
|
5
|
+
readonly metadata: StoryMetadata;
|
|
6
|
+
readonly initialState: StoryStateDefinition;
|
|
7
|
+
/** Source lines that remain to be parsed as the story body. */
|
|
8
|
+
readonly bodyLines: readonly SourceLine[];
|
|
9
|
+
readonly diagnostics: Diagnostic[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Extracts and parses a leading `--- ... ---` YAML frontmatter block, if
|
|
13
|
+
* present, normalizing it into a StoryMetadata plus a first-class initial
|
|
14
|
+
* state map. Unsupported state values (arrays, nested objects, YAML
|
|
15
|
+
* timestamps/binary/aliases, ...) are reported as AT1201 diagnostics and
|
|
16
|
+
* dropped from the state map rather than throwing. If the YAML itself has
|
|
17
|
+
* syntax errors, only AT1202 is reported for `state:` — semantic
|
|
18
|
+
* validation of its (possibly parser-recovered, unreliable) contents is
|
|
19
|
+
* skipped to avoid a misleading AT1201 cascade. Returns the remaining
|
|
20
|
+
* body lines (frontmatter stripped) for the block parser to consume.
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractFrontmatter(source: string): FrontmatterResult;
|
|
23
|
+
//# sourceMappingURL=frontmatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/parser/frontmatter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAc,aAAa,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAgD,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE3F,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,EAAE,SAAS,UAAU,EAAE,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;CACpC;AAgDD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAgHpE"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { isMap, isScalar, LineCounter, parseDocument } from "yaml";
|
|
2
|
+
import { Diagnostics } from "../diagnostics/codes.js";
|
|
3
|
+
import { variableNameProblem } from "./expression-lexer.js";
|
|
4
|
+
import { joinLineText, lineEnd, lineStart, splitLines } from "./lines.js";
|
|
5
|
+
const DELIMITER = "---";
|
|
6
|
+
/** A YAML scalar resolving to one of v0.1's allowed initial-state value types. */
|
|
7
|
+
function isAllowedScalarNode(node) {
|
|
8
|
+
if (!node || !isScalar(node))
|
|
9
|
+
return false;
|
|
10
|
+
const value = node.value;
|
|
11
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
12
|
+
}
|
|
13
|
+
function keyName(key) {
|
|
14
|
+
return isScalar(key) ? String(key.value) : String(key);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The state key exactly as the author wrote it. The YAML core schema reads an
|
|
18
|
+
* unquoted `TRUE`, `False`, `Null`, or `~` as a boolean/null and `0x10` as a
|
|
19
|
+
* number, so `String(key.value)` would silently turn the declared key `TRUE`
|
|
20
|
+
* into `"true"`. For plain scalars the original source text is the key; quoted
|
|
21
|
+
* scalars already carry their text as the value.
|
|
22
|
+
*/
|
|
23
|
+
function stateKeyName(key) {
|
|
24
|
+
if (isScalar(key) && key.type === "PLAIN" && typeof key.source === "string")
|
|
25
|
+
return key.source;
|
|
26
|
+
return keyName(key);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `__proto__` is rejected as a state key, but not as a `@set` name: assigned
|
|
30
|
+
* through the plain-object initial-state map it would silently vanish (or,
|
|
31
|
+
* for `null`, change the map's prototype), so the declaration could not be
|
|
32
|
+
* trusted to round-trip. See CORE_SPEC Section 12.
|
|
33
|
+
*/
|
|
34
|
+
const FORBIDDEN_STATE_KEY = "__proto__";
|
|
35
|
+
/** The reason a frontmatter `state:` key is not a valid state variable name, if any. */
|
|
36
|
+
function stateKeyProblem(key) {
|
|
37
|
+
if (key === FORBIDDEN_STATE_KEY)
|
|
38
|
+
return `"${FORBIDDEN_STATE_KEY}" is not allowed as a state key.`;
|
|
39
|
+
switch (variableNameProblem(key)) {
|
|
40
|
+
case "invalid-identifier":
|
|
41
|
+
return "state keys must match [A-Za-z_][A-Za-z0-9_]*.";
|
|
42
|
+
case "reserved-literal":
|
|
43
|
+
return `"${key}" is a reserved literal and cannot be a state variable name.`;
|
|
44
|
+
default:
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Extracts and parses a leading `--- ... ---` YAML frontmatter block, if
|
|
50
|
+
* present, normalizing it into a StoryMetadata plus a first-class initial
|
|
51
|
+
* state map. Unsupported state values (arrays, nested objects, YAML
|
|
52
|
+
* timestamps/binary/aliases, ...) are reported as AT1201 diagnostics and
|
|
53
|
+
* dropped from the state map rather than throwing. If the YAML itself has
|
|
54
|
+
* syntax errors, only AT1202 is reported for `state:` — semantic
|
|
55
|
+
* validation of its (possibly parser-recovered, unreliable) contents is
|
|
56
|
+
* skipped to avoid a misleading AT1201 cascade. Returns the remaining
|
|
57
|
+
* body lines (frontmatter stripped) for the block parser to consume.
|
|
58
|
+
*/
|
|
59
|
+
export function extractFrontmatter(source) {
|
|
60
|
+
const lines = splitLines(source);
|
|
61
|
+
const diagnostics = [];
|
|
62
|
+
const emptyMetadata = { title: undefined, entry: undefined, span: undefined };
|
|
63
|
+
const empty = { metadata: emptyMetadata, initialState: {}, bodyLines: lines, diagnostics };
|
|
64
|
+
if (lines.length === 0 || lines[0].text.trim() !== DELIMITER) {
|
|
65
|
+
return empty;
|
|
66
|
+
}
|
|
67
|
+
let closingIndex = -1;
|
|
68
|
+
for (let i = 1; i < lines.length; i++) {
|
|
69
|
+
if (lines[i].text.trim() === DELIMITER) {
|
|
70
|
+
closingIndex = i;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (closingIndex === -1) {
|
|
75
|
+
// No closing delimiter: treat the whole thing as body (best-effort recovery).
|
|
76
|
+
return empty;
|
|
77
|
+
}
|
|
78
|
+
const openLine = lines[0];
|
|
79
|
+
const closeLine = lines[closingIndex];
|
|
80
|
+
const yamlLines = lines.slice(1, closingIndex);
|
|
81
|
+
const yamlText = joinLineText(yamlLines);
|
|
82
|
+
const span = { start: lineStart(openLine), end: lineEnd(closeLine) };
|
|
83
|
+
const bodyLines = lines.slice(closingIndex + 1);
|
|
84
|
+
const anchorLine = yamlLines.length > 0 ? yamlLines[0].number : openLine.number + 1;
|
|
85
|
+
const anchorOffset = yamlLines.length > 0 ? yamlLines[0].startOffset : closeLine.startOffset;
|
|
86
|
+
const lineCounter = new LineCounter();
|
|
87
|
+
const doc = parseDocument(yamlText, { lineCounter, prettyErrors: false });
|
|
88
|
+
function positionAt(offset) {
|
|
89
|
+
const local = lineCounter.linePos(offset);
|
|
90
|
+
return { line: anchorLine + (local.line - 1), column: local.col, offset: anchorOffset + offset };
|
|
91
|
+
}
|
|
92
|
+
function spanOfNode(node) {
|
|
93
|
+
const range = node.range;
|
|
94
|
+
if (!range) {
|
|
95
|
+
const fallback = positionAt(0);
|
|
96
|
+
return { start: fallback, end: fallback };
|
|
97
|
+
}
|
|
98
|
+
return { start: positionAt(range[0]), end: positionAt(range[1]) };
|
|
99
|
+
}
|
|
100
|
+
// YAML syntax errors (e.g. an unclosed flow sequence) don't throw — the
|
|
101
|
+
// `yaml` package collects them here and still returns a best-effort,
|
|
102
|
+
// partially-resolved document. Surface each as an AT1202 diagnostic
|
|
103
|
+
// rather than silently continuing on possibly-broken content.
|
|
104
|
+
const hasYamlSyntaxErrors = doc.errors.length > 0;
|
|
105
|
+
for (const error of doc.errors) {
|
|
106
|
+
const errorSpan = { start: positionAt(error.pos[0]), end: positionAt(error.pos[1]) };
|
|
107
|
+
diagnostics.push(Diagnostics.invalidFrontmatter(error.message, errorSpan));
|
|
108
|
+
}
|
|
109
|
+
let title;
|
|
110
|
+
let entry;
|
|
111
|
+
const state = {};
|
|
112
|
+
if (isMap(doc.contents)) {
|
|
113
|
+
for (const pair of doc.contents.items) {
|
|
114
|
+
const key = keyName(pair.key);
|
|
115
|
+
const value = pair.value;
|
|
116
|
+
if (key === "title" && isAllowedScalarNode(value) && typeof value.value === "string") {
|
|
117
|
+
title = value.value;
|
|
118
|
+
}
|
|
119
|
+
else if (key === "entry" && isAllowedScalarNode(value) && typeof value.value === "string") {
|
|
120
|
+
entry = value.value;
|
|
121
|
+
}
|
|
122
|
+
else if (key === "state" && !hasYamlSyntaxErrors) {
|
|
123
|
+
// Skip semantic validation of `state:` entirely when the YAML
|
|
124
|
+
// itself failed to parse cleanly — the tree the parser recovers
|
|
125
|
+
// around a syntax error doesn't reflect the author's intent, and
|
|
126
|
+
// validating it would only produce misleading AT1201 diagnostics
|
|
127
|
+
// cascading from the real AT1202 syntax error.
|
|
128
|
+
if (value && isMap(value)) {
|
|
129
|
+
for (const statePair of value.items) {
|
|
130
|
+
const stateKey = stateKeyName(statePair.key);
|
|
131
|
+
const stateValue = statePair.value;
|
|
132
|
+
const keyProblem = stateKeyProblem(stateKey);
|
|
133
|
+
if (keyProblem !== undefined) {
|
|
134
|
+
// One diagnostic per bad entry, on the key itself; the entry is
|
|
135
|
+
// dropped so the initial state never holds an unreferenceable key.
|
|
136
|
+
const keyNode = statePair.key;
|
|
137
|
+
diagnostics.push(Diagnostics.unsupportedStateKey(stateKey, keyProblem, spanOfNode(keyNode ?? stateValue ?? value)));
|
|
138
|
+
}
|
|
139
|
+
else if (isAllowedScalarNode(stateValue)) {
|
|
140
|
+
state[stateKey] = stateValue.value;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
diagnostics.push(Diagnostics.unsupportedStateValue(stateKey, spanOfNode(stateValue ?? value)));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (value && !(isScalar(value) && value.value === null)) {
|
|
148
|
+
// `state:` with no value at all resolves to a null scalar — treated
|
|
149
|
+
// as "no initial state", not a malformed declaration.
|
|
150
|
+
diagnostics.push(Diagnostics.unsupportedStateValue("state", spanOfNode(value)));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const metadata = { title, entry, span };
|
|
156
|
+
return { metadata, initialState: state, bodyLines, diagnostics };
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/parser/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAInE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAmB,MAAM,YAAY,CAAC;AAU3F,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB,kFAAkF;AAClF,SAAS,mBAAmB,CAAC,IAA6B;IACxD,IAAI,CAAC,IAAI,IAAI,C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kB,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACvD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, dependency-free lexical facts shared between the block parser
|
|
3
|
+
* (`blocks.ts`) and the public serializer-safety predicates
|
|
4
|
+
* (`serializer-safety.ts`, docs/CORE_SPEC.md Section 25.40's "Serializer
|
|
5
|
+
* Injection Safety Amendment"). Deliberately has zero imports — in
|
|
6
|
+
* particular, no `remark`/`mdast` dependency — so it can be safely reached
|
|
7
|
+
* from the public compiler surface (`src/index.ts`) without pulling in
|
|
8
|
+
* anything `parseProseChunk`/`markdown.ts` needs.
|
|
9
|
+
*
|
|
10
|
+
* `blocks.ts` and `serializer-safety.ts` both import these two facts from
|
|
11
|
+
* here rather than each defining/scanning for them independently, so the
|
|
12
|
+
* parser's actual tokenization behavior and the tooling-facing boundary-
|
|
13
|
+
* safety predicates cannot silently drift apart.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The exact separator-whitespace definition Presentation argument
|
|
17
|
+
* tokenization (`tokenizePresentationArgs`) and Choice tail parsing
|
|
18
|
+
* (`CHOICE_TAIL_PATTERN`'s `if`-separator) both use to recognize a token
|
|
19
|
+
* boundary — expressed as raw regex source so it can be interpolated into a
|
|
20
|
+
* larger composite pattern (`CHOICE_TAIL_PATTERN`) as well as used directly
|
|
21
|
+
* via `SEPARATOR_WHITESPACE_PATTERN`. Keeping one source string, rather than
|
|
22
|
+
* a hardcoded `\s` duplicated at each use site, is what makes it a true
|
|
23
|
+
* single source of truth — a `RegExp` object alone cannot be spliced into
|
|
24
|
+
* another pattern's literal source.
|
|
25
|
+
*/
|
|
26
|
+
export declare const SEPARATOR_WHITESPACE_SOURCE: string;
|
|
27
|
+
/** The exact separator-whitespace definition Presentation argument tokenization (`tokenizePresentationArgs`) and Choice tail parsing both use to recognize a token boundary. */
|
|
28
|
+
export declare const SEPARATOR_WHITESPACE_PATTERN: RegExp;
|
|
29
|
+
/**
|
|
30
|
+
* Finds the last `->` in `text` that isn't escaped as `\->`, scanning left
|
|
31
|
+
* to right so an escaped arrow inside display text (`A \-> B`) is skipped
|
|
32
|
+
* and only a real, unescaped arrow can act as the Choice item delimiter.
|
|
33
|
+
* Using the *last* unescaped arrow (rather than the first) means display
|
|
34
|
+
* text is free to contain its own literal `->` via escaping without
|
|
35
|
+
* confusing the split. Returns -1 if no unescaped arrow exists.
|
|
36
|
+
*/
|
|
37
|
+
export declare function findLastUnescapedArrow(text: string): number;
|
|
38
|
+
//# sourceMappingURL=lexical-primitives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexical-primitives.d.ts","sourceRoot":"","sources":["../../src/parser/lexical-primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,QAAiB,CAAC;AAE1D,gLAAgL;AAChL,eAAO,MAAM,4BAA4B,QAA0C,CAAC;AAEpF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ3D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, dependency-free lexical facts shared between the block parser
|
|
3
|
+
* (`blocks.ts`) and the public serializer-safety predicates
|
|
4
|
+
* (`serializer-safety.ts`, docs/CORE_SPEC.md Section 25.40's "Serializer
|
|
5
|
+
* Injection Safety Amendment"). Deliberately has zero imports — in
|
|
6
|
+
* particular, no `remark`/`mdast` dependency — so it can be safely reached
|
|
7
|
+
* from the public compiler surface (`src/index.ts`) without pulling in
|
|
8
|
+
* anything `parseProseChunk`/`markdown.ts` needs.
|
|
9
|
+
*
|
|
10
|
+
* `blocks.ts` and `serializer-safety.ts` both import these two facts from
|
|
11
|
+
* here rather than each defining/scanning for them independently, so the
|
|
12
|
+
* parser's actual tokenization behavior and the tooling-facing boundary-
|
|
13
|
+
* safety predicates cannot silently drift apart.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The exact separator-whitespace definition Presentation argument
|
|
17
|
+
* tokenization (`tokenizePresentationArgs`) and Choice tail parsing
|
|
18
|
+
* (`CHOICE_TAIL_PATTERN`'s `if`-separator) both use to recognize a token
|
|
19
|
+
* boundary — expressed as raw regex source so it can be interpolated into a
|
|
20
|
+
* larger composite pattern (`CHOICE_TAIL_PATTERN`) as well as used directly
|
|
21
|
+
* via `SEPARATOR_WHITESPACE_PATTERN`. Keeping one source string, rather than
|
|
22
|
+
* a hardcoded `\s` duplicated at each use site, is what makes it a true
|
|
23
|
+
* single source of truth — a `RegExp` object alone cannot be spliced into
|
|
24
|
+
* another pattern's literal source.
|
|
25
|
+
*/
|
|
26
|
+
export const SEPARATOR_WHITESPACE_SOURCE = String.raw `\s`;
|
|
27
|
+
/** The exact separator-whitespace definition Presentation argument tokenization (`tokenizePresentationArgs`) and Choice tail parsing both use to recognize a token boundary. */
|
|
28
|
+
export const SEPARATOR_WHITESPACE_PATTERN = new RegExp(SEPARATOR_WHITESPACE_SOURCE);
|
|
29
|
+
/**
|
|
30
|
+
* Finds the last `->` in `text` that isn't escaped as `\->`, scanning left
|
|
31
|
+
* to right so an escaped arrow inside display text (`A \-> B`) is skipped
|
|
32
|
+
* and only a real, unescaped arrow can act as the Choice item delimiter.
|
|
33
|
+
* Using the *last* unescaped arrow (rather than the first) means display
|
|
34
|
+
* text is free to contain its own literal `->` via escaping without
|
|
35
|
+
* confusing the split. Returns -1 if no unescaped arrow exists.
|
|
36
|
+
*/
|
|
37
|
+
export function findLastUnescapedArrow(text) {
|
|
38
|
+
let lastIndex = -1;
|
|
39
|
+
for (let i = 0; i < text.length - 1; i++) {
|
|
40
|
+
if (text[i] === "-" && text[i + 1] === ">" && text[i - 1] !== "\\") {
|
|
41
|
+
lastIndex = i;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return lastIndex;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=lexical-primitives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexical-primitives.js","sourceRoot":"","sources":["../../src/parser/lexical-primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,GAAG,CAAA,IAAI,CAAC;AAE1D,gLAAgL;AAChL,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEpF;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACnE,SAAS,GAAG,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SourcePosition } from "../ast/span.js";
|
|
2
|
+
/** One physical line of source, with its absolute offsets in the full source string. */
|
|
3
|
+
export interface SourceLine {
|
|
4
|
+
/** 1-based line number. */
|
|
5
|
+
readonly number: number;
|
|
6
|
+
/** Offset of the first character of this line (before any trailing \r\n stripping). */
|
|
7
|
+
readonly startOffset: number;
|
|
8
|
+
/** Offset just past the last content character, excluding the line terminator. */
|
|
9
|
+
readonly endOffset: number;
|
|
10
|
+
/** Line text with any trailing \r\n / \n stripped. */
|
|
11
|
+
readonly text: string;
|
|
12
|
+
/** Length of the line terminator that followed this line: 0, 1 (\n) or 2 (\r\n). */
|
|
13
|
+
readonly newlineLength: 0 | 1 | 2;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Splits source into lines while tracking absolute offsets, so downstream
|
|
17
|
+
* AST nodes can carry accurate SourceSpans back into the original text.
|
|
18
|
+
*/
|
|
19
|
+
export declare function splitLines(source: string): SourceLine[];
|
|
20
|
+
/** The position of the start of a line (column 1). */
|
|
21
|
+
export declare function lineStart(line: SourceLine): SourcePosition;
|
|
22
|
+
/** The position just past the end of a line's content. */
|
|
23
|
+
export declare function lineEnd(line: SourceLine): SourcePosition;
|
|
24
|
+
/**
|
|
25
|
+
* Reconstructs the exact original source text spanned by a contiguous run
|
|
26
|
+
* of lines (including original line terminators), so it can be re-parsed
|
|
27
|
+
* (e.g. by remark) with offsets that stay in lockstep with the full source.
|
|
28
|
+
*/
|
|
29
|
+
export declare function joinLineText(lines: readonly SourceLine[]): string;
|
|
30
|
+
/** Position of a given 0-based character index within a line's text. */
|
|
31
|
+
export declare function positionAt(line: SourceLine, charIndex: number): SourcePosition;
|
|
32
|
+
//# sourceMappingURL=lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../src/parser/lines.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,wFAAwF;AACxF,MAAM,WAAW,UAAU;IACzB,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,uFAAuF;IACvF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,kFAAkF;IAClF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oFAAoF;IACpF,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,CA0BvD;AAED,sDAAsD;AACtD,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAE1D;AAED,0DAA0D;AAC1D,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAMxD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,CAIjE;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAM9E"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits source into lines while tracking absolute offsets, so downstream
|
|
3
|
+
* AST nodes can carry accurate SourceSpans back into the original text.
|
|
4
|
+
*/
|
|
5
|
+
export function splitLines(source) {
|
|
6
|
+
const lines = [];
|
|
7
|
+
let start = 0;
|
|
8
|
+
let lineNumber = 1;
|
|
9
|
+
for (let i = 0; i <= source.length; i++) {
|
|
10
|
+
if (i === source.length || source[i] === "\n") {
|
|
11
|
+
let end = i;
|
|
12
|
+
let newlineLength = i === source.length ? 0 : 1;
|
|
13
|
+
if (end > start && source[end - 1] === "\r") {
|
|
14
|
+
end -= 1;
|
|
15
|
+
newlineLength = 2;
|
|
16
|
+
}
|
|
17
|
+
lines.push({
|
|
18
|
+
number: lineNumber,
|
|
19
|
+
startOffset: start,
|
|
20
|
+
endOffset: end,
|
|
21
|
+
text: source.slice(start, end),
|
|
22
|
+
newlineLength
|
|
23
|
+
});
|
|
24
|
+
lineNumber += 1;
|
|
25
|
+
start = i + 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return lines;
|
|
29
|
+
}
|
|
30
|
+
/** The position of the start of a line (column 1). */
|
|
31
|
+
export function lineStart(line) {
|
|
32
|
+
return { line: line.number, column: 1, offset: line.startOffset };
|
|
33
|
+
}
|
|
34
|
+
/** The position just past the end of a line's content. */
|
|
35
|
+
export function lineEnd(line) {
|
|
36
|
+
return {
|
|
37
|
+
line: line.number,
|
|
38
|
+
column: line.endOffset - line.startOffset + 1,
|
|
39
|
+
offset: line.endOffset
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reconstructs the exact original source text spanned by a contiguous run
|
|
44
|
+
* of lines (including original line terminators), so it can be re-parsed
|
|
45
|
+
* (e.g. by remark) with offsets that stay in lockstep with the full source.
|
|
46
|
+
*/
|
|
47
|
+
export function joinLineText(lines) {
|
|
48
|
+
return lines
|
|
49
|
+
.map((line) => line.text + (line.newlineLength === 2 ? "\r\n" : line.newlineLength === 1 ? "\n" : ""))
|
|
50
|
+
.join("");
|
|
51
|
+
}
|
|
52
|
+
/** Position of a given 0-based character index within a line's text. */
|
|
53
|
+
export function positionAt(line, charIndex) {
|
|
54
|
+
return {
|
|
55
|
+
line: line.number,
|
|
56
|
+
column: charIndex + 1,
|
|
57
|
+
offset: line.startOffset + charIndex
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines.js","sourceRoot":"","sources":["../../src/parser/lines.ts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AAU,OAAO,CAAC,IAAgB;IACtC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,MAAM,EAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,WAAW,GAAG,CAAC;QAC7C,MAAM,EAAE,IAAI,CAAC,SAAS;KACvB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAA4B;IACvD,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACrG,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,IAAgB,EAAE,SAAiB;IAC5D,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,MAAM,EAAE,SAAS,GAAG,CAAC;QACrB,MAAM,EAAE,IAAI,CAAC,WAAW,GAAG,SAAS;KACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StoryBlock } from "../ast/story.js";
|
|
2
|
+
import type { Diagnostic } from "../diagnostics/types.js";
|
|
3
|
+
interface ChunkAnchor {
|
|
4
|
+
/** 1-based line number of the chunk's first line in the full document. */
|
|
5
|
+
readonly startLine: number;
|
|
6
|
+
/** Absolute character offset of the chunk's first character in the full document. */
|
|
7
|
+
readonly startOffset: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parses a contiguous run of prose source text (already known to contain no
|
|
11
|
+
* AfterText directives) as Markdown, converting the result into
|
|
12
|
+
* AfterText-owned StoryBlock nodes anchored back to the full document via
|
|
13
|
+
* `anchor`. Constructs outside v0.1's supported subset (lists, blockquotes,
|
|
14
|
+
* images, code blocks, ...) still fall back to flattened plain text, but
|
|
15
|
+
* emit an AT3001 warning rather than changing document meaning silently.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseProseChunk(text: string, anchor: ChunkAnchor, diagnostics: Diagnostic[]): StoryBlock[];
|
|
18
|
+
export type { ChunkAnchor };
|
|
19
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAA8B,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAY1D,UAAU,WAAW;IACnB,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qFAAqF;IACrF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AA6ND;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAI1G;AAED,YAAY,EAAE,WAAW,EAAE,CAAC"}
|