@aufbau/syntax 0.0.5 → 0.0.6
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/CHANGELOG.md +129 -0
- package/README.md +5 -2
- package/dist/delimiters.d.ts +13 -0
- package/dist/delimiters.js +26 -0
- package/dist/delimiters.js.map +1 -1
- package/dist/elab.d.ts +3 -1
- package/dist/elab.js +49 -5
- package/dist/elab.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/parse.d.ts +28 -14
- package/dist/parse.js +108 -49
- package/dist/parse.js.map +1 -1
- package/dist/print.d.ts +42 -9
- package/dist/print.js +383 -144
- package/dist/print.js.map +1 -1
- package/dist/reader/annotations.d.ts +14 -1
- package/dist/reader/annotations.js +14 -1
- package/dist/reader/annotations.js.map +1 -1
- package/dist/reader/spec.d.ts +47 -0
- package/dist/reader/spec.js +175 -41
- package/dist/reader/spec.js.map +1 -1
- package/dist/reader/statements.d.ts +18 -2
- package/dist/reader/statements.js +54 -16
- package/dist/reader/statements.js.map +1 -1
- package/dist/scan.d.ts +3 -2
- package/dist/scan.js +1 -0
- package/dist/scan.js.map +1 -1
- package/dist/unfold.d.ts +23 -0
- package/dist/unfold.js +131 -0
- package/dist/unfold.js.map +1 -0
- package/dist/vocabulary.d.ts +9 -0
- package/dist/vocabulary.js +21 -5
- package/dist/vocabulary.js.map +1 -1
- package/package.json +1 -1
package/dist/reader/spec.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { delimiterRules, isReachableChunk, segment, } from "../delimiters.js";
|
|
11
11
|
import { diagnostic, } from "../diagnostics.js";
|
|
12
|
-
import { surfaceVocabulary } from "../vocabulary.js";
|
|
12
|
+
import { nameOnlyTerms, surfaceVocabulary } from "../vocabulary.js";
|
|
13
13
|
import { parseSyntaxAnnotation, } from "./annotations.js";
|
|
14
14
|
import { parseStatements, } from "./statements.js";
|
|
15
15
|
const TEMPLATES = {
|
|
@@ -33,10 +33,16 @@ const TEMPLATES = {
|
|
|
33
33
|
refusal_target: "@syntax forbid must sit on a two-place term with an infix notation",
|
|
34
34
|
elided_duplicate: "sort {sort} already has an elided term",
|
|
35
35
|
vars_term_conflict: "@vars token {token} is also a declared term; a name can be only one",
|
|
36
|
-
role_target: "@syntax role must sit on a sort or a
|
|
37
|
-
|
|
36
|
+
role_target: "@syntax role must sit on a sort, a term, or a rule",
|
|
37
|
+
alias_target: "@syntax alias must sit on an axiom or a theorem",
|
|
38
|
+
alias_is_rule_name: "{alias} is already the name of a rule, so it cannot be an alias",
|
|
39
|
+
alias_duplicate: "{alias} already names {rule}",
|
|
40
|
+
fallback_unknown: "@fallback {rule} does not name an earlier axiom or theorem",
|
|
41
|
+
fallback_duplicate: "a rule may carry only one @fallback",
|
|
42
|
+
delimiter_unknown: "delimiter {token} is neither a notation token, a bracket, a lexicon name, nor an elab literal, so no input can ever be read as it",
|
|
38
43
|
delimiter_token_not_delimited: "{token} is not a surface delimiter; it is only read when whitespace or a delimiter bounds it, so it will run into an adjacent token",
|
|
39
44
|
delimiter_unreachable_name: "the delimiters split {name} into {chunks}, so it can never be read as one name",
|
|
45
|
+
delimiter_splits_token: "the delimiters split the notation token {token} into {chunks}, so it can never be read; mm0.md requires a token not to contain a delimiter",
|
|
40
46
|
};
|
|
41
47
|
function report(diagnostics, id, params, span, severity = "error") {
|
|
42
48
|
diagnostics.push(diagnostic(id, TEMPLATES[id] ?? id, params, span, severity));
|
|
@@ -83,6 +89,28 @@ function tokenSpans(spec) {
|
|
|
83
89
|
}
|
|
84
90
|
return spans;
|
|
85
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* A notation token a delimiter cuts through is dead: mm0.md forbids it
|
|
94
|
+
* outright ("a declared token must not contain a delimiter token as a
|
|
95
|
+
* substring"), the engine cannot read it either, and the printer never
|
|
96
|
+
* picks it as a spelling. A warning rather than an error, since the
|
|
97
|
+
* engine tolerates the declaration — `/\\` beside `∧` in a file whose
|
|
98
|
+
* `[x/t]` makes `/` a delimiter — and so does everything here.
|
|
99
|
+
*/
|
|
100
|
+
function reportDeadTokens(spec, diagnostics) {
|
|
101
|
+
// The theory's own delimiters, not the surface set: a token the surface
|
|
102
|
+
// letters split (`tsub` under forallx) is an engine-only notation, and
|
|
103
|
+
// `delimiter_token_not_delimited` already says so.
|
|
104
|
+
const rules = delimiterRules(spec.delimiters);
|
|
105
|
+
const spans = tokenSpans(spec);
|
|
106
|
+
for (const token of surfaceVocabulary(spec).tokens) {
|
|
107
|
+
const span = spans.get(token);
|
|
108
|
+
if (span === undefined || isReachableChunk(token, rules)) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
report(diagnostics, "delimiter_splits_token", { chunks: segment(token, rules).join(" "), token }, span, "warning");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
86
114
|
/**
|
|
87
115
|
* The surface delimiter set, checked against the vocabulary it has to cut
|
|
88
116
|
* up. Only runs when the spec declares `@syntax delimiter`: a spec that
|
|
@@ -101,10 +129,16 @@ function checkSurfaceDelimiters(spec, declarations, diagnostics) {
|
|
|
101
129
|
...spec.surfaceDelimiters.right,
|
|
102
130
|
]);
|
|
103
131
|
// A delimiter nothing can be classified as cuts input into pieces the
|
|
104
|
-
// parser must then reject — a boundary with no meaning behind it.
|
|
132
|
+
// parser must then reject — a boundary with no meaning behind it. An elab
|
|
133
|
+
// literal is a meaning: the layer reads that chunk before the parser does,
|
|
134
|
+
// and a delimiter is the only way to give it its own chunk when it is
|
|
135
|
+
// glued to a name (`x'`).
|
|
136
|
+
const literals = new Set([...matchedLiterals(spec)].map(({ token }) => token));
|
|
105
137
|
for (const { entries, span } of declarations) {
|
|
106
138
|
for (const entry of entries) {
|
|
107
|
-
if (!vocabulary.tokens.has(entry) &&
|
|
139
|
+
if (!vocabulary.tokens.has(entry) &&
|
|
140
|
+
!vocabulary.names.has(entry) &&
|
|
141
|
+
!literals.has(entry)) {
|
|
108
142
|
report(diagnostics, "delimiter_unknown", { token: entry }, span);
|
|
109
143
|
}
|
|
110
144
|
}
|
|
@@ -121,10 +155,14 @@ function checkSurfaceDelimiters(spec, declarations, diagnostics) {
|
|
|
121
155
|
}
|
|
122
156
|
// A name the delimiters split apart is unreachable: segmentation happens
|
|
123
157
|
// before anything knows the name exists, so no bracketing recovers it.
|
|
124
|
-
//
|
|
125
|
-
//
|
|
158
|
+
// Only a term with no other spelling is at stake; a notated term's name
|
|
159
|
+
// is MM0's application syntax, still reachable under the engine's own
|
|
160
|
+
// delimiters. Elided terms are exempt — they are supplied by the parser
|
|
161
|
+
// and dropped by the printer, never typed.
|
|
162
|
+
const nameOnly = nameOnlyTerms(spec);
|
|
126
163
|
for (const [name, ref] of vocabulary.names) {
|
|
127
|
-
if (ref.kind === "term" &&
|
|
164
|
+
if (ref.kind === "term" &&
|
|
165
|
+
(spec.terms.get(ref.term)?.elided === true || !nameOnly.has(ref.term))) {
|
|
128
166
|
continue;
|
|
129
167
|
}
|
|
130
168
|
if (isReachableChunk(name, rules)) {
|
|
@@ -142,10 +180,6 @@ function checkSurfaceDelimiters(spec, declarations, diagnostics) {
|
|
|
142
180
|
* of the layer — but it is matched one chunk at a time, so a literal the
|
|
143
181
|
* delimiters split can never match anything, and a rule that quietly does
|
|
144
182
|
* nothing is the failure this reader exists to prevent.
|
|
145
|
-
*
|
|
146
|
-
* Template literals are checked too, for every rule that is not
|
|
147
|
-
* `input-only`: delaboration runs the rule inverted, where the template's
|
|
148
|
-
* literals *are* the pattern.
|
|
149
183
|
*/
|
|
150
184
|
function checkElabLiterals(spec, diagnostics) {
|
|
151
185
|
const rules = delimiterRules(spec.surfaceDelimiters);
|
|
@@ -161,18 +195,24 @@ function checkElabLiterals(spec, diagnostics) {
|
|
|
161
195
|
report(diagnostics, "elab_literal_split", { chunks: segment(token, rules).join(" "), literal: token }, span);
|
|
162
196
|
}
|
|
163
197
|
};
|
|
198
|
+
for (const { token, span } of matchedLiterals(spec)) {
|
|
199
|
+
check(token, span);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Every elab literal some direction matches against text: each rule's
|
|
204
|
+
* pattern literals, and the template literals of every rule that is not
|
|
205
|
+
* `input-only`, since delaboration runs the rule inverted, where the
|
|
206
|
+
* template's literals *are* the pattern.
|
|
207
|
+
*/
|
|
208
|
+
function* matchedLiterals(spec) {
|
|
164
209
|
for (const rule of spec.elabRules) {
|
|
165
|
-
|
|
210
|
+
const elements = rule.inputOnly
|
|
211
|
+
? rule.pattern
|
|
212
|
+
: [...rule.pattern, ...rule.template];
|
|
213
|
+
for (const element of elements) {
|
|
166
214
|
if (element.kind === "literal") {
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (rule.inputOnly) {
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
for (const element of rule.template) {
|
|
174
|
-
if (element.kind === "literal") {
|
|
175
|
-
check(element.token, rule.span);
|
|
215
|
+
yield { token: element.token, span: rule.span };
|
|
176
216
|
}
|
|
177
217
|
}
|
|
178
218
|
}
|
|
@@ -183,6 +223,8 @@ export function parseSpec(source) {
|
|
|
183
223
|
const sorts = new Map();
|
|
184
224
|
const terms = new Map();
|
|
185
225
|
const coercions = [];
|
|
226
|
+
const rules = new Map();
|
|
227
|
+
const ruleAliases = new Map();
|
|
186
228
|
const notations = [];
|
|
187
229
|
const elabRules = [];
|
|
188
230
|
const lints = [];
|
|
@@ -215,7 +257,10 @@ export function parseSpec(source) {
|
|
|
215
257
|
}
|
|
216
258
|
switch (statement.kind) {
|
|
217
259
|
case "sort": {
|
|
218
|
-
|
|
260
|
+
// Sorts and terms are separate namespaces (peano.mm0 declares a
|
|
261
|
+
// sort `nat` and a def `nat`); each name may be declared once
|
|
262
|
+
// within its own.
|
|
263
|
+
if (sorts.has(statement.name)) {
|
|
219
264
|
report(diagnostics, "duplicate_declaration", { name: statement.name }, statement.span);
|
|
220
265
|
break;
|
|
221
266
|
}
|
|
@@ -240,30 +285,37 @@ export function parseSpec(source) {
|
|
|
240
285
|
}
|
|
241
286
|
case "term":
|
|
242
287
|
case "def": {
|
|
243
|
-
if (
|
|
288
|
+
if (terms.has(statement.name)) {
|
|
244
289
|
report(diagnostics, "duplicate_declaration", { name: statement.name }, statement.span);
|
|
245
290
|
break;
|
|
246
291
|
}
|
|
247
|
-
const returnSort = statement.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
const extra = statement.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
292
|
+
const returnSort = statement.returnChain[statement.returnChain.length - 1]?.sort ?? "";
|
|
293
|
+
// Arrow sugar (`a > b > c`) desugars to extra anonymous regular
|
|
294
|
+
// binders so arity means one thing everywhere downstream. A
|
|
295
|
+
// def's dot-dummies go the other way: they are variables of the
|
|
296
|
+
// definiens, never arguments, so they are no part of the
|
|
297
|
+
// syntax.
|
|
298
|
+
const extra = statement.returnChain
|
|
299
|
+
.slice(0, -1)
|
|
300
|
+
.map((type) => ({
|
|
301
|
+
binds: false,
|
|
302
|
+
dummy: false,
|
|
303
|
+
name: "_",
|
|
304
|
+
span: type.span,
|
|
305
|
+
type,
|
|
306
|
+
}));
|
|
307
|
+
const arguments_ = statement.binders.filter((binder) => !binder.dummy);
|
|
262
308
|
terms.set(statement.name, {
|
|
263
|
-
binders: [...
|
|
309
|
+
binders: [...arguments_, ...extra],
|
|
264
310
|
elided: false,
|
|
265
311
|
foreignAnnotations: foreign,
|
|
266
312
|
isDef: statement.kind === "def",
|
|
313
|
+
definition: statement.kind === "def" && statement.definiens !== null
|
|
314
|
+
? {
|
|
315
|
+
dummies: statement.binders.filter((binder) => binder.dummy),
|
|
316
|
+
text: statement.definiens.text,
|
|
317
|
+
}
|
|
318
|
+
: null,
|
|
267
319
|
juxtaposed: false,
|
|
268
320
|
juxtaposedCompound: false,
|
|
269
321
|
name: statement.name,
|
|
@@ -320,8 +372,46 @@ export function parseSpec(source) {
|
|
|
320
372
|
break;
|
|
321
373
|
}
|
|
322
374
|
case "axiom":
|
|
323
|
-
case "theorem":
|
|
375
|
+
case "theorem": {
|
|
376
|
+
// The engine refuses a second declaration of a name; recording it
|
|
377
|
+
// once here keeps the alias table from ever being ambiguous.
|
|
378
|
+
if (rules.has(statement.name)) {
|
|
379
|
+
report(diagnostics, "duplicate_declaration", { name: statement.name }, statement.span);
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
// The engine's `@fallback` is read like `@vars`: the line stays
|
|
383
|
+
// foreign, and the reader checks what the engine would, so a chain
|
|
384
|
+
// a consumer follows always points backwards and ends.
|
|
385
|
+
let fallback = null;
|
|
386
|
+
let fallbacks = 0;
|
|
387
|
+
for (const annotation of foreign) {
|
|
388
|
+
const [head, target = ""] = annotation.text.trim().split(/\s+/);
|
|
389
|
+
if (head !== "@fallback") {
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
fallbacks += 1;
|
|
393
|
+
if (fallbacks > 1) {
|
|
394
|
+
report(diagnostics, "fallback_duplicate", {}, annotation.span);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (rules.has(target)) {
|
|
398
|
+
fallback = target;
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
report(diagnostics, "fallback_unknown", { rule: target }, annotation.span);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
rules.set(statement.name, {
|
|
405
|
+
aliases: [],
|
|
406
|
+
fallback,
|
|
407
|
+
roles: [],
|
|
408
|
+
foreignAnnotations: foreign,
|
|
409
|
+
kind: statement.kind,
|
|
410
|
+
name: statement.name,
|
|
411
|
+
span: statement.span,
|
|
412
|
+
});
|
|
324
413
|
break;
|
|
414
|
+
}
|
|
325
415
|
}
|
|
326
416
|
}
|
|
327
417
|
// ── Second pass: interpret @syntax annotations now that names resolve.
|
|
@@ -390,6 +480,16 @@ export function parseSpec(source) {
|
|
|
390
480
|
}
|
|
391
481
|
break;
|
|
392
482
|
}
|
|
483
|
+
if (statement.kind === "axiom" || statement.kind === "theorem") {
|
|
484
|
+
const info = rules.get(statement.name);
|
|
485
|
+
if (info !== undefined) {
|
|
486
|
+
rules.set(statement.name, {
|
|
487
|
+
...info,
|
|
488
|
+
roles: [...info.roles, annotation.role],
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
393
493
|
if (statement.kind !== "term" && statement.kind !== "def") {
|
|
394
494
|
report(diagnostics, "role_target", {}, span);
|
|
395
495
|
break;
|
|
@@ -403,6 +503,37 @@ export function parseSpec(source) {
|
|
|
403
503
|
}
|
|
404
504
|
break;
|
|
405
505
|
}
|
|
506
|
+
case "alias": {
|
|
507
|
+
const info = statement.kind === "axiom" || statement.kind === "theorem"
|
|
508
|
+
? rules.get(statement.name)
|
|
509
|
+
: undefined;
|
|
510
|
+
if (info === undefined) {
|
|
511
|
+
report(diagnostics, "alias_target", {}, span);
|
|
512
|
+
break;
|
|
513
|
+
}
|
|
514
|
+
for (const alias of annotation.names) {
|
|
515
|
+
// A proof citing this name must mean one rule. The rule's own
|
|
516
|
+
// name is the engine's, and another rule's alias is taken.
|
|
517
|
+
if (rules.has(alias)) {
|
|
518
|
+
report(diagnostics, "alias_is_rule_name", { alias }, span);
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
const owner = ruleAliases.get(alias);
|
|
522
|
+
if (owner !== undefined) {
|
|
523
|
+
if (owner !== info.name) {
|
|
524
|
+
report(diagnostics, "alias_duplicate", { alias, rule: owner }, span);
|
|
525
|
+
}
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
ruleAliases.set(alias, info.name);
|
|
529
|
+
const current = rules.get(info.name) ?? info;
|
|
530
|
+
rules.set(info.name, {
|
|
531
|
+
...current,
|
|
532
|
+
aliases: [...current.aliases, alias],
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
406
537
|
case "brackets": {
|
|
407
538
|
for (const pair of annotation.pairs) {
|
|
408
539
|
const exists = groupingPairs.some(([open, close]) => open === pair[0] && close === pair[1]);
|
|
@@ -583,6 +714,8 @@ export function parseSpec(source) {
|
|
|
583
714
|
lints,
|
|
584
715
|
notations,
|
|
585
716
|
elabRules,
|
|
717
|
+
ruleAliases,
|
|
718
|
+
rules,
|
|
586
719
|
sorts,
|
|
587
720
|
statements,
|
|
588
721
|
// The union: what the engine splits on, plus what the textbook does.
|
|
@@ -592,6 +725,7 @@ export function parseSpec(source) {
|
|
|
592
725
|
},
|
|
593
726
|
terms,
|
|
594
727
|
};
|
|
728
|
+
reportDeadTokens(spec, diagnostics);
|
|
595
729
|
checkSurfaceDelimiters(spec, surfaceDeclarations, diagnostics);
|
|
596
730
|
checkElabLiterals(spec, diagnostics);
|
|
597
731
|
return { diagnostics, spec };
|
package/dist/reader/spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/reader/spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,cAAc,EACd,gBAAgB,EAChB,OAAO,GACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,UAAU,GAGX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAIL,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AA0GzB,MAAM,SAAS,GAA2B;IACxC,qBAAqB,EAAE,4BAA4B;IACnD,YAAY,EAAE,6BAA6B;IAC3C,YAAY,EAAE,6BAA6B;IAC3C,WAAW,EAAE,uDAAuD;IACpE,yBAAyB,EACvB,kEAAkE;IACpE,cAAc,EACZ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AC,CAAC,GAAG,eAAe,EAAE,GAAG,YAAY,CAAC,CAAC;SACtD;QACD,KAAK;KACN,CAAC;IAEF,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,EAAE,WAAW,CAAC,CAAC;IAC/D,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAErC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["/**\n * From parsed statements to a `Spec` — the library's central object: the\n * signature, notations, coercions, and `@syntax` surface metadata of one\n * logical system, validated.\n *\n * Validation here is about the spec being *coherent* (token conflicts,\n * dangling names, non-invertible elab rules); whether the theory proves\n * anything is the engine's business, and axiom bodies pass through opaque.\n */\n\nimport {\n type DelimiterSet,\n delimiterRules,\n isReachableChunk,\n segment,\n} from \"../delimiters.js\";\nimport {\n type Diagnostic,\n diagnostic,\n type Severity,\n type Span,\n} from \"../diagnostics.js\";\nimport { surfaceVocabulary } from \"../vocabulary.js\";\nimport {\n type ElabRule,\n type LintName,\n type OperandRelation,\n parseSyntaxAnnotation,\n type SyntaxAnnotation,\n} from \"./annotations.js\";\nimport {\n type Annotation,\n type Binder,\n type NotationLiteral,\n type Precedence,\n parseStatements,\n type Statement,\n} from \"./statements.js\";\n\nexport interface SortInfo {\n readonly foreignAnnotations: readonly Annotation[];\n readonly modifiers: readonly string[];\n readonly name: string;\n readonly roles: readonly string[];\n readonly span: Span;\n /**\n * The sort's variable tokens, read from the engine's own `@vars`\n * annotation (which stays in `foreignAnnotations` untouched — it is the\n * engine's, we only listen in). These are the surface lexicon's\n * identifiers of this sort; whether a quantifier can bind them falls\n * out of the quantifiers' binder sorts, not from here.\n */\n readonly vars: readonly string[];\n}\n\nexport interface TermInfo {\n readonly binders: readonly Binder[];\n /** `@syntax elided`: supplied when an argument of its sort is missing. */\n readonly elided: boolean;\n readonly foreignAnnotations: readonly Annotation[];\n /** True when this came from a `def` rather than a `term`. */\n readonly isDef: boolean;\n /** `@syntax juxtaposed`: adjacency of its sort's leaves denotes it. */\n readonly juxtaposed: boolean;\n /**\n * `@syntax juxtaposed compound`: a parenthesized group may stand as a\n * glue operand in argument position, not just a single token. False\n * whenever `juxtaposed` is.\n */\n readonly juxtaposedCompound: boolean;\n readonly name: string;\n /**\n * `@syntax forbid`: the unbracketed connective operands this term\n * refuses. Empty — the default — permits all three.\n * See {@link OperandRelation} for what each one names.\n */\n readonly refuses: ReadonlySet<OperandRelation>;\n readonly returnSort: string;\n readonly roles: readonly string[];\n readonly span: Span;\n}\n\nexport interface CoercionInfo {\n readonly from: string;\n readonly name: string;\n readonly span: Span;\n readonly to: string;\n}\n\nexport type NotationInfo =\n | {\n readonly form: \"general\";\n /** The notation statement's own binders, which its variables name. */\n readonly binders: readonly Binder[];\n readonly literals: readonly NotationLiteral[];\n readonly span: Span;\n readonly term: string;\n }\n | {\n readonly form: \"simple\";\n readonly fixity: \"infixl\" | \"infixr\" | \"prefix\";\n readonly prec: Precedence;\n readonly span: Span;\n readonly term: string;\n readonly token: string;\n };\n\nexport interface Spec {\n readonly coercions: readonly CoercionInfo[];\n /**\n * The theory's own `delimiter` statement — how the *engine* cuts up math\n * strings. Single bytes, because that is all the engine's table holds.\n */\n readonly delimiters: DelimiterSet;\n readonly display: {\n readonly dropOuterParens: boolean;\n readonly rotateBrackets: readonly (readonly [string, string])[] | null;\n };\n /** Always starts with the built-in `(\"(\", \")\")` pair. */\n readonly groupingPairs: readonly (readonly [string, string])[];\n readonly lints: readonly LintName[];\n /** In declaration order; the last notation for a term is canonical. */\n readonly notations: readonly NotationInfo[];\n readonly elabRules: readonly ElabRule[];\n readonly sorts: ReadonlyMap<string, SortInfo>;\n /** Every statement, in order, annotations intact — full fidelity. */\n readonly statements: readonly Statement[];\n /**\n * How *student* input is cut up: `delimiters` unioned with every\n * `@syntax delimiter` the spec declares. A spec that declares none gets\n * the theory's set unchanged — so writing textbook notation tight\n * (`~~P`, `Fxy`) is an explicit opt-in, never something a spec acquires\n * by accident.\n */\n readonly surfaceDelimiters: DelimiterSet;\n readonly terms: ReadonlyMap<string, TermInfo>;\n}\n\nexport interface SpecParse {\n readonly diagnostics: readonly Diagnostic[];\n readonly spec: Spec;\n}\n\nconst TEMPLATES: Record<string, string> = {\n duplicate_declaration: \"{name} is already declared\",\n unknown_sort: \"sort {name} is not declared\",\n unknown_term: \"term {name} is not declared\",\n infix_arity: \"an infix operator needs exactly two regular arguments\",\n unknown_notation_variable:\n \"notation variable {name} is not one of the declaration's binders\",\n token_conflict:\n \"token {token} already has a meaning; a token may carry one parse rule\",\n precedence_mixed_associativity:\n \"precedence {prec} mixes infixl and infixr operators\",\n grouping_token_conflict:\n \"{token} is a grouping bracket and cannot also be a notation token\",\n elab_duplicate_capture: \"capture {name} appears twice in the pattern\",\n elab_unknown_reference:\n \"the template references {name}, which the pattern does not capture\",\n elab_not_invertible:\n \"capture {name} is not used exactly once in the template; mark the rule input-only if that is intended\",\n elab_literal_split:\n \"the literal {literal} is not one chunk — the delimiters read it as {chunks}; write those as separate elements\",\n elab_literal_looks_like_capture:\n \"the literal {literal} contains ?; a capture is its own element, so write it with spaces around it\",\n juxtaposed_target:\n \"@syntax juxtaposed must sit on a binary term whose arguments and result share one sort\",\n juxtaposed_needs_notation:\n \"a juxtaposed term needs an infix notation — adjacency inherits its precedence, and the engine cannot read invisibility\",\n juxtaposed_duplicate: \"sort {sort} already has a juxtaposed combiner\",\n elided_target: \"@syntax elided must sit on a term with no arguments\",\n refusal_target:\n \"@syntax forbid must sit on a two-place term with an infix notation\",\n elided_duplicate: \"sort {sort} already has an elided term\",\n vars_term_conflict:\n \"@vars token {token} is also a declared term; a name can be only one\",\n role_target: \"@syntax role must sit on a sort or a term\",\n delimiter_unknown:\n \"delimiter {token} is neither a notation token, a bracket, nor a lexicon name, so no input can ever be read as it\",\n delimiter_token_not_delimited:\n \"{token} is not a surface delimiter; it is only read when whitespace or a delimiter bounds it, so it will run into an adjacent token\",\n delimiter_unreachable_name:\n \"the delimiters split {name} into {chunks}, so it can never be read as one name\",\n};\n\nfunction report(\n diagnostics: Diagnostic[],\n id: string,\n params: Record<string, string>,\n span: Span,\n severity: Severity = \"error\",\n): void {\n diagnostics.push(\n diagnostic(id, TEMPLATES[id] ?? id, params, span, severity),\n );\n}\n\n/** The binder count an application must fill (bound and regular alike). */\nfunction regularBinders(binders: readonly Binder[]): readonly Binder[] {\n return binders.filter((binder) => !binder.binds);\n}\n\nfunction binderSortOf(binder: Binder): string {\n return \"sort\" in binder.type ? binder.type.sort : \"\";\n}\n\ninterface TokenMeaning {\n readonly key: string;\n readonly term: string;\n}\n\n/**\n * One line per parse rule a token can carry. Two identical lines are a\n * pointless duplicate but not an ambiguity; anything else sharing a token\n * is a conflict.\n */\nfunction meaningOf(notation: NotationInfo): TokenMeaning | null {\n if (notation.form === \"simple\") {\n return {\n key: `${notation.fixity}:${String(notation.prec)}`,\n term: notation.term,\n };\n }\n\n const first = notation.literals[0];\n\n if (first === undefined || first.kind !== \"constant\") {\n return null;\n }\n\n return { key: \"general\", term: notation.term };\n}\n\n/** Where each notation constant was declared, for pointing a diagnostic. */\nfunction tokenSpans(spec: Spec): Map<string, Span> {\n const spans = new Map<string, Span>();\n\n for (const notation of spec.notations) {\n const constants =\n notation.form === \"simple\"\n ? [notation.token]\n : notation.literals\n .filter((literal) => literal.kind === \"constant\")\n .map((literal) => literal.token);\n\n for (const token of constants) {\n if (!spans.has(token)) {\n spans.set(token, notation.span);\n }\n }\n }\n\n return spans;\n}\n\n/**\n * The surface delimiter set, checked against the vocabulary it has to cut\n * up. Only runs when the spec declares `@syntax delimiter`: a spec that\n * declares none is read under the theory's own delimiters, where tokens\n * are whitespace-separated and none of this can bite.\n */\nfunction checkSurfaceDelimiters(\n spec: Spec,\n declarations: readonly { entries: readonly string[]; span: Span }[],\n diagnostics: Diagnostic[],\n): void {\n const fallback = declarations[0]?.span;\n\n if (fallback === undefined) {\n return;\n }\n\n const vocabulary = surfaceVocabulary(spec);\n const rules = delimiterRules(spec.surfaceDelimiters);\n const declared = new Set([\n ...spec.surfaceDelimiters.left,\n ...spec.surfaceDelimiters.right,\n ]);\n\n // A delimiter nothing can be classified as cuts input into pieces the\n // parser must then reject — a boundary with no meaning behind it.\n for (const { entries, span } of declarations) {\n for (const entry of entries) {\n if (!vocabulary.tokens.has(entry) && !vocabulary.names.has(entry)) {\n report(diagnostics, \"delimiter_unknown\", { token: entry }, span);\n }\n }\n }\n\n // A token that is not itself a delimiter still reads when whitespace or a\n // delimiter bounds it — `P->Q` is fine with the letters declared — so this\n // is advice, not breakage. What it warns about is two such tokens\n // meeting: `->~` is one chunk unless one of them delimits.\n const spans = tokenSpans(spec);\n\n for (const token of vocabulary.tokens) {\n if (!declared.has(token)) {\n report(\n diagnostics,\n \"delimiter_token_not_delimited\",\n { token },\n spans.get(token) ?? fallback,\n \"warning\",\n );\n }\n }\n\n // A name the delimiters split apart is unreachable: segmentation happens\n // before anything knows the name exists, so no bracketing recovers it.\n // Elided terms are exempt — they are supplied by the parser and dropped\n // by the printer, never typed.\n for (const [name, ref] of vocabulary.names) {\n if (ref.kind === \"term\" && spec.terms.get(ref.term)?.elided === true) {\n continue;\n }\n\n if (isReachableChunk(name, rules)) {\n continue;\n }\n\n const span =\n ref.kind === \"term\"\n ? spec.terms.get(ref.term)?.span\n : spec.sorts.get(ref.sort)?.span;\n\n report(\n diagnostics,\n \"delimiter_unreachable_name\",\n { chunks: segment(name, rules).join(\" \"), name },\n span ?? fallback,\n );\n }\n}\n\n/**\n * Elab literals against the delimiters that will cut up the text they have\n * to match. A literal need not be declared vocabulary — that is the point\n * of the layer — but it is matched one chunk at a time, so a literal the\n * delimiters split can never match anything, and a rule that quietly does\n * nothing is the failure this reader exists to prevent.\n *\n * Template literals are checked too, for every rule that is not\n * `input-only`: delaboration runs the rule inverted, where the template's\n * literals *are* the pattern.\n */\nfunction checkElabLiterals(spec: Spec, diagnostics: Diagnostic[]): void {\n const rules = delimiterRules(spec.surfaceDelimiters);\n\n const check = (token: string, span: Span): void => {\n // `parsePattern` splits on whitespace, so `(?x:var)` arrives as one\n // literal rather than three elements. It would trip the split check\n // below as well, but this names the actual mistake.\n if (token.includes(\"?\")) {\n report(\n diagnostics,\n \"elab_literal_looks_like_capture\",\n { literal: token },\n span,\n );\n return;\n }\n\n if (!isReachableChunk(token, rules)) {\n report(\n diagnostics,\n \"elab_literal_split\",\n { chunks: segment(token, rules).join(\" \"), literal: token },\n span,\n );\n }\n };\n\n for (const rule of spec.elabRules) {\n for (const element of rule.pattern) {\n if (element.kind === \"literal\") {\n check(element.token, rule.span);\n }\n }\n\n if (rule.inputOnly) {\n continue;\n }\n\n for (const element of rule.template) {\n if (element.kind === \"literal\") {\n check(element.token, rule.span);\n }\n }\n }\n}\n\nexport function parseSpec(source: string): SpecParse {\n const { statements, diagnostics: parseDiagnostics } =\n parseStatements(source);\n const diagnostics: Diagnostic[] = [...parseDiagnostics];\n\n const sorts = new Map<string, SortInfo>();\n const terms = new Map<string, TermInfo>();\n const coercions: CoercionInfo[] = [];\n const notations: NotationInfo[] = [];\n const elabRules: ElabRule[] = [];\n const lints: LintName[] = [];\n const delimitersLeft = new Set<string>();\n const delimitersRight = new Set<string>();\n const surfaceLeft = new Set<string>();\n const surfaceRight = new Set<string>();\n const surfaceDeclarations: {\n readonly entries: readonly string[];\n readonly span: Span;\n }[] = [];\n const groupingPairs: (readonly [string, string])[] = [[\"(\", \")\"]];\n let dropOuterParens = false;\n let rotateBrackets: readonly (readonly [string, string])[] | null = null;\n\n // ── First pass: split each statement's annotations, collect declarations.\n\n interface Attached {\n readonly annotation: SyntaxAnnotation;\n readonly span: Span;\n readonly statement: Statement;\n }\n\n const attached: Attached[] = [];\n\n for (const statement of statements) {\n const foreign: Annotation[] = [];\n\n for (const annotation of statement.annotations) {\n const parsed = parseSyntaxAnnotation(annotation.text, annotation.span);\n\n if (parsed === null) {\n foreign.push(annotation);\n continue;\n }\n\n if (parsed.diagnostic !== null) {\n diagnostics.push(parsed.diagnostic);\n continue;\n }\n\n attached.push({\n annotation: parsed.annotation,\n span: annotation.span,\n statement,\n });\n }\n\n switch (statement.kind) {\n case \"sort\": {\n if (sorts.has(statement.name) || terms.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n // The engine's `@vars` pools are this library's variable lexicon\n // too; the lines stay foreign (they are the engine's to keep).\n const vars: string[] = [];\n\n for (const annotation of foreign) {\n const match = /^@vars\\s+(.+)$/.exec(annotation.text.trim());\n\n if (match !== null) {\n vars.push(\n ...(match[1] ?? \"\").split(/\\s+/).filter((w) => w.length > 0),\n );\n }\n }\n\n sorts.set(statement.name, {\n foreignAnnotations: foreign,\n modifiers: statement.modifiers,\n name: statement.name,\n roles: [],\n span: statement.span,\n vars,\n });\n break;\n }\n\n case \"term\":\n case \"def\": {\n if (sorts.has(statement.name) || terms.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n const returnSort =\n statement.kind === \"term\"\n ? (statement.returnChain[statement.returnChain.length - 1]\n ?.sort ?? \"\")\n : statement.returnType.sort;\n\n // Arrow sugar on a term (`a > b > c`) desugars to extra anonymous\n // regular binders so arity means one thing everywhere downstream.\n const extra: Binder[] =\n statement.kind === \"term\"\n ? statement.returnChain.slice(0, -1).map((type) => ({\n binds: false,\n dummy: false,\n name: \"_\",\n span: type.span,\n type,\n }))\n : [];\n\n terms.set(statement.name, {\n binders: [...statement.binders, ...extra],\n elided: false,\n foreignAnnotations: foreign,\n isDef: statement.kind === \"def\",\n juxtaposed: false,\n juxtaposedCompound: false,\n name: statement.name,\n refuses: new Set(),\n returnSort,\n roles: [],\n span: statement.span,\n });\n break;\n }\n\n case \"coercion\": {\n coercions.push({\n from: statement.from,\n name: statement.name,\n span: statement.span,\n to: statement.to,\n });\n break;\n }\n\n case \"delimiter\": {\n for (const ch of statement.left) {\n delimitersLeft.add(ch);\n }\n for (const ch of statement.right) {\n delimitersRight.add(ch);\n }\n break;\n }\n\n case \"simple-notation\": {\n notations.push({\n form: \"simple\",\n fixity: statement.fixity,\n prec: statement.prec,\n span: statement.span,\n term: statement.term,\n token: statement.token,\n });\n break;\n }\n\n case \"notation\": {\n notations.push({\n form: \"general\",\n binders: statement.binders,\n literals: statement.literals,\n span: statement.span,\n term: statement.term,\n });\n\n for (const literal of statement.literals) {\n if (\n literal.kind === \"variable\" &&\n !statement.binders.some((b) => b.name === literal.name)\n ) {\n report(\n diagnostics,\n \"unknown_notation_variable\",\n { name: literal.name },\n literal.span,\n );\n }\n }\n break;\n }\n\n case \"axiom\":\n case \"theorem\":\n break;\n }\n }\n\n // ── Second pass: interpret @syntax annotations now that names resolve.\n\n const juxtaposedBySort = new Map<string, string>();\n const elidedBySort = new Map<string, string>();\n\n for (const { annotation, span, statement } of attached) {\n switch (annotation.kind) {\n case \"juxtaposed\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n const regular =\n info === undefined ? [] : regularBinders(info.binders);\n const sort = info?.returnSort ?? \"\";\n\n if (\n info === undefined ||\n info.binders.length !== 2 ||\n regular.length !== 2 ||\n regular.some((binder) => binderSortOf(binder) !== sort)\n ) {\n report(diagnostics, \"juxtaposed_target\", {}, span);\n break;\n }\n\n // An *infix* notation specifically: adjacency stands in for the\n // written operator, so it needs a precedence and an associativity\n // to inherit — and the engine cannot read invisibility either way.\n if (\n !notations.some(\n (notation) =>\n notation.term === info.name &&\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\",\n )\n ) {\n report(diagnostics, \"juxtaposed_needs_notation\", {}, span);\n break;\n }\n\n if (juxtaposedBySort.has(sort)) {\n report(diagnostics, \"juxtaposed_duplicate\", { sort }, span);\n break;\n }\n\n juxtaposedBySort.set(sort, info.name);\n terms.set(info.name, {\n ...info,\n juxtaposed: true,\n juxtaposedCompound: annotation.compound,\n });\n break;\n }\n\n case \"elided\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n\n if (info === undefined || regularBinders(info.binders).length !== 0) {\n report(diagnostics, \"elided_target\", {}, span);\n break;\n }\n\n if (elidedBySort.has(info.returnSort)) {\n report(\n diagnostics,\n \"elided_duplicate\",\n { sort: info.returnSort },\n span,\n );\n break;\n }\n\n elidedBySort.set(info.returnSort, info.name);\n terms.set(info.name, { ...info, elided: true });\n break;\n }\n\n case \"role\": {\n if (statement.kind === \"sort\") {\n const info = sorts.get(statement.name);\n\n if (info !== undefined) {\n sorts.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n if (statement.kind !== \"term\" && statement.kind !== \"def\") {\n report(diagnostics, \"role_target\", {}, span);\n break;\n }\n\n const info = terms.get(statement.name);\n\n if (info !== undefined) {\n terms.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n case \"brackets\": {\n for (const pair of annotation.pairs) {\n const exists = groupingPairs.some(\n ([open, close]) => open === pair[0] && close === pair[1],\n );\n\n if (!exists) {\n groupingPairs.push(pair);\n }\n }\n break;\n }\n\n case \"delimiter\": {\n for (const entry of annotation.left) {\n surfaceLeft.add(entry);\n }\n\n for (const entry of annotation.right) {\n surfaceRight.add(entry);\n }\n\n surfaceDeclarations.push({\n entries: [...new Set([...annotation.left, ...annotation.right])],\n span,\n });\n break;\n }\n\n case \"forbid\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n\n // Only an infix two-place term can *have* an unbracketed connective\n // operand, so anywhere else the annotation would sit and do nothing.\n if (\n info === undefined ||\n regularBinders(info.binders).length !== 2 ||\n !notations.some(\n (notation) =>\n notation.term === info.name &&\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\",\n )\n ) {\n report(diagnostics, \"refusal_target\", {}, span);\n break;\n }\n\n terms.set(info.name, {\n ...info,\n refuses: new Set([...info.refuses, ...annotation.relations]),\n });\n break;\n }\n\n case \"lint\": {\n if (!lints.includes(annotation.name)) {\n lints.push(annotation.name);\n }\n break;\n }\n\n case \"display-drop-outer-parens\": {\n dropOuterParens = true;\n break;\n }\n\n case \"display-rotate-brackets\": {\n rotateBrackets = annotation.pairs;\n break;\n }\n\n case \"elab\": {\n elabRules.push(annotation.rule);\n break;\n }\n }\n }\n\n // ── Validation over the collected spec.\n\n for (const info of terms.values()) {\n for (const binder of info.binders) {\n if (\"sort\" in binder.type && !sorts.has(binder.type.sort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: binder.type.sort },\n binder.type.span,\n );\n }\n }\n\n if (info.returnSort !== \"\" && !sorts.has(info.returnSort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: info.returnSort },\n info.span,\n );\n }\n }\n\n for (const sort of sorts.values()) {\n for (const token of sort.vars) {\n if (terms.has(token)) {\n report(diagnostics, \"vars_term_conflict\", { token }, sort.span);\n }\n }\n }\n\n for (const coercion of coercions) {\n if (!terms.has(coercion.name)) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: coercion.name },\n coercion.span,\n );\n }\n for (const sort of [coercion.from, coercion.to]) {\n if (!sorts.has(sort)) {\n report(diagnostics, \"unknown_sort\", { name: sort }, coercion.span);\n }\n }\n }\n\n const tokenMeanings = new Map<string, { key: string; term: string }>();\n\n for (const notation of notations) {\n const info = terms.get(notation.term);\n\n if (info === undefined) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: notation.term },\n notation.span,\n );\n continue;\n }\n\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n (regularBinders(info.binders).length !== 2 ||\n info.binders.some((b) => b.binds))\n ) {\n report(diagnostics, \"infix_arity\", {}, notation.span);\n }\n\n const token =\n notation.form === \"simple\"\n ? notation.token\n : notation.literals[0]?.kind === \"constant\"\n ? notation.literals[0].token\n : null;\n const meaning = meaningOf(notation);\n\n if (token === null || meaning === null) {\n continue;\n }\n\n const existing = tokenMeanings.get(token);\n\n if (existing !== undefined) {\n if (existing.key !== meaning.key || existing.term !== meaning.term) {\n report(diagnostics, \"token_conflict\", { token }, notation.span);\n }\n continue;\n }\n\n tokenMeanings.set(token, meaning);\n }\n\n const precFixities = new Map<number, Set<\"infixl\" | \"infixr\">>();\n\n for (const notation of notations) {\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n typeof notation.prec === \"number\"\n ) {\n const set = precFixities.get(notation.prec) ?? new Set();\n set.add(notation.fixity);\n precFixities.set(notation.prec, set);\n\n if (set.size > 1) {\n report(\n diagnostics,\n \"precedence_mixed_associativity\",\n { prec: String(notation.prec) },\n notation.span,\n );\n }\n }\n }\n\n for (const [open, close] of groupingPairs) {\n for (const token of [open, close]) {\n if (tokenMeanings.has(token)) {\n report(\n diagnostics,\n \"grouping_token_conflict\",\n { token },\n {\n start: 0,\n end: 0,\n },\n );\n }\n }\n }\n\n for (const rule of elabRules) {\n const captures = new Map<string, number>();\n\n for (const element of rule.pattern) {\n if (element.kind === \"capture\") {\n if (captures.has(element.name)) {\n report(\n diagnostics,\n \"elab_duplicate_capture\",\n { name: element.name },\n rule.span,\n );\n }\n captures.set(element.name, 0);\n }\n }\n\n for (const element of rule.template) {\n if (element.kind === \"reference\") {\n const count = captures.get(element.name);\n\n if (count === undefined) {\n report(\n diagnostics,\n \"elab_unknown_reference\",\n { name: element.name },\n rule.span,\n );\n continue;\n }\n\n captures.set(element.name, count + 1);\n }\n }\n\n if (!rule.inputOnly) {\n for (const [name, count] of captures) {\n if (count !== 1) {\n report(diagnostics, \"elab_not_invertible\", { name }, rule.span);\n }\n }\n }\n }\n\n const spec: Spec = {\n coercions,\n delimiters: { left: delimitersLeft, right: delimitersRight },\n display: { dropOuterParens, rotateBrackets },\n groupingPairs,\n lints,\n notations,\n elabRules,\n sorts,\n statements,\n // The union: what the engine splits on, plus what the textbook does.\n surfaceDelimiters: {\n left: new Set([...delimitersLeft, ...surfaceLeft]),\n right: new Set([...delimitersRight, ...surfaceRight]),\n },\n terms,\n };\n\n checkSurfaceDelimiters(spec, surfaceDeclarations, diagnostics);\n checkElabLiterals(spec, diagnostics);\n\n return { diagnostics, spec };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/reader/spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,cAAc,EACd,gBAAgB,EAChB,OAAO,GACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,UAAU,GAGX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAIL,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AA2JzB,MAAM,SAAS,GAA2B;IACxC,qBAAqB,EAAE,4BAA4B;IACnD,YAAY,EAAE,6BAA6B;IAC3C,YAAY,EAAE,6BAA6B;IAC3C,WAAW,EAAE,uDAAuD;IACpE,yBAAyB,EACvB,kEAAkE;IACpE,cAAc,EACZ,uEAAuE;IACzE,8BAA8B,EAC5B,qDAAqD;IACvD,uBAAuB,EACrB,mEAAmE;IACrE,sBAAsB,EAAE,6CAA6C;IACrE,sBAAsB,EACpB,oEAAoE;IACtE,mBAAmB,EACjB,uGAAuG;IACzG,kBAAkB,EAChB,+GAA+G;IACjH,+BAA+B,EAC7B,mGAAmG;IACrG,iBAAiB,EACf,wFAAwF;IAC1F,yBAAyB,EACvB,wHAAwH;IAC1H,oBAAoB,EAAE,+CAA+C;IACrE,aAAa,EAAE,qDAAqD;IACpE,cAAc,EACZ,oEAAoE;IACtE,gBAAgB,EAAE,wCAAwC;IAC1D,kBAAkB,EAChB,qEAAqE;IACvE,WAAW,EAAE,oDAAoD;IACjE,YAAY,EAAE,iDAAiD;IAC/D,kBAAkB,EAChB,iEAAiE;IACnE,eAAe,EAAE,8BAA8B;IAC/C,gBAAgB,EACd,4DAA4D;I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AE,CAAC;gBACrC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;oBAChB,MAAM,CAAC,WAAW,EAAE,qBAAqB,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAS;QACjB,SAAS;QACT,UAAU,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE;QAC5D,OAAO,EAAE,EAAE,eAAe,EAAE,cAAc,EAAE;QAC5C,aAAa;QACb,KAAK;QACL,SAAS;QACT,SAAS;QACT,WAAW;QACX,KAAK;QACL,KAAK;QACL,UAAU;QACV,qEAAqE;QACrE,iBAAiB,EAAE;YACjB,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,WAAW,CAAC,CAAC;YAClD,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,eAAe,EAAE,GAAG,YAAY,CAAC,CAAC;SACtD;QACD,KAAK;KACN,CAAC;IAEF,gBAAgB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACpC,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,EAAE,WAAW,CAAC,CAAC;IAC/D,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAErC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["/**\n * From parsed statements to a `Spec` — the library's central object: the\n * signature, notations, coercions, and `@syntax` surface metadata of one\n * logical system, validated.\n *\n * Validation here is about the spec being *coherent* (token conflicts,\n * dangling names, non-invertible elab rules); whether the theory proves\n * anything is the engine's business, and axiom bodies pass through opaque.\n */\n\nimport {\n type DelimiterSet,\n delimiterRules,\n isReachableChunk,\n segment,\n} from \"../delimiters.js\";\nimport {\n type Diagnostic,\n diagnostic,\n type Severity,\n type Span,\n} from \"../diagnostics.js\";\nimport { nameOnlyTerms, surfaceVocabulary } from \"../vocabulary.js\";\nimport {\n type ElabRule,\n type LintName,\n type OperandRelation,\n parseSyntaxAnnotation,\n type SyntaxAnnotation,\n} from \"./annotations.js\";\nimport {\n type Annotation,\n type Binder,\n type NotationLiteral,\n type Precedence,\n parseStatements,\n type Statement,\n} from \"./statements.js\";\n\nexport interface SortInfo {\n readonly foreignAnnotations: readonly Annotation[];\n readonly modifiers: readonly string[];\n readonly name: string;\n readonly roles: readonly string[];\n readonly span: Span;\n /**\n * The sort's variable tokens, read from the engine's own `@vars`\n * annotation (which stays in `foreignAnnotations` untouched — it is the\n * engine's, we only listen in). These are the surface lexicon's\n * identifiers of this sort; whether a quantifier can bind them falls\n * out of the quantifiers' binder sorts, not from here.\n */\n readonly vars: readonly string[];\n}\n\nexport interface TermInfo {\n readonly binders: readonly Binder[];\n /** `@syntax elided`: supplied when an argument of its sort is missing. */\n readonly elided: boolean;\n readonly foreignAnnotations: readonly Annotation[];\n /** True when this came from a `def` rather than a `term`. */\n readonly isDef: boolean;\n /**\n * A def's body: its definiens as engine text, over `binders` and its own\n * dot-dummies. Null for a `term`, and for a def whose definiens the proof\n * file supplies. `unfoldDefinitions` reads it.\n */\n readonly definition: Definition | null;\n /** `@syntax juxtaposed`: adjacency of its sort's leaves denotes it. */\n readonly juxtaposed: boolean;\n /**\n * `@syntax juxtaposed compound`: a parenthesized group may stand as a\n * glue operand in argument position, not just a single token. False\n * whenever `juxtaposed` is.\n */\n readonly juxtaposedCompound: boolean;\n readonly name: string;\n /**\n * `@syntax forbid`: the unbracketed connective operands this term\n * refuses. Empty — the default — permits all three.\n * See {@link OperandRelation} for what each one names.\n */\n readonly refuses: ReadonlySet<OperandRelation>;\n readonly returnSort: string;\n readonly roles: readonly string[];\n readonly span: Span;\n}\n\n/** A def's definiens and the dot-dummies it binds. */\nexport interface Definition {\n readonly dummies: readonly Binder[];\n readonly text: string;\n}\n\nexport interface CoercionInfo {\n readonly from: string;\n readonly name: string;\n readonly span: Span;\n readonly to: string;\n}\n\n/**\n * An axiom or theorem, as far as the surface layer is concerned: a name a\n * proof cites, the `@syntax alias` names it may cite it by instead, and the\n * `@syntax role`s that say what it is for. The statement itself passes\n * through opaque, on `Spec.statements`.\n */\nexport interface RuleInfo {\n /** In declaration order; never contains the rule's own name. */\n readonly aliases: readonly string[];\n /**\n * The rule the engine retries this one with when it fails to apply, read\n * from the engine's own `@fallback` annotation (which stays in\n * `foreignAnnotations` — it is the engine's, we only listen in). Always an\n * earlier rule, so following the chain ends; `null` without one.\n */\n readonly fallback: string | null;\n readonly foreignAnnotations: readonly Annotation[];\n readonly kind: \"axiom\" | \"theorem\";\n readonly name: string;\n /**\n * `@syntax role`: what this rule *is* to a consumer — a proof editor\n * looks for `assumption` to tell the lines that open a hypothesis from\n * the ones that cite a rule. Uninterpreted here, like a term's roles.\n */\n readonly roles: readonly string[];\n readonly span: Span;\n}\n\nexport type NotationInfo =\n | {\n readonly form: \"general\";\n /** The notation statement's own binders, which its variables name. */\n readonly binders: readonly Binder[];\n readonly literals: readonly NotationLiteral[];\n readonly span: Span;\n readonly term: string;\n }\n | {\n readonly form: \"simple\";\n readonly fixity: \"infixl\" | \"infixr\" | \"prefix\";\n readonly prec: Precedence;\n readonly span: Span;\n readonly term: string;\n readonly token: string;\n };\n\nexport interface Spec {\n readonly coercions: readonly CoercionInfo[];\n /**\n * The theory's own `delimiter` statement — how the *engine* cuts up math\n * strings. Single bytes, because that is all the engine's table holds.\n */\n readonly delimiters: DelimiterSet;\n readonly display: {\n readonly dropOuterParens: boolean;\n readonly rotateBrackets: readonly (readonly [string, string])[] | null;\n };\n /** Always starts with the built-in `(\"(\", \")\")` pair. */\n readonly groupingPairs: readonly (readonly [string, string])[];\n readonly lints: readonly LintName[];\n /** In declaration order; the last notation for a term is canonical. */\n readonly notations: readonly NotationInfo[];\n readonly elabRules: readonly ElabRule[];\n /**\n * Alias to the rule it names, over every `@syntax alias` in the spec —\n * the one lookup a proof reader needs: `ruleAliases.get(cited) ?? cited`\n * is what to hand the engine. Canonical names are not keys; a name that\n * is not an alias is already the engine's.\n */\n readonly ruleAliases: ReadonlyMap<string, string>;\n /** Every axiom and theorem, keyed by name. */\n readonly rules: ReadonlyMap<string, RuleInfo>;\n readonly sorts: ReadonlyMap<string, SortInfo>;\n /** Every statement, in order, annotations intact — full fidelity. */\n readonly statements: readonly Statement[];\n /**\n * How *student* input is cut up: `delimiters` unioned with every\n * `@syntax delimiter` the spec declares. A spec that declares none gets\n * the theory's set unchanged — so writing textbook notation tight\n * (`~~P`, `Fxy`) is an explicit opt-in, never something a spec acquires\n * by accident.\n */\n readonly surfaceDelimiters: DelimiterSet;\n readonly terms: ReadonlyMap<string, TermInfo>;\n}\n\nexport interface SpecParse {\n readonly diagnostics: readonly Diagnostic[];\n readonly spec: Spec;\n}\n\nconst TEMPLATES: Record<string, string> = {\n duplicate_declaration: \"{name} is already declared\",\n unknown_sort: \"sort {name} is not declared\",\n unknown_term: \"term {name} is not declared\",\n infix_arity: \"an infix operator needs exactly two regular arguments\",\n unknown_notation_variable:\n \"notation variable {name} is not one of the declaration's binders\",\n token_conflict:\n \"token {token} already has a meaning; a token may carry one parse rule\",\n precedence_mixed_associativity:\n \"precedence {prec} mixes infixl and infixr operators\",\n grouping_token_conflict:\n \"{token} is a grouping bracket and cannot also be a notation token\",\n elab_duplicate_capture: \"capture {name} appears twice in the pattern\",\n elab_unknown_reference:\n \"the template references {name}, which the pattern does not capture\",\n elab_not_invertible:\n \"capture {name} is not used exactly once in the template; mark the rule input-only if that is intended\",\n elab_literal_split:\n \"the literal {literal} is not one chunk — the delimiters read it as {chunks}; write those as separate elements\",\n elab_literal_looks_like_capture:\n \"the literal {literal} contains ?; a capture is its own element, so write it with spaces around it\",\n juxtaposed_target:\n \"@syntax juxtaposed must sit on a binary term whose arguments and result share one sort\",\n juxtaposed_needs_notation:\n \"a juxtaposed term needs an infix notation — adjacency inherits its precedence, and the engine cannot read invisibility\",\n juxtaposed_duplicate: \"sort {sort} already has a juxtaposed combiner\",\n elided_target: \"@syntax elided must sit on a term with no arguments\",\n refusal_target:\n \"@syntax forbid must sit on a two-place term with an infix notation\",\n elided_duplicate: \"sort {sort} already has an elided term\",\n vars_term_conflict:\n \"@vars token {token} is also a declared term; a name can be only one\",\n role_target: \"@syntax role must sit on a sort, a term, or a rule\",\n alias_target: \"@syntax alias must sit on an axiom or a theorem\",\n alias_is_rule_name:\n \"{alias} is already the name of a rule, so it cannot be an alias\",\n alias_duplicate: \"{alias} already names {rule}\",\n fallback_unknown:\n \"@fallback {rule} does not name an earlier axiom or theorem\",\n fallback_duplicate: \"a rule may carry only one @fallback\",\n delimiter_unknown:\n \"delimiter {token} is neither a notation token, a bracket, a lexicon name, nor an elab literal, so no input can ever be read as it\",\n delimiter_token_not_delimited:\n \"{token} is not a surface delimiter; it is only read when whitespace or a delimiter bounds it, so it will run into an adjacent token\",\n delimiter_unreachable_name:\n \"the delimiters split {name} into {chunks}, so it can never be read as one name\",\n delimiter_splits_token:\n \"the delimiters split the notation token {token} into {chunks}, so it can never be read; mm0.md requires a token not to contain a delimiter\",\n};\n\nfunction report(\n diagnostics: Diagnostic[],\n id: string,\n params: Record<string, string>,\n span: Span,\n severity: Severity = \"error\",\n): void {\n diagnostics.push(\n diagnostic(id, TEMPLATES[id] ?? id, params, span, severity),\n );\n}\n\n/** The binder count an application must fill (bound and regular alike). */\nfunction regularBinders(binders: readonly Binder[]): readonly Binder[] {\n return binders.filter((binder) => !binder.binds);\n}\n\nfunction binderSortOf(binder: Binder): string {\n return \"sort\" in binder.type ? binder.type.sort : \"\";\n}\n\ninterface TokenMeaning {\n readonly key: string;\n readonly term: string;\n}\n\n/**\n * One line per parse rule a token can carry. Two identical lines are a\n * pointless duplicate but not an ambiguity; anything else sharing a token\n * is a conflict.\n */\nfunction meaningOf(notation: NotationInfo): TokenMeaning | null {\n if (notation.form === \"simple\") {\n return {\n key: `${notation.fixity}:${String(notation.prec)}`,\n term: notation.term,\n };\n }\n\n const first = notation.literals[0];\n\n if (first === undefined || first.kind !== \"constant\") {\n return null;\n }\n\n return { key: \"general\", term: notation.term };\n}\n\n/** Where each notation constant was declared, for pointing a diagnostic. */\nfunction tokenSpans(spec: Spec): Map<string, Span> {\n const spans = new Map<string, Span>();\n\n for (const notation of spec.notations) {\n const constants =\n notation.form === \"simple\"\n ? [notation.token]\n : notation.literals\n .filter((literal) => literal.kind === \"constant\")\n .map((literal) => literal.token);\n\n for (const token of constants) {\n if (!spans.has(token)) {\n spans.set(token, notation.span);\n }\n }\n }\n\n return spans;\n}\n\n/**\n * A notation token a delimiter cuts through is dead: mm0.md forbids it\n * outright (\"a declared token must not contain a delimiter token as a\n * substring\"), the engine cannot read it either, and the printer never\n * picks it as a spelling. A warning rather than an error, since the\n * engine tolerates the declaration — `/\\\\` beside `∧` in a file whose\n * `[x/t]` makes `/` a delimiter — and so does everything here.\n */\nfunction reportDeadTokens(spec: Spec, diagnostics: Diagnostic[]): void {\n // The theory's own delimiters, not the surface set: a token the surface\n // letters split (`tsub` under forallx) is an engine-only notation, and\n // `delimiter_token_not_delimited` already says so.\n const rules = delimiterRules(spec.delimiters);\n const spans = tokenSpans(spec);\n\n for (const token of surfaceVocabulary(spec).tokens) {\n const span = spans.get(token);\n\n if (span === undefined || isReachableChunk(token, rules)) {\n continue;\n }\n\n report(\n diagnostics,\n \"delimiter_splits_token\",\n { chunks: segment(token, rules).join(\" \"), token },\n span,\n \"warning\",\n );\n }\n}\n\n/**\n * The surface delimiter set, checked against the vocabulary it has to cut\n * up. Only runs when the spec declares `@syntax delimiter`: a spec that\n * declares none is read under the theory's own delimiters, where tokens\n * are whitespace-separated and none of this can bite.\n */\nfunction checkSurfaceDelimiters(\n spec: Spec,\n declarations: readonly { entries: readonly string[]; span: Span }[],\n diagnostics: Diagnostic[],\n): void {\n const fallback = declarations[0]?.span;\n\n if (fallback === undefined) {\n return;\n }\n\n const vocabulary = surfaceVocabulary(spec);\n const rules = delimiterRules(spec.surfaceDelimiters);\n const declared = new Set([\n ...spec.surfaceDelimiters.left,\n ...spec.surfaceDelimiters.right,\n ]);\n\n // A delimiter nothing can be classified as cuts input into pieces the\n // parser must then reject — a boundary with no meaning behind it. An elab\n // literal is a meaning: the layer reads that chunk before the parser does,\n // and a delimiter is the only way to give it its own chunk when it is\n // glued to a name (`x'`).\n const literals = new Set(\n [...matchedLiterals(spec)].map(({ token }) => token),\n );\n\n for (const { entries, span } of declarations) {\n for (const entry of entries) {\n if (\n !vocabulary.tokens.has(entry) &&\n !vocabulary.names.has(entry) &&\n !literals.has(entry)\n ) {\n report(diagnostics, \"delimiter_unknown\", { token: entry }, span);\n }\n }\n }\n\n // A token that is not itself a delimiter still reads when whitespace or a\n // delimiter bounds it — `P->Q` is fine with the letters declared — so this\n // is advice, not breakage. What it warns about is two such tokens\n // meeting: `->~` is one chunk unless one of them delimits.\n const spans = tokenSpans(spec);\n\n for (const token of vocabulary.tokens) {\n if (!declared.has(token)) {\n report(\n diagnostics,\n \"delimiter_token_not_delimited\",\n { token },\n spans.get(token) ?? fallback,\n \"warning\",\n );\n }\n }\n\n // A name the delimiters split apart is unreachable: segmentation happens\n // before anything knows the name exists, so no bracketing recovers it.\n // Only a term with no other spelling is at stake; a notated term's name\n // is MM0's application syntax, still reachable under the engine's own\n // delimiters. Elided terms are exempt — they are supplied by the parser\n // and dropped by the printer, never typed.\n const nameOnly = nameOnlyTerms(spec);\n\n for (const [name, ref] of vocabulary.names) {\n if (\n ref.kind === \"term\" &&\n (spec.terms.get(ref.term)?.elided === true || !nameOnly.has(ref.term))\n ) {\n continue;\n }\n\n if (isReachableChunk(name, rules)) {\n continue;\n }\n\n const span =\n ref.kind === \"term\"\n ? spec.terms.get(ref.term)?.span\n : spec.sorts.get(ref.sort)?.span;\n\n report(\n diagnostics,\n \"delimiter_unreachable_name\",\n { chunks: segment(name, rules).join(\" \"), name },\n span ?? fallback,\n );\n }\n}\n\n/**\n * Elab literals against the delimiters that will cut up the text they have\n * to match. A literal need not be declared vocabulary — that is the point\n * of the layer — but it is matched one chunk at a time, so a literal the\n * delimiters split can never match anything, and a rule that quietly does\n * nothing is the failure this reader exists to prevent.\n */\nfunction checkElabLiterals(spec: Spec, diagnostics: Diagnostic[]): void {\n const rules = delimiterRules(spec.surfaceDelimiters);\n\n const check = (token: string, span: Span): void => {\n // `parsePattern` splits on whitespace, so `(?x:var)` arrives as one\n // literal rather than three elements. It would trip the split check\n // below as well, but this names the actual mistake.\n if (token.includes(\"?\")) {\n report(\n diagnostics,\n \"elab_literal_looks_like_capture\",\n { literal: token },\n span,\n );\n return;\n }\n\n if (!isReachableChunk(token, rules)) {\n report(\n diagnostics,\n \"elab_literal_split\",\n { chunks: segment(token, rules).join(\" \"), literal: token },\n span,\n );\n }\n };\n\n for (const { token, span } of matchedLiterals(spec)) {\n check(token, span);\n }\n}\n\n/**\n * Every elab literal some direction matches against text: each rule's\n * pattern literals, and the template literals of every rule that is not\n * `input-only`, since delaboration runs the rule inverted, where the\n * template's literals *are* the pattern.\n */\nfunction* matchedLiterals(\n spec: Spec,\n): Generator<{ readonly token: string; readonly span: Span }> {\n for (const rule of spec.elabRules) {\n const elements = rule.inputOnly\n ? rule.pattern\n : [...rule.pattern, ...rule.template];\n\n for (const element of elements) {\n if (element.kind === \"literal\") {\n yield { token: element.token, span: rule.span };\n }\n }\n }\n}\n\nexport function parseSpec(source: string): SpecParse {\n const { statements, diagnostics: parseDiagnostics } =\n parseStatements(source);\n const diagnostics: Diagnostic[] = [...parseDiagnostics];\n\n const sorts = new Map<string, SortInfo>();\n const terms = new Map<string, TermInfo>();\n const coercions: CoercionInfo[] = [];\n const rules = new Map<string, RuleInfo>();\n const ruleAliases = new Map<string, string>();\n const notations: NotationInfo[] = [];\n const elabRules: ElabRule[] = [];\n const lints: LintName[] = [];\n const delimitersLeft = new Set<string>();\n const delimitersRight = new Set<string>();\n const surfaceLeft = new Set<string>();\n const surfaceRight = new Set<string>();\n const surfaceDeclarations: {\n readonly entries: readonly string[];\n readonly span: Span;\n }[] = [];\n const groupingPairs: (readonly [string, string])[] = [[\"(\", \")\"]];\n let dropOuterParens = false;\n let rotateBrackets: readonly (readonly [string, string])[] | null = null;\n\n // ── First pass: split each statement's annotations, collect declarations.\n\n interface Attached {\n readonly annotation: SyntaxAnnotation;\n readonly span: Span;\n readonly statement: Statement;\n }\n\n const attached: Attached[] = [];\n\n for (const statement of statements) {\n const foreign: Annotation[] = [];\n\n for (const annotation of statement.annotations) {\n const parsed = parseSyntaxAnnotation(annotation.text, annotation.span);\n\n if (parsed === null) {\n foreign.push(annotation);\n continue;\n }\n\n if (parsed.diagnostic !== null) {\n diagnostics.push(parsed.diagnostic);\n continue;\n }\n\n attached.push({\n annotation: parsed.annotation,\n span: annotation.span,\n statement,\n });\n }\n\n switch (statement.kind) {\n case \"sort\": {\n // Sorts and terms are separate namespaces (peano.mm0 declares a\n // sort `nat` and a def `nat`); each name may be declared once\n // within its own.\n if (sorts.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n // The engine's `@vars` pools are this library's variable lexicon\n // too; the lines stay foreign (they are the engine's to keep).\n const vars: string[] = [];\n\n for (const annotation of foreign) {\n const match = /^@vars\\s+(.+)$/.exec(annotation.text.trim());\n\n if (match !== null) {\n vars.push(\n ...(match[1] ?? \"\").split(/\\s+/).filter((w) => w.length > 0),\n );\n }\n }\n\n sorts.set(statement.name, {\n foreignAnnotations: foreign,\n modifiers: statement.modifiers,\n name: statement.name,\n roles: [],\n span: statement.span,\n vars,\n });\n break;\n }\n\n case \"term\":\n case \"def\": {\n if (terms.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n const returnSort =\n statement.returnChain[statement.returnChain.length - 1]?.sort ?? \"\";\n\n // Arrow sugar (`a > b > c`) desugars to extra anonymous regular\n // binders so arity means one thing everywhere downstream. A\n // def's dot-dummies go the other way: they are variables of the\n // definiens, never arguments, so they are no part of the\n // syntax.\n const extra: Binder[] = statement.returnChain\n .slice(0, -1)\n .map((type) => ({\n binds: false,\n dummy: false,\n name: \"_\",\n span: type.span,\n type,\n }));\n const arguments_ = statement.binders.filter(\n (binder) => !binder.dummy,\n );\n\n terms.set(statement.name, {\n binders: [...arguments_, ...extra],\n elided: false,\n foreignAnnotations: foreign,\n isDef: statement.kind === \"def\",\n definition:\n statement.kind === \"def\" && statement.definiens !== null\n ? {\n dummies: statement.binders.filter((binder) => binder.dummy),\n text: statement.definiens.text,\n }\n : null,\n juxtaposed: false,\n juxtaposedCompound: false,\n name: statement.name,\n refuses: new Set(),\n returnSort,\n roles: [],\n span: statement.span,\n });\n break;\n }\n\n case \"coercion\": {\n coercions.push({\n from: statement.from,\n name: statement.name,\n span: statement.span,\n to: statement.to,\n });\n break;\n }\n\n case \"delimiter\": {\n for (const ch of statement.left) {\n delimitersLeft.add(ch);\n }\n for (const ch of statement.right) {\n delimitersRight.add(ch);\n }\n break;\n }\n\n case \"simple-notation\": {\n notations.push({\n form: \"simple\",\n fixity: statement.fixity,\n prec: statement.prec,\n span: statement.span,\n term: statement.term,\n token: statement.token,\n });\n break;\n }\n\n case \"notation\": {\n notations.push({\n form: \"general\",\n binders: statement.binders,\n literals: statement.literals,\n span: statement.span,\n term: statement.term,\n });\n\n for (const literal of statement.literals) {\n if (\n literal.kind === \"variable\" &&\n !statement.binders.some((b) => b.name === literal.name)\n ) {\n report(\n diagnostics,\n \"unknown_notation_variable\",\n { name: literal.name },\n literal.span,\n );\n }\n }\n break;\n }\n\n case \"axiom\":\n case \"theorem\": {\n // The engine refuses a second declaration of a name; recording it\n // once here keeps the alias table from ever being ambiguous.\n if (rules.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n // The engine's `@fallback` is read like `@vars`: the line stays\n // foreign, and the reader checks what the engine would, so a chain\n // a consumer follows always points backwards and ends.\n let fallback: string | null = null;\n let fallbacks = 0;\n\n for (const annotation of foreign) {\n const [head, target = \"\"] = annotation.text.trim().split(/\\s+/);\n\n if (head !== \"@fallback\") {\n continue;\n }\n\n fallbacks += 1;\n\n if (fallbacks > 1) {\n report(diagnostics, \"fallback_duplicate\", {}, annotation.span);\n continue;\n }\n\n if (rules.has(target)) {\n fallback = target;\n } else {\n report(\n diagnostics,\n \"fallback_unknown\",\n { rule: target },\n annotation.span,\n );\n }\n }\n\n rules.set(statement.name, {\n aliases: [],\n fallback,\n roles: [],\n foreignAnnotations: foreign,\n kind: statement.kind,\n name: statement.name,\n span: statement.span,\n });\n break;\n }\n }\n }\n\n // ── Second pass: interpret @syntax annotations now that names resolve.\n\n const juxtaposedBySort = new Map<string, string>();\n const elidedBySort = new Map<string, string>();\n\n for (const { annotation, span, statement } of attached) {\n switch (annotation.kind) {\n case \"juxtaposed\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n const regular =\n info === undefined ? [] : regularBinders(info.binders);\n const sort = info?.returnSort ?? \"\";\n\n if (\n info === undefined ||\n info.binders.length !== 2 ||\n regular.length !== 2 ||\n regular.some((binder) => binderSortOf(binder) !== sort)\n ) {\n report(diagnostics, \"juxtaposed_target\", {}, span);\n break;\n }\n\n // An *infix* notation specifically: adjacency stands in for the\n // written operator, so it needs a precedence and an associativity\n // to inherit — and the engine cannot read invisibility either way.\n if (\n !notations.some(\n (notation) =>\n notation.term === info.name &&\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\",\n )\n ) {\n report(diagnostics, \"juxtaposed_needs_notation\", {}, span);\n break;\n }\n\n if (juxtaposedBySort.has(sort)) {\n report(diagnostics, \"juxtaposed_duplicate\", { sort }, span);\n break;\n }\n\n juxtaposedBySort.set(sort, info.name);\n terms.set(info.name, {\n ...info,\n juxtaposed: true,\n juxtaposedCompound: annotation.compound,\n });\n break;\n }\n\n case \"elided\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n\n if (info === undefined || regularBinders(info.binders).length !== 0) {\n report(diagnostics, \"elided_target\", {}, span);\n break;\n }\n\n if (elidedBySort.has(info.returnSort)) {\n report(\n diagnostics,\n \"elided_duplicate\",\n { sort: info.returnSort },\n span,\n );\n break;\n }\n\n elidedBySort.set(info.returnSort, info.name);\n terms.set(info.name, { ...info, elided: true });\n break;\n }\n\n case \"role\": {\n if (statement.kind === \"sort\") {\n const info = sorts.get(statement.name);\n\n if (info !== undefined) {\n sorts.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n if (statement.kind === \"axiom\" || statement.kind === \"theorem\") {\n const info = rules.get(statement.name);\n\n if (info !== undefined) {\n rules.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n if (statement.kind !== \"term\" && statement.kind !== \"def\") {\n report(diagnostics, \"role_target\", {}, span);\n break;\n }\n\n const info = terms.get(statement.name);\n\n if (info !== undefined) {\n terms.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n case \"alias\": {\n const info =\n statement.kind === \"axiom\" || statement.kind === \"theorem\"\n ? rules.get(statement.name)\n : undefined;\n\n if (info === undefined) {\n report(diagnostics, \"alias_target\", {}, span);\n break;\n }\n\n for (const alias of annotation.names) {\n // A proof citing this name must mean one rule. The rule's own\n // name is the engine's, and another rule's alias is taken.\n if (rules.has(alias)) {\n report(diagnostics, \"alias_is_rule_name\", { alias }, span);\n continue;\n }\n\n const owner = ruleAliases.get(alias);\n\n if (owner !== undefined) {\n if (owner !== info.name) {\n report(\n diagnostics,\n \"alias_duplicate\",\n { alias, rule: owner },\n span,\n );\n }\n continue;\n }\n\n ruleAliases.set(alias, info.name);\n const current = rules.get(info.name) ?? info;\n rules.set(info.name, {\n ...current,\n aliases: [...current.aliases, alias],\n });\n }\n break;\n }\n\n case \"brackets\": {\n for (const pair of annotation.pairs) {\n const exists = groupingPairs.some(\n ([open, close]) => open === pair[0] && close === pair[1],\n );\n\n if (!exists) {\n groupingPairs.push(pair);\n }\n }\n break;\n }\n\n case \"delimiter\": {\n for (const entry of annotation.left) {\n surfaceLeft.add(entry);\n }\n\n for (const entry of annotation.right) {\n surfaceRight.add(entry);\n }\n\n surfaceDeclarations.push({\n entries: [...new Set([...annotation.left, ...annotation.right])],\n span,\n });\n break;\n }\n\n case \"forbid\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n\n // Only an infix two-place term can *have* an unbracketed connective\n // operand, so anywhere else the annotation would sit and do nothing.\n if (\n info === undefined ||\n regularBinders(info.binders).length !== 2 ||\n !notations.some(\n (notation) =>\n notation.term === info.name &&\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\",\n )\n ) {\n report(diagnostics, \"refusal_target\", {}, span);\n break;\n }\n\n terms.set(info.name, {\n ...info,\n refuses: new Set([...info.refuses, ...annotation.relations]),\n });\n break;\n }\n\n case \"lint\": {\n if (!lints.includes(annotation.name)) {\n lints.push(annotation.name);\n }\n break;\n }\n\n case \"display-drop-outer-parens\": {\n dropOuterParens = true;\n break;\n }\n\n case \"display-rotate-brackets\": {\n rotateBrackets = annotation.pairs;\n break;\n }\n\n case \"elab\": {\n elabRules.push(annotation.rule);\n break;\n }\n }\n }\n\n // ── Validation over the collected spec.\n\n for (const info of terms.values()) {\n for (const binder of info.binders) {\n if (\"sort\" in binder.type && !sorts.has(binder.type.sort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: binder.type.sort },\n binder.type.span,\n );\n }\n }\n\n if (info.returnSort !== \"\" && !sorts.has(info.returnSort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: info.returnSort },\n info.span,\n );\n }\n }\n\n for (const sort of sorts.values()) {\n for (const token of sort.vars) {\n if (terms.has(token)) {\n report(diagnostics, \"vars_term_conflict\", { token }, sort.span);\n }\n }\n }\n\n for (const coercion of coercions) {\n if (!terms.has(coercion.name)) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: coercion.name },\n coercion.span,\n );\n }\n for (const sort of [coercion.from, coercion.to]) {\n if (!sorts.has(sort)) {\n report(diagnostics, \"unknown_sort\", { name: sort }, coercion.span);\n }\n }\n }\n\n const tokenMeanings = new Map<string, { key: string; term: string }>();\n\n for (const notation of notations) {\n const info = terms.get(notation.term);\n\n if (info === undefined) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: notation.term },\n notation.span,\n );\n continue;\n }\n\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n (regularBinders(info.binders).length !== 2 ||\n info.binders.some((b) => b.binds))\n ) {\n report(diagnostics, \"infix_arity\", {}, notation.span);\n }\n\n const token =\n notation.form === \"simple\"\n ? notation.token\n : notation.literals[0]?.kind === \"constant\"\n ? notation.literals[0].token\n : null;\n const meaning = meaningOf(notation);\n\n if (token === null || meaning === null) {\n continue;\n }\n\n const existing = tokenMeanings.get(token);\n\n if (existing !== undefined) {\n if (existing.key !== meaning.key || existing.term !== meaning.term) {\n report(diagnostics, \"token_conflict\", { token }, notation.span);\n }\n continue;\n }\n\n tokenMeanings.set(token, meaning);\n }\n\n const precFixities = new Map<number, Set<\"infixl\" | \"infixr\">>();\n\n for (const notation of notations) {\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n typeof notation.prec === \"number\"\n ) {\n const set = precFixities.get(notation.prec) ?? new Set();\n set.add(notation.fixity);\n precFixities.set(notation.prec, set);\n\n if (set.size > 1) {\n report(\n diagnostics,\n \"precedence_mixed_associativity\",\n { prec: String(notation.prec) },\n notation.span,\n );\n }\n }\n }\n\n for (const [open, close] of groupingPairs) {\n for (const token of [open, close]) {\n if (tokenMeanings.has(token)) {\n report(\n diagnostics,\n \"grouping_token_conflict\",\n { token },\n {\n start: 0,\n end: 0,\n },\n );\n }\n }\n }\n\n for (const rule of elabRules) {\n const captures = new Map<string, number>();\n\n for (const element of rule.pattern) {\n if (element.kind === \"capture\") {\n if (captures.has(element.name)) {\n report(\n diagnostics,\n \"elab_duplicate_capture\",\n { name: element.name },\n rule.span,\n );\n }\n captures.set(element.name, 0);\n }\n }\n\n for (const element of rule.template) {\n if (element.kind === \"reference\") {\n const count = captures.get(element.name);\n\n if (count === undefined) {\n report(\n diagnostics,\n \"elab_unknown_reference\",\n { name: element.name },\n rule.span,\n );\n continue;\n }\n\n captures.set(element.name, count + 1);\n }\n }\n\n if (!rule.inputOnly) {\n for (const [name, count] of captures) {\n if (count !== 1) {\n report(diagnostics, \"elab_not_invertible\", { name }, rule.span);\n }\n }\n }\n }\n\n const spec: Spec = {\n coercions,\n delimiters: { left: delimitersLeft, right: delimitersRight },\n display: { dropOuterParens, rotateBrackets },\n groupingPairs,\n lints,\n notations,\n elabRules,\n ruleAliases,\n rules,\n sorts,\n statements,\n // The union: what the engine splits on, plus what the textbook does.\n surfaceDelimiters: {\n left: new Set([...delimitersLeft, ...surfaceLeft]),\n right: new Set([...delimitersRight, ...surfaceRight]),\n },\n terms,\n };\n\n reportDeadTokens(spec, diagnostics);\n checkSurfaceDelimiters(spec, surfaceDeclarations, diagnostics);\n checkElabLiterals(spec, diagnostics);\n\n return { diagnostics, spec };\n}\n"]}
|