@aufbau/syntax 0.0.1 → 0.0.2

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/dist/parse.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * The surface parser: a faithful port of MM0's operator-precedence math
3
- * parser (mm0.md, "the dynamic parser"), running over the character-level
4
- * scanner instead of MM0's whitespace lexer, with exactly three declared
5
- * extensions beyond the upstream grammar:
3
+ * parser (mm0.md, "the dynamic parser"), running over the delimiter
4
+ * scanner — MM0's own segmentation rule under a wider, declared delimiter
5
+ * set — with exactly three declared extensions beyond the upstream
6
+ * grammar:
6
7
  *
7
8
  * 1. **Grouping pairs** — `expression(max) → open expression(0) close`
8
9
  * for every declared bracket pair, close matching open;
@@ -31,7 +32,7 @@ import { elaborate, remapSpan } from "./elab.js";
31
32
  import { Scanner } from "./scan.js";
32
33
  import { walkTerm } from "./term.js";
33
34
  const TEMPLATES = {
34
- unrecognized_character: "Unexpected character “{character}”.",
35
+ unrecognized_chunk: "“{chunk}” is not part of this language.",
35
36
  expected_formula: "Expected a formula.",
36
37
  expected_formula_found: "Expected a formula but found “{token}”.",
37
38
  unexpected_token: "Unexpected “{token}”.",
@@ -57,7 +58,10 @@ function binderSort(binder) {
57
58
  /** Everything derived from a Spec that parsing needs, built once. */
58
59
  export class SurfaceLanguage {
59
60
  spec;
61
+ /** Student input: the wide surface delimiter set. */
60
62
  scanner;
63
+ /** Engine text: the same vocabulary under the theory's own delimiters. */
64
+ engineScanner;
61
65
  heads = new Map();
62
66
  infixes = new Map();
63
67
  closeOf = new Map();
@@ -76,6 +80,7 @@ export class SurfaceLanguage {
76
80
  constructor(spec) {
77
81
  this.spec = spec;
78
82
  this.scanner = new Scanner(spec);
83
+ this.engineScanner = new Scanner(spec, spec.delimiters);
79
84
  for (const notation of spec.notations) {
80
85
  const info = spec.terms.get(notation.term);
81
86
  if (info === undefined) {
@@ -222,18 +227,28 @@ export class SurfaceLanguage {
222
227
  /**
223
228
  * Parse surface text. `lints: false` skips the spec's refusal
224
229
  * conventions (bracket discipline, chain refusal, closed sentences) —
225
- * for reading text that is grammatical but not surface-idiomatic, such
226
- * as this library's own engine-mode output.
230
+ * for reading text that is grammatical but not surface-idiomatic.
231
+ *
232
+ * `mode: "engine"` reads this library's own engine-mode output instead:
233
+ * the theory's delimiters rather than the surface set, no elaboration,
234
+ * and lints off unless asked for. Engine text is whitespace-separated
235
+ * and fully parenthesized, so it needs no wide delimiter set — and a
236
+ * surface elab rule would misread it, Quine's `( ?x:var )` happily
237
+ * eating the `(x)` inside `(F (x))`.
227
238
  */
228
239
  parse(text, options = {}) {
229
- const lints = options.lints ?? true;
240
+ const mode = options.mode ?? "surface";
241
+ const lints = options.lints ?? mode === "surface";
242
+ if (mode === "engine") {
243
+ return new Parse(this, this.engineScanner, text, lints).run();
244
+ }
230
245
  if (this.spec.elabRules.length === 0) {
231
- return new Parse(this, text, lints).run();
246
+ return new Parse(this, this.scanner, text, lints).run();
232
247
  }
233
248
  // Elaborate first, then map every span in the outcome back through
234
249
  // the origin map, so nothing downstream sees elaborated offsets.
235
250
  const elaborated = elaborate(this, text);
236
- const result = new Parse(this, elaborated.text, lints).run();
251
+ const result = new Parse(this, this.scanner, elaborated.text, lints).run();
237
252
  const diagnostics = result.diagnostics.map((diag) => ({
238
253
  ...diag,
239
254
  span: remapSpan(elaborated.origin, diag.span),
@@ -253,6 +268,7 @@ export class SurfaceLanguage {
253
268
  }
254
269
  class Parse {
255
270
  lang;
271
+ scanner;
256
272
  text;
257
273
  lintsEnabled;
258
274
  position = 0;
@@ -265,22 +281,23 @@ class Parse {
265
281
  * not a stray `(` after the sentence letter F.
266
282
  */
267
283
  bestTrialFailure = null;
268
- constructor(lang, text, lintsEnabled) {
284
+ constructor(lang, scanner, text, lintsEnabled) {
269
285
  this.lang = lang;
286
+ this.scanner = scanner;
270
287
  this.text = text;
271
288
  this.lintsEnabled = lintsEnabled;
272
289
  }
273
290
  run() {
274
291
  const parsed = this.parseExpr(0);
275
292
  if (parsed !== null) {
276
- const point = this.lang.scanner.at(this.text, this.position);
293
+ const point = this.scanner.at(this.text, this.position);
277
294
  if (!point.atEnd) {
278
295
  const trial = this.bestTrialFailure;
279
296
  if (trial !== null && trial.end > point.start) {
280
297
  this.diagnostics.push(trial.diag);
281
298
  }
282
299
  else if (point.readings.length === 0) {
283
- this.report("unrecognized_character", { character: this.text[point.start] ?? "" }, { start: point.start, end: point.start + 1 });
300
+ this.report("unrecognized_chunk", { chunk: point.chunk }, { start: point.start, end: point.start + point.chunk.length });
284
301
  }
285
302
  else {
286
303
  const reading = point.readings[0];
@@ -378,7 +395,7 @@ class Parse {
378
395
  return null;
379
396
  }
380
397
  for (;;) {
381
- const point = this.lang.scanner.at(this.text, this.position);
398
+ const point = this.scanner.at(this.text, this.position);
382
399
  if (point.atEnd) {
383
400
  return left;
384
401
  }
@@ -417,15 +434,18 @@ class Parse {
417
434
  }
418
435
  }
419
436
  parsePrimary(min) {
420
- const point = this.lang.scanner.at(this.text, this.position);
437
+ const point = this.scanner.at(this.text, this.position);
421
438
  if (point.atEnd) {
422
439
  return this.report("expected_formula", {}, {
423
440
  start: point.start,
424
441
  end: point.start,
425
442
  });
426
443
  }
444
+ // The chunk's boundaries were fixed by the delimiters, so the whole of
445
+ // what the writer wrote between them is what nothing recognizes — not
446
+ // just its first character.
427
447
  if (point.readings.length === 0) {
428
- return this.report("unrecognized_character", { character: this.text[point.start] ?? "" }, { start: point.start, end: point.start + 1 });
448
+ return this.report("unrecognized_chunk", { chunk: point.chunk }, { start: point.start, end: point.start + point.chunk.length });
429
449
  }
430
450
  // Try each reading with backtracking; if none succeeds, re-run the
431
451
  // first viable one so its diagnostics — the most specific available —
@@ -481,7 +501,7 @@ class Parse {
481
501
  if (inner === null) {
482
502
  return null;
483
503
  }
484
- const point = this.lang.scanner.at(this.text, this.position);
504
+ const point = this.scanner.at(this.text, this.position);
485
505
  const reading = point.readings.find((r) => r.kind === "token" && r.token === close);
486
506
  if (reading === undefined) {
487
507
  return this.report("expected_bracket", { bracket: close }, {
@@ -559,7 +579,7 @@ class Parse {
559
579
  const byIndex = new Map();
560
580
  for (const part of entry.parts) {
561
581
  if (part.kind === "constant") {
562
- const point = this.lang.scanner.at(this.text, this.position);
582
+ const point = this.scanner.at(this.text, this.position);
563
583
  const reading = point.readings.find((r) => r.kind === "token" && r.token === part.token);
564
584
  if (reading === undefined) {
565
585
  return this.report("expected_bracket", { bracket: part.token }, {
@@ -621,7 +641,7 @@ class Parse {
621
641
  return null;
622
642
  }
623
643
  expectBoundVariable(sort) {
624
- const point = this.lang.scanner.at(this.text, this.position);
644
+ const point = this.scanner.at(this.text, this.position);
625
645
  const reading = point.readings.find((r) => r.kind === "name" && r.ref.kind === "var" && r.ref.sort === sort);
626
646
  if (reading === undefined || reading.kind !== "name") {
627
647
  return this.report("expected_variable", {}, {
@@ -671,7 +691,7 @@ class Parse {
671
691
  const args = [];
672
692
  for (const binder of argBinders) {
673
693
  const target = binderSort(binder);
674
- const point = this.lang.scanner.at(this.text, this.position);
694
+ const point = this.scanner.at(this.text, this.position);
675
695
  const open = this.lang.spec.groupingPairs[0]?.[0] ?? "(";
676
696
  const close = this.lang.spec.groupingPairs[0]?.[1] ?? ")";
677
697
  const openReading = point.readings.find((r) => r.kind === "token" && r.token === open);
@@ -681,7 +701,7 @@ class Parse {
681
701
  if (arg === null) {
682
702
  return null;
683
703
  }
684
- const closePoint = this.lang.scanner.at(this.text, this.position);
704
+ const closePoint = this.scanner.at(this.text, this.position);
685
705
  const closeReading = closePoint.readings.find((r) => r.kind === "token" && r.token === close);
686
706
  if (closeReading === undefined) {
687
707
  return this.report("expected_bracket", { bracket: close }, {
@@ -773,7 +793,7 @@ class Parse {
773
793
  * is ambiguous under variadic sequences and stays deferred.
774
794
  */
775
795
  glueOperand(target) {
776
- const point = this.lang.scanner.at(this.text, this.position);
796
+ const point = this.scanner.at(this.text, this.position);
777
797
  for (const reading of point.readings) {
778
798
  if (reading.kind === "name") {
779
799
  if (reading.ref.kind === "var") {
package/dist/parse.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAmB,UAAU,EAAa,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGjD,OAAO,EAAgB,OAAO,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,SAAS,GAA2B;IACxC,sBAAsB,EAAE,qCAAqC;IAC7D,gBAAgB,EAAE,qBAAqB;IACvC,sBAAsB,EAAE,yCAAyC;IACjE,gBAAgB,EAAE,uBAAuB;IACzC,iBAAiB,EAAE,2CAA2C;IAC9D,gBAAgB,EAAE,uBAAuB;IACzC,aAAa,EACX,8DAA8D;IAChE,iBAAiB,EACf,2EAA2E;IAC7E,aAAa,EACX,gEAAgE;IAClE,aAAa,EAAE,oDAAoD;IACnE,iBAAiB,EAAE,8CAA8C;IACjE,iBAAiB,EAAE,oDAAoD;IACvE,wBAAwB,EACtB,8DAA8D;CACjE,CAAC;AAEF,SAAS,OAAO,CAAC,IAAoB;IACnC,OAAO,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AA+CD,SAAS,UAAU,CAAC,MAA0B;IAC5C,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAQ,MAAM,CAAC,IAAgB,CAAC,IAAI,CAAC;AACvC,CAAC;AAED,qEAAqE;AACrE,MAAM,OAAO,eAAe;IACjB,IAAI,CA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,QAAQ,CAAC;oBACtD,QAAQ,KAAK,IAAI;oBACjB,WAAW,KAAK,SAAS;oBACzB,WAAW,CAAC,MAAM,KAAK,CAAC;oBACxB,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;gBAEjD,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,IAAI,CAAC,MAAM,CACT,mBAAmB,EACnB,EAAE,EACF;wBACE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;wBACtB,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC;qBACzB,CACF,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,4EAA4E;IACpE,cAAc,CAAC,IAAY;QACjC,IAAI,KAAK,GAAkB,IAAI,CAAC;QAEhC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAChD,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACzD,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;YACzB,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["/**\n * The surface parser: a faithful port of MM0's operator-precedence math\n * parser (mm0.md, \"the dynamic parser\"), running over the character-level\n * scanner instead of MM0's whitespace lexer, with exactly three declared\n * extensions beyond the upstream grammar:\n *\n * 1. **Grouping pairs** — `expression(max) → open expression(0) close`\n * for every declared bracket pair, close matching open;\n * 2. **assoc-none levels** — a precedence in `@syntax assoc-none` refuses\n * to chain regardless of its declared associativity (`P → Q → R` is an\n * error, per forallx);\n * 3. **Lints** — the closed set of post-parse checks\n * (`parenthesize-binary-only`, `closed-sentences`).\n *\n * Two survivable deviations, both surface-side supersets: a lexicon name\n * (nullary, elided-bare, or applied to parenthesized or juxtaposed\n * arguments) counts as `expression(max)`, where MM0 puts constructor\n * application at 1024; and a token that is both a notation and a lexicon\n * name (Calgary's `A`) is disambiguated by backtracking, notation reading\n * first.\n *\n * mm0.md's slot-precedence rules are used exactly: a prefix notation's\n * intermediate arguments parse at max and its last at the notation's\n * precedence; a general notation's slot parses at max before a variable, at\n * `p+1` before a constant of precedence `p`, and at the head precedence\n * when last. Coercions are inserted along the (unique) path in the coercion\n * graph, per the spec.\n */\n\nimport { type Diagnostic, diagnostic, type Span } from \"./diagnostics.js\";\nimport { elaborate, remapSpan } from \"./elab.js\";\nimport type { NotationInfo, Spec, TermInfo } from \"./reader/spec.js\";\nimport type { Binder, TypeRef } from \"./reader/statements.js\";\nimport { type Reading, Scanner } from \"./scan.js\";\nimport type { AppTerm, Term, VariableTerm } from \"./term.js\";\nimport { walkTerm } from \"./term.js\";\n\nconst TEMPLATES: Record<string, string> = {\n unrecognized_character: \"Unexpected character “{character}”.\",\n expected_formula: \"Expected a formula.\",\n expected_formula_found: \"Expected a formula but found “{token}”.\",\n unexpected_token: \"Unexpected “{token}”.\",\n expected_variable: \"Expected a variable after the quantifier.\",\n expected_bracket: \"Expected “{bracket}”.\",\n chain_refused:\n \"“{operator}” cannot be chained; add parentheses to group it.\",\n group_binary_only:\n \"Parentheses may only enclose a sentence joined by a two-place connective.\",\n free_variable:\n \"“{name}” is a free variable; every formula must be a sentence.\",\n sort_mismatch: \"This has sort {actual} where {expected} is needed.\",\n term_not_sentence: \"This is a {actual}, not a complete sentence.\",\n needs_parentheses: \"“{token}” binds too loosely here; parenthesize it.\",\n spec_notation_incomplete:\n \"The notation for {term} does not cover all of its arguments.\",\n};\n\nfunction precNum(prec: number | \"max\"): number {\n return prec === \"max\" ? Number.POSITIVE_INFINITY : prec;\n}\n\ninterface PrefixEntry {\n readonly kind: \"prefix\";\n readonly info: TermInfo;\n readonly prec: number | \"max\";\n}\n\ninterface InfixEntry {\n readonly kind: \"infix\";\n readonly info: TermInfo;\n readonly prec: number;\n readonly fixity: \"infixl\" | \"infixr\";\n}\n\ninterface GeneralSlot {\n readonly binder: Binder;\n /** Index into the term's binder list this slot fills. */\n readonly index: number;\n readonly prec: number;\n}\n\ninterface GeneralEntry {\n readonly kind: \"general\";\n readonly info: TermInfo;\n /** Interleaved constants (to expect) and slots (to parse), head dropped. */\n readonly parts: readonly (\n | { readonly kind: \"constant\"; readonly token: string }\n | { readonly kind: \"slot\"; readonly slot: GeneralSlot }\n )[];\n}\n\ntype HeadEntry = GeneralEntry | PrefixEntry;\n\nexport interface ParseSuccess {\n readonly ok: true;\n readonly term: Term;\n readonly diagnostics: readonly Diagnostic[];\n}\n\nexport interface ParseFailure {\n readonly ok: false;\n readonly diagnostics: readonly Diagnostic[];\n}\n\nexport type ParseResult = ParseFailure | ParseSuccess;\n\nfunction binderSort(binder: Binder | undefined): string {\n if (binder === undefined || !(\"sort\" in binder.type)) {\n return \"\";\n }\n\n return (binder.type as TypeRef).sort;\n}\n\n/** Everything derived from a Spec that parsing needs, built once. */\nexport class SurfaceLanguage {\n readonly spec: Spec;\n readonly scanner: Scanner;\n readonly heads = new Map<string, HeadEntry>();\n readonly infixes = new Map<string, InfixEntry>();\n readonly closeOf = new Map<string, string>();\n readonly closers = new Set<string>();\n /** Per sort, its `@syntax juxtaposed` combiner — adjacency's meaning. */\n readonly juxtaposedOf = new Map<string, TermInfo>();\n /** Per sort, its `@syntax elided` term — the unwritten argument. */\n readonly elidedOf = new Map<string, TermInfo>();\n /** Sorts some quantifier binds — whose variables *can* be captured. */\n readonly bindableSorts = new Set<string>();\n readonly provableSort: string | null;\n /** Per term, its last-declared notation — the canonical spelling. */\n readonly canonical = new Map<string, NotationInfo>();\n readonly coercionNames = new Set<string>();\n private readonly coercionPaths = new Map<\n string,\n readonly string[] | null\n >();\n\n constructor(spec: Spec) {\n this.spec = spec;\n this.scanner = new Scanner(spec);\n\n for (const notation of spec.notations) {\n const info = spec.terms.get(notation.term);\n\n if (info === undefined) {\n continue;\n }\n\n if (notation.form === \"simple\") {\n if (notation.fixity === \"prefix\") {\n this.heads.set(notation.token, {\n kind: \"prefix\",\n info,\n prec: notation.prec,\n });\n } else if (typeof notation.prec === \"number\") {\n this.infixes.set(notation.token, {\n kind: \"infix\",\n info,\n prec: notation.prec,\n fixity: notation.fixity,\n });\n }\n continue;\n }\n\n const head = notation.literals[0];\n\n if (head === undefined || head.kind !== \"constant\") {\n continue;\n }\n\n // mm0.md's P(lits, q): a slot parses at max before a variable, at\n // p+1 before a constant of precedence p, and at q (the head\n // precedence) when it is the trailing slot.\n const parts: (\n | { kind: \"constant\"; token: string }\n | { kind: \"slot\"; slot: GeneralSlot }\n )[] = [];\n const rest = notation.literals.slice(1);\n\n for (let i = 0; i < rest.length; i += 1) {\n const literal = rest[i];\n\n if (literal === undefined) {\n continue;\n }\n\n if (literal.kind === \"constant\") {\n parts.push({ kind: \"constant\", token: literal.token });\n continue;\n }\n\n const index = notation.binders.findIndex(\n (binder) => binder.name === literal.name,\n );\n const binder = notation.binders[index];\n\n if (binder === undefined) {\n continue;\n }\n\n const following = rest[i + 1];\n const prec =\n following === undefined\n ? precNum(head.prec)\n : following.kind === \"constant\"\n ? precNum(following.prec) + 1\n : Number.POSITIVE_INFINITY;\n\n parts.push({ kind: \"slot\", slot: { binder, index, prec } });\n }\n\n this.heads.set(head.token, { kind: \"general\", info, parts });\n }\n\n for (const [open, close] of spec.groupingPairs) {\n this.closeOf.set(open, close);\n this.closers.add(close);\n }\n\n for (const term of spec.terms.values()) {\n if (term.juxtaposed) {\n this.juxtaposedOf.set(term.returnSort, term);\n }\n\n if (term.elided) {\n this.elidedOf.set(term.returnSort, term);\n }\n\n for (const binder of term.binders) {\n if (binder.binds) {\n this.bindableSorts.add(binderSort(binder));\n }\n }\n }\n\n for (const notation of spec.notations) {\n this.canonical.set(notation.term, notation);\n }\n\n for (const coercion of spec.coercions) {\n this.coercionNames.add(coercion.name);\n }\n\n this.provableSort =\n [...spec.sorts.values()].find((sort) =>\n sort.modifiers.includes(\"provable\"),\n )?.name ?? null;\n }\n\n /**\n * A sentential connective: an infix constructor joining two things of\n * the provable sort. This is the class forallx's bracket convention and\n * the display printer's spacing both key on — `∧` is one, `=` over\n * terms is not.\n */\n isConnective(term: string): boolean {\n const info = this.spec.terms.get(term);\n const provable = this.provableSort;\n const notation = this.canonical.get(term);\n\n return (\n provable !== null &&\n info !== undefined &&\n notation !== undefined &&\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n info.binders.length === 2 &&\n info.binders.every(\n (binder) =>\n !binder.binds &&\n \"sort\" in binder.type &&\n binder.type.sort === provable,\n )\n );\n }\n\n /** The coercion path from one sort to another; unique per mm0.md. */\n coerce(from: string, to: string): readonly string[] | null {\n if (from === to) {\n return [];\n }\n\n const key = `${from}>${to}`;\n const cached = this.coercionPaths.get(key);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const previous = new Map<string, { sort: string; name: string }>();\n const queue = [from];\n\n while (queue.length > 0) {\n const sort = queue.shift();\n\n if (sort === undefined || sort === to) {\n break;\n }\n\n for (const coercion of this.spec.coercions) {\n if (coercion.from === sort && !previous.has(coercion.to)) {\n previous.set(coercion.to, { sort, name: coercion.name });\n queue.push(coercion.to);\n }\n }\n }\n\n let path: string[] | null = null;\n\n if (previous.has(to)) {\n path = [];\n let at = to;\n\n while (at !== from) {\n const step = previous.get(at);\n\n if (step === undefined) {\n path = null;\n break;\n }\n\n path.unshift(step.name);\n at = step.sort;\n }\n }\n\n this.coercionPaths.set(key, path);\n return path;\n }\n\n /**\n * Parse surface text. `lints: false` skips the spec's refusal\n * conventions (bracket discipline, chain refusal, closed sentences) —\n * for reading text that is grammatical but not surface-idiomatic, such\n * as this library's own engine-mode output.\n */\n parse(\n text: string,\n options: { readonly lints?: boolean } = {},\n ): ParseResult {\n const lints = options.lints ?? true;\n\n if (this.spec.elabRules.length === 0) {\n return new Parse(this, text, lints).run();\n }\n\n // Elaborate first, then map every span in the outcome back through\n // the origin map, so nothing downstream sees elaborated offsets.\n const elaborated = elaborate(this, text);\n const result = new Parse(this, elaborated.text, lints).run();\n const diagnostics = result.diagnostics.map((diag) => ({\n ...diag,\n span: remapSpan(elaborated.origin, diag.span),\n }));\n\n if (!result.ok) {\n return { ok: false, diagnostics };\n }\n\n const remapTerm = (term: Term): Term =>\n term.kind === \"variable\"\n ? { ...term, span: remapSpan(elaborated.origin, term.span) }\n : {\n ...term,\n span: remapSpan(elaborated.origin, term.span),\n args: term.args.map(remapTerm),\n };\n\n return { ok: true, term: remapTerm(result.term), diagnostics };\n }\n}\n\nclass Parse {\n private position = 0;\n private diagnostics: Diagnostic[] = [];\n /**\n * The deepest-reaching diagnostic a failed trial produced. When a\n * fallback reading succeeds but leaves trailing input short of where a\n * higher-priority reading got to, that earlier, more specific error is\n * the one the writer should see — `F(a` is an unclosed argument list,\n * not a stray `(` after the sentence letter F.\n */\n private bestTrialFailure: { end: number; diag: Diagnostic } | null = null;\n\n constructor(\n private readonly lang: SurfaceLanguage,\n private readonly text: string,\n private readonly lintsEnabled: boolean,\n ) {}\n\n run(): ParseResult {\n const parsed = this.parseExpr(0);\n\n if (parsed !== null) {\n const point = this.lang.scanner.at(this.text, this.position);\n\n if (!point.atEnd) {\n const trial = this.bestTrialFailure;\n\n if (trial !== null && trial.end > point.start) {\n this.diagnostics.push(trial.diag);\n } else if (point.readings.length === 0) {\n this.report(\n \"unrecognized_character\",\n { character: this.text[point.start] ?? \"\" },\n { start: point.start, end: point.start + 1 },\n );\n } else {\n const reading = point.readings[0];\n const token =\n reading === undefined\n ? (this.text[point.start] ?? \"\")\n : reading.kind === \"token\"\n ? reading.token\n : reading.name;\n\n this.report(\n \"unexpected_token\",\n { token },\n {\n start: point.start,\n end: point.start + (reading?.length ?? 1),\n },\n );\n }\n\n return { ok: false, diagnostics: this.diagnostics };\n }\n }\n\n if (parsed === null) {\n if (this.diagnostics.length === 0) {\n this.report(\"expected_formula\", {}, { start: 0, end: 0 });\n }\n\n return { ok: false, diagnostics: this.diagnostics };\n }\n\n let term = parsed;\n const provable = this.lang.provableSort;\n\n if (provable !== null && term.sort !== provable) {\n const wrapped = this.coerceTerm(term, provable);\n\n if (wrapped === null) {\n this.report(\"term_not_sentence\", { actual: term.sort }, term.span);\n return { ok: false, diagnostics: this.diagnostics };\n }\n\n term = wrapped;\n }\n\n if (this.lintsEnabled) {\n this.lint(term);\n }\n\n if (this.diagnostics.length > 0) {\n return { ok: false, diagnostics: this.diagnostics };\n }\n\n return { ok: true, term, diagnostics: this.diagnostics };\n }\n\n // ── plumbing ──────────────────────────────────────────────────────────\n\n private report(\n id: string,\n params: Record<string, string>,\n span: Span,\n ): null {\n this.diagnostics.push(diagnostic(id, TEMPLATES[id] ?? id, params, span));\n return null;\n }\n\n /** Run a trial parse; on failure, rewind input and drop its diagnostics. */\n private attempt<T>(body: () => T | null): T | null {\n const position = this.position;\n const kept = this.diagnostics.length;\n const result = body();\n\n if (result === null) {\n for (const diag of this.diagnostics.slice(kept)) {\n if (diag.span.end > (this.bestTrialFailure?.end ?? -1)) {\n this.bestTrialFailure = { end: diag.span.end, diag };\n }\n }\n\n this.position = position;\n this.diagnostics.length = kept;\n }\n\n return result;\n }\n\n private coerceTerm(term: Term, target: string): Term | null {\n const path = this.lang.coerce(term.sort, target);\n\n if (path === null) {\n return null;\n }\n\n let wrapped = term;\n\n for (const name of path) {\n const info = this.lang.spec.terms.get(name);\n\n wrapped = {\n kind: \"app\",\n term: name,\n args: [wrapped],\n sort: info?.returnSort ?? target,\n span: wrapped.span,\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n };\n }\n\n return wrapped;\n }\n\n private coerceOrReport(term: Term, target: string): Term | null {\n const wrapped = this.coerceTerm(term, target);\n\n if (wrapped === null) {\n return this.report(\n \"sort_mismatch\",\n { actual: term.sort, expected: target },\n term.span,\n );\n }\n\n return wrapped;\n }\n\n // ── the precedence parser ─────────────────────────────────────────────\n\n private parseExpr(min: number): Term | null {\n let left = this.parsePrimary(min);\n\n if (left === null) {\n return null;\n }\n\n for (;;) {\n const point = this.lang.scanner.at(this.text, this.position);\n\n if (point.atEnd) {\n return left;\n }\n\n const reading = point.readings.find((r) => r.kind === \"token\");\n\n if (reading === undefined || reading.kind !== \"token\") {\n return left;\n }\n\n const entry = this.lang.infixes.get(reading.token);\n\n if (entry === undefined || entry.prec < min) {\n return left;\n }\n\n this.position = point.start + reading.length;\n\n const right = this.parseExpr(\n entry.fixity === \"infixl\" ? entry.prec + 1 : entry.prec,\n );\n\n if (right === null) {\n return null;\n }\n\n const binders = entry.info.binders;\n const leftSort = binderSort(binders[0]);\n const rightSort = binderSort(binders[1]);\n const coercedLeft = this.coerceOrReport(left, leftSort);\n const coercedRight = this.coerceOrReport(right, rightSort);\n\n if (coercedLeft === null || coercedRight === null) {\n return null;\n }\n\n left = {\n kind: \"app\",\n term: entry.info.name,\n args: [coercedLeft, coercedRight],\n sort: entry.info.returnSort,\n span: { start: left.span.start, end: right.span.end },\n grouped: false,\n fixity: entry.fixity,\n prec: entry.prec,\n token: reading.token,\n } satisfies AppTerm;\n }\n }\n\n private parsePrimary(min: number): Term | null {\n const point = this.lang.scanner.at(this.text, this.position);\n\n if (point.atEnd) {\n return this.report(\n \"expected_formula\",\n {},\n {\n start: point.start,\n end: point.start,\n },\n );\n }\n\n if (point.readings.length === 0) {\n return this.report(\n \"unrecognized_character\",\n { character: this.text[point.start] ?? \"\" },\n { start: point.start, end: point.start + 1 },\n );\n }\n\n // Try each reading with backtracking; if none succeeds, re-run the\n // first viable one so its diagnostics — the most specific available —\n // are the ones the writer sees.\n const viable = point.readings.filter((reading) =>\n this.isViablePrimary(reading),\n );\n\n for (const reading of viable) {\n const result = this.attempt(() =>\n this.parsePrimaryReading(point.start, reading, min),\n );\n\n if (result !== null) {\n return result;\n }\n }\n\n const first = viable[0];\n\n if (first !== undefined) {\n return this.parsePrimaryReading(point.start, first, min);\n }\n\n const reading = point.readings[0];\n const token =\n reading?.kind === \"token\" ? reading.token : (reading?.name ?? \"\");\n\n return this.report(\n \"expected_formula_found\",\n { token },\n {\n start: point.start,\n end: point.start + (reading?.length ?? 1),\n },\n );\n }\n\n private isViablePrimary(reading: Reading): boolean {\n if (reading.kind === \"name\") {\n return true;\n }\n\n return (\n this.lang.closeOf.has(reading.token) ||\n this.lang.heads.has(reading.token)\n );\n }\n\n private parsePrimaryReading(\n start: number,\n reading: Reading,\n min: number,\n ): Term | null {\n if (reading.kind === \"name\") {\n return this.parseName(start, reading);\n }\n\n const close = this.lang.closeOf.get(reading.token);\n\n if (close !== undefined) {\n return this.parseGroup(start, close, reading.length);\n }\n\n const head = this.lang.heads.get(reading.token);\n\n if (head === undefined) {\n return this.report(\n \"expected_formula_found\",\n { token: reading.token },\n {\n start,\n end: start + reading.length,\n },\n );\n }\n\n this.position = start + reading.length;\n\n return head.kind === \"prefix\"\n ? this.parsePrefix(start, reading.token, head, min)\n : this.parseGeneral(start, reading.token, head, min);\n }\n\n private parseGroup(\n start: number,\n close: string,\n openLength: number,\n ): Term | null {\n this.position = start + openLength;\n\n const inner = this.parseExpr(0);\n\n if (inner === null) {\n return null;\n }\n\n const point = this.lang.scanner.at(this.text, this.position);\n const reading = point.readings.find(\n (r) => r.kind === \"token\" && r.token === close,\n );\n\n if (reading === undefined) {\n return this.report(\n \"expected_bracket\",\n { bracket: close },\n {\n start: point.start,\n end: point.start + 1,\n },\n );\n }\n\n this.position = point.start + reading.length;\n\n return {\n ...inner,\n grouped: true,\n span: { start, end: this.position },\n };\n }\n\n private parsePrefix(\n start: number,\n token: string,\n entry: PrefixEntry,\n min: number,\n ): Term | null {\n if (precNum(entry.prec) < min) {\n return this.report(\n \"needs_parentheses\",\n { token },\n {\n start,\n end: this.position,\n },\n );\n }\n\n const binders = entry.info.binders;\n const args: Term[] = [];\n\n for (let i = 0; i < binders.length; i += 1) {\n const binder = binders[i];\n\n if (binder === undefined) {\n continue;\n }\n\n if (binder.binds) {\n const variable = this.expectBoundVariable(binderSort(binder));\n\n if (variable === null) {\n return null;\n }\n\n args.push(variable);\n continue;\n }\n\n // mm0.md: a prefix notation's intermediate arguments parse at max,\n // its last at the notation's own precedence.\n const slotPrec =\n i === binders.length - 1\n ? precNum(entry.prec)\n : Number.POSITIVE_INFINITY;\n const arg = this.parseExpr(slotPrec);\n\n if (arg === null) {\n return null;\n }\n\n const coerced = this.coerceOrReport(arg, binderSort(binder));\n\n if (coerced === null) {\n return null;\n }\n\n args.push(coerced);\n }\n\n return {\n kind: \"app\",\n term: entry.info.name,\n args,\n sort: entry.info.returnSort,\n span: {\n start,\n end: args[args.length - 1]?.span.end ?? this.position,\n },\n grouped: false,\n fixity: \"prefix\",\n prec: precNum(entry.prec),\n token,\n };\n }\n\n private parseGeneral(\n start: number,\n token: string,\n entry: GeneralEntry,\n min: number,\n ): Term | null {\n const headPrec = this.headPrecOf(token);\n\n if (headPrec !== null && headPrec < min) {\n return this.report(\n \"needs_parentheses\",\n { token },\n {\n start,\n end: this.position,\n },\n );\n }\n\n const byIndex = new Map<number, Term>();\n\n for (const part of entry.parts) {\n if (part.kind === \"constant\") {\n const point = this.lang.scanner.at(this.text, this.position);\n const reading = point.readings.find(\n (r) => r.kind === \"token\" && r.token === part.token,\n );\n\n if (reading === undefined) {\n return this.report(\n \"expected_bracket\",\n { bracket: part.token },\n {\n start: point.start,\n end: point.start + 1,\n },\n );\n }\n\n this.position = point.start + reading.length;\n continue;\n }\n\n const { binder, index, prec } = part.slot;\n\n if (binder.binds) {\n const variable = this.expectBoundVariable(binderSort(binder));\n\n if (variable === null) {\n return null;\n }\n\n byIndex.set(index, variable);\n continue;\n }\n\n const arg = this.parseExpr(prec);\n\n if (arg === null) {\n return null;\n }\n\n const coerced = this.coerceOrReport(arg, binderSort(binder));\n\n if (coerced === null) {\n return null;\n }\n\n byIndex.set(index, coerced);\n }\n\n const args: Term[] = [];\n\n for (let i = 0; i < entry.info.binders.length; i += 1) {\n const arg = byIndex.get(i);\n\n if (arg === undefined) {\n return this.report(\n \"spec_notation_incomplete\",\n { term: entry.info.name },\n { start, end: this.position },\n );\n }\n\n args.push(arg);\n }\n\n return {\n kind: \"app\",\n term: entry.info.name,\n args,\n sort: entry.info.returnSort,\n span: { start, end: args[args.length - 1]?.span.end ?? this.position },\n grouped: false,\n fixity: \"general\",\n prec: headPrec,\n token,\n };\n }\n\n private headPrecOf(token: string): number | null {\n for (const notation of this.lang.spec.notations) {\n if (notation.form === \"general\") {\n const head = notation.literals[0];\n\n if (head?.kind === \"constant\" && head.token === token) {\n return precNum(head.prec);\n }\n }\n }\n\n return null;\n }\n\n private expectBoundVariable(sort: string): VariableTerm | null {\n const point = this.lang.scanner.at(this.text, this.position);\n const reading = point.readings.find(\n (r): r is Reading & { kind: \"name\" } =>\n r.kind === \"name\" && r.ref.kind === \"var\" && r.ref.sort === sort,\n );\n\n if (reading === undefined || reading.kind !== \"name\") {\n return this.report(\n \"expected_variable\",\n {},\n {\n start: point.start,\n end: point.start + 1,\n },\n );\n }\n\n this.position = point.start + reading.length;\n\n return {\n kind: \"variable\",\n name: reading.name,\n sort,\n span: { start: point.start, end: this.position },\n grouped: false,\n binder: true,\n };\n }\n\n /**\n * A lexicon name: a `@vars` token (a variable of its sort), or a\n * declared term with no notation of its own — a sentence letter,\n * predicate, function symbol, or constant. A term's arguments come\n * parenthesized (application syntax, so the argument is not marked\n * `grouped` and the binary-only lint does not apply inside; the\n * canonical pair is always the first declared one), or juxtaposed when\n * the argument sort has an `@syntax juxtaposed` combiner, or not at all\n * when it has an `@syntax elided` term. Context settles the `A`-as-∀\n * ambiguity exactly as in Carnap: the quantifier reading was tried\n * first, and fell through to here only if it failed.\n */\n private parseName(\n start: number,\n reading: Reading & { kind: \"name\" },\n ): Term | null {\n this.position = start + reading.length;\n\n if (reading.ref.kind === \"var\") {\n return {\n kind: \"variable\",\n name: reading.name,\n sort: reading.ref.sort,\n span: { start, end: this.position },\n grouped: false,\n binder: false,\n };\n }\n\n const info = this.lang.spec.terms.get(reading.ref.term);\n\n if (info === undefined) {\n return this.report(\n \"expected_formula_found\",\n { token: reading.name },\n { start, end: start + reading.length },\n );\n }\n\n const argBinders = info.binders.filter((binder) => !binder.binds);\n const args: Term[] = [];\n\n for (const binder of argBinders) {\n const target = binderSort(binder);\n const point = this.lang.scanner.at(this.text, this.position);\n const open = this.lang.spec.groupingPairs[0]?.[0] ?? \"(\";\n const close = this.lang.spec.groupingPairs[0]?.[1] ?? \")\";\n const openReading = point.readings.find(\n (r) => r.kind === \"token\" && r.token === open,\n );\n\n if (openReading !== undefined) {\n this.position = point.start + openReading.length;\n\n const arg = this.parseExpr(0);\n\n if (arg === null) {\n return null;\n }\n\n const closePoint = this.lang.scanner.at(this.text, this.position);\n const closeReading = closePoint.readings.find(\n (r) => r.kind === \"token\" && r.token === close,\n );\n\n if (closeReading === undefined) {\n return this.report(\n \"expected_bracket\",\n { bracket: close },\n {\n start: closePoint.start,\n end: closePoint.start + 1,\n },\n );\n }\n\n this.position = closePoint.start + closeReading.length;\n\n const coerced = this.coerceOrReport(arg, target);\n\n if (coerced === null) {\n return null;\n }\n\n args.push(coerced);\n continue;\n }\n\n // Juxtaposed gluing — `Fxy`, the pre-2019 forallx shape. Operands\n // (self-delimiting single-token expressions) are consumed greedily\n // while they coerce into the argument sort; several fold through\n // the sort's declared combiner.\n const combiner =\n argBinders.length === 1\n ? this.lang.juxtaposedOf.get(target)\n : undefined;\n\n if (combiner !== undefined) {\n const leaves: Term[] = [];\n\n for (;;) {\n const leaf = this.glueOperand(target);\n\n if (leaf === null) {\n break;\n }\n\n leaves.push(leaf);\n }\n\n const first = leaves[0];\n\n if (first !== undefined) {\n let folded = first;\n\n for (const leaf of leaves.slice(1)) {\n folded = {\n kind: \"app\",\n term: combiner.name,\n args: [folded, leaf],\n sort: combiner.returnSort,\n span: { start: folded.span.start, end: leaf.span.end },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n };\n }\n\n args.push(folded);\n continue;\n }\n // No operand at all: fall through to elision, so a bare letter\n // can still be a sentence letter in a juxtaposed dialect.\n }\n\n const elided = this.lang.elidedOf.get(target);\n\n if (elided !== undefined) {\n args.push({\n kind: \"app\",\n term: elided.name,\n args: [],\n sort: elided.returnSort,\n span: { start, end: start + reading.length },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n });\n continue;\n }\n\n return this.report(\n \"expected_formula_found\",\n { token: reading.name },\n { start, end: start + reading.length },\n );\n }\n\n return {\n kind: \"app\",\n term: reading.name,\n args,\n sort: info.returnSort,\n span: { start, end: this.position },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n };\n }\n\n /**\n * One juxtaposed operand: a self-delimiting single-token expression — a\n * variable, a nullary lexicon name, or a nullary notation (an\n * empty-set-style constant) — whose sort coerces into the target.\n * Anything larger (a parenthesized group, a term applied to arguments\n * of its own) is deliberately not an operand yet: nested juxtaposition\n * is ambiguous under variadic sequences and stays deferred.\n */\n private glueOperand(target: string): Term | null {\n const point = this.lang.scanner.at(this.text, this.position);\n\n for (const reading of point.readings) {\n if (reading.kind === \"name\") {\n if (reading.ref.kind === \"var\") {\n if (this.lang.coerce(reading.ref.sort, target) === null) {\n continue;\n }\n\n this.position = point.start + reading.length;\n\n return this.coerceOrReport(\n {\n kind: \"variable\",\n name: reading.name,\n sort: reading.ref.sort,\n span: { start: point.start, end: this.position },\n grouped: false,\n binder: false,\n },\n target,\n );\n }\n\n const info = this.lang.spec.terms.get(reading.ref.term);\n\n if (\n info === undefined ||\n info.binders.some((binder) => !binder.binds) ||\n this.lang.coerce(info.returnSort, target) === null\n ) {\n continue;\n }\n\n this.position = point.start + reading.length;\n\n return this.coerceOrReport(\n {\n kind: \"app\",\n term: info.name,\n args: [],\n sort: info.returnSort,\n span: { start: point.start, end: this.position },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n },\n target,\n );\n }\n\n const head = this.lang.heads.get(reading.token);\n\n if (\n head?.kind === \"general\" &&\n head.parts.length === 0 &&\n head.info.binders.length === 0 &&\n this.lang.coerce(head.info.returnSort, target) !== null\n ) {\n this.position = point.start + reading.length;\n\n return this.coerceOrReport(\n {\n kind: \"app\",\n term: head.info.name,\n args: [],\n sort: head.info.returnSort,\n span: { start: point.start, end: this.position },\n grouped: false,\n fixity: \"general\",\n prec: null,\n token: reading.token,\n },\n target,\n );\n }\n }\n\n return null;\n }\n\n // ── lints ─────────────────────────────────────────────────────────────\n\n private lint(term: Term): void {\n const lints = this.lang.spec.lints;\n const assocNone = this.lang.spec.assocNone;\n const provable = this.lang.provableSort;\n\n walkTerm(term, (node, bound) => {\n if (node.kind === \"variable\") {\n // A leaf of a sort no quantifier binds — a constant from a\n // `@vars` pool, like Calgary's names — cannot be *free*: freedom\n // is only meaningful where binding is possible.\n if (\n lints.includes(\"closed-sentences\") &&\n !node.binder &&\n this.lang.bindableSorts.has(node.sort) &&\n !bound.has(node.name)\n ) {\n this.report(\"free_variable\", { name: node.name }, node.span);\n }\n\n return;\n }\n\n // The chain refusal: an operand produced by an operator at the same\n // assoc-none level, without its own brackets, has no reading.\n if (\n typeof node.prec === \"number\" &&\n assocNone.has(node.prec) &&\n (node.fixity === \"infixl\" || node.fixity === \"infixr\")\n ) {\n for (const arg of node.args) {\n if (\n arg.kind === \"app\" &&\n typeof arg.prec === \"number\" &&\n arg.prec === node.prec &&\n (arg.fixity === \"infixl\" || arg.fixity === \"infixr\") &&\n !arg.grouped\n ) {\n const operator =\n arg.token ?? this.canonicalToken(arg.term) ?? arg.term;\n\n this.report(\"chain_refused\", { operator }, arg.span);\n }\n }\n }\n\n if (lints.includes(\"parenthesize-binary-only\") && node.grouped) {\n const binderSorts = this.lang.spec.terms\n .get(node.term)\n ?.binders.map(binderSort);\n const connective =\n (node.fixity === \"infixl\" || node.fixity === \"infixr\") &&\n provable !== null &&\n binderSorts !== undefined &&\n binderSorts.length === 2 &&\n binderSorts.every((sort) => sort === provable);\n\n if (!connective) {\n this.report(\n \"group_binary_only\",\n {},\n {\n start: node.span.start,\n end: node.span.start + 1,\n },\n );\n }\n }\n });\n }\n\n /** The last-declared notation token for a term — its canonical spelling. */\n private canonicalToken(term: string): string | null {\n let token: string | null = null;\n\n for (const notation of this.lang.spec.notations) {\n if (notation.term === term && notation.form === \"simple\") {\n token = notation.token;\n }\n }\n\n return token;\n }\n}\n"]}
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAmB,UAAU,EAAa,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGjD,OAAO,EAAgB,OAAO,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,SAAS,GAA2B;IACxC,kBAAkB,EAAE,yCAAyC;IAC7D,gBAAgB,EAAE,qBAAqB;IACvC,sBAAsB,EAAE,yCAAyC;IACjE,gBAAgB,EAAE,uBAAuB;IACzC,iBAAiB,EAAE,2CAA2C;IAC9D,gBAAgB,EAAE,uBAAuB;IACzC,aAAa,EACX,8DAA8D;IAChE,iBAAiB,EACf,2EAA2E;IAC7E,aAAa,EACX,gEAAgE;IAClE,aAAa,EAAE,oDAAoD;IACnE,iBAAiB,EAAE,8CAA8C;IACjE,iBAAiB,EAAE,oDAAoD;IACvE,wBAAwB,EACtB,8DAA8D;CACjE,CAAC;AAEF,SAAS,OAAO,CAAC,IAAoB;IACnC,OAAO,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AAuDD,SAAS,UAAU,CAAC,MAA0B;IAC5C,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAQ,MAAM,CAAC,IAAgB,CAA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ACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["/**\n * The surface parser: a faithful port of MM0's operator-precedence math\n * parser (mm0.md, \"the dynamic parser\"), running over the delimiter\n * scanner — MM0's own segmentation rule under a wider, declared delimiter\n * set — with exactly three declared extensions beyond the upstream\n * grammar:\n *\n * 1. **Grouping pairs** — `expression(max) → open expression(0) close`\n * for every declared bracket pair, close matching open;\n * 2. **assoc-none levels** — a precedence in `@syntax assoc-none` refuses\n * to chain regardless of its declared associativity (`P → Q → R` is an\n * error, per forallx);\n * 3. **Lints** — the closed set of post-parse checks\n * (`parenthesize-binary-only`, `closed-sentences`).\n *\n * Two survivable deviations, both surface-side supersets: a lexicon name\n * (nullary, elided-bare, or applied to parenthesized or juxtaposed\n * arguments) counts as `expression(max)`, where MM0 puts constructor\n * application at 1024; and a token that is both a notation and a lexicon\n * name (Calgary's `A`) is disambiguated by backtracking, notation reading\n * first.\n *\n * mm0.md's slot-precedence rules are used exactly: a prefix notation's\n * intermediate arguments parse at max and its last at the notation's\n * precedence; a general notation's slot parses at max before a variable, at\n * `p+1` before a constant of precedence `p`, and at the head precedence\n * when last. Coercions are inserted along the (unique) path in the coercion\n * graph, per the spec.\n */\n\nimport { type Diagnostic, diagnostic, type Span } from \"./diagnostics.js\";\nimport { elaborate, remapSpan } from \"./elab.js\";\nimport type { NotationInfo, Spec, TermInfo } from \"./reader/spec.js\";\nimport type { Binder, TypeRef } from \"./reader/statements.js\";\nimport { type Reading, Scanner } from \"./scan.js\";\nimport type { AppTerm, Term, VariableTerm } from \"./term.js\";\nimport { walkTerm } from \"./term.js\";\n\nconst TEMPLATES: Record<string, string> = {\n unrecognized_chunk: \"“{chunk}” is not part of this language.\",\n expected_formula: \"Expected a formula.\",\n expected_formula_found: \"Expected a formula but found “{token}”.\",\n unexpected_token: \"Unexpected “{token}”.\",\n expected_variable: \"Expected a variable after the quantifier.\",\n expected_bracket: \"Expected “{bracket}”.\",\n chain_refused:\n \"“{operator}” cannot be chained; add parentheses to group it.\",\n group_binary_only:\n \"Parentheses may only enclose a sentence joined by a two-place connective.\",\n free_variable:\n \"“{name}” is a free variable; every formula must be a sentence.\",\n sort_mismatch: \"This has sort {actual} where {expected} is needed.\",\n term_not_sentence: \"This is a {actual}, not a complete sentence.\",\n needs_parentheses: \"“{token}” binds too loosely here; parenthesize it.\",\n spec_notation_incomplete:\n \"The notation for {term} does not cover all of its arguments.\",\n};\n\nfunction precNum(prec: number | \"max\"): number {\n return prec === \"max\" ? Number.POSITIVE_INFINITY : prec;\n}\n\ninterface PrefixEntry {\n readonly kind: \"prefix\";\n readonly info: TermInfo;\n readonly prec: number | \"max\";\n}\n\ninterface InfixEntry {\n readonly kind: \"infix\";\n readonly info: TermInfo;\n readonly prec: number;\n readonly fixity: \"infixl\" | \"infixr\";\n}\n\ninterface GeneralSlot {\n readonly binder: Binder;\n /** Index into the term's binder list this slot fills. */\n readonly index: number;\n readonly prec: number;\n}\n\ninterface GeneralEntry {\n readonly kind: \"general\";\n readonly info: TermInfo;\n /** Interleaved constants (to expect) and slots (to parse), head dropped. */\n readonly parts: readonly (\n | { readonly kind: \"constant\"; readonly token: string }\n | { readonly kind: \"slot\"; readonly slot: GeneralSlot }\n )[];\n}\n\ntype HeadEntry = GeneralEntry | PrefixEntry;\n\nexport interface ParseSuccess {\n readonly ok: true;\n readonly term: Term;\n readonly diagnostics: readonly Diagnostic[];\n}\n\nexport interface ParseFailure {\n readonly ok: false;\n readonly diagnostics: readonly Diagnostic[];\n}\n\nexport type ParseResult = ParseFailure | ParseSuccess;\n\n/**\n * Which delimiter set cuts the input up. `surface` is student input, read\n * under the spec's `surfaceDelimiters`; `engine` is this library's own\n * engine-mode emission, read under the theory's own `delimiters` — the\n * counterpart of `printTerm`'s two modes.\n */\nexport type ParseMode = \"engine\" | \"surface\";\n\nfunction binderSort(binder: Binder | undefined): string {\n if (binder === undefined || !(\"sort\" in binder.type)) {\n return \"\";\n }\n\n return (binder.type as TypeRef).sort;\n}\n\n/** Everything derived from a Spec that parsing needs, built once. */\nexport class SurfaceLanguage {\n readonly spec: Spec;\n /** Student input: the wide surface delimiter set. */\n readonly scanner: Scanner;\n /** Engine text: the same vocabulary under the theory's own delimiters. */\n readonly engineScanner: Scanner;\n readonly heads = new Map<string, HeadEntry>();\n readonly infixes = new Map<string, InfixEntry>();\n readonly closeOf = new Map<string, string>();\n readonly closers = new Set<string>();\n /** Per sort, its `@syntax juxtaposed` combiner — adjacency's meaning. */\n readonly juxtaposedOf = new Map<string, TermInfo>();\n /** Per sort, its `@syntax elided` term — the unwritten argument. */\n readonly elidedOf = new Map<string, TermInfo>();\n /** Sorts some quantifier binds — whose variables *can* be captured. */\n readonly bindableSorts = new Set<string>();\n readonly provableSort: string | null;\n /** Per term, its last-declared notation — the canonical spelling. */\n readonly canonical = new Map<string, NotationInfo>();\n readonly coercionNames = new Set<string>();\n private readonly coercionPaths = new Map<\n string,\n readonly string[] | null\n >();\n\n constructor(spec: Spec) {\n this.spec = spec;\n this.scanner = new Scanner(spec);\n this.engineScanner = new Scanner(spec, spec.delimiters);\n\n for (const notation of spec.notations) {\n const info = spec.terms.get(notation.term);\n\n if (info === undefined) {\n continue;\n }\n\n if (notation.form === \"simple\") {\n if (notation.fixity === \"prefix\") {\n this.heads.set(notation.token, {\n kind: \"prefix\",\n info,\n prec: notation.prec,\n });\n } else if (typeof notation.prec === \"number\") {\n this.infixes.set(notation.token, {\n kind: \"infix\",\n info,\n prec: notation.prec,\n fixity: notation.fixity,\n });\n }\n continue;\n }\n\n const head = notation.literals[0];\n\n if (head === undefined || head.kind !== \"constant\") {\n continue;\n }\n\n // mm0.md's P(lits, q): a slot parses at max before a variable, at\n // p+1 before a constant of precedence p, and at q (the head\n // precedence) when it is the trailing slot.\n const parts: (\n | { kind: \"constant\"; token: string }\n | { kind: \"slot\"; slot: GeneralSlot }\n )[] = [];\n const rest = notation.literals.slice(1);\n\n for (let i = 0; i < rest.length; i += 1) {\n const literal = rest[i];\n\n if (literal === undefined) {\n continue;\n }\n\n if (literal.kind === \"constant\") {\n parts.push({ kind: \"constant\", token: literal.token });\n continue;\n }\n\n const index = notation.binders.findIndex(\n (binder) => binder.name === literal.name,\n );\n const binder = notation.binders[index];\n\n if (binder === undefined) {\n continue;\n }\n\n const following = rest[i + 1];\n const prec =\n following === undefined\n ? precNum(head.prec)\n : following.kind === \"constant\"\n ? precNum(following.prec) + 1\n : Number.POSITIVE_INFINITY;\n\n parts.push({ kind: \"slot\", slot: { binder, index, prec } });\n }\n\n this.heads.set(head.token, { kind: \"general\", info, parts });\n }\n\n for (const [open, close] of spec.groupingPairs) {\n this.closeOf.set(open, close);\n this.closers.add(close);\n }\n\n for (const term of spec.terms.values()) {\n if (term.juxtaposed) {\n this.juxtaposedOf.set(term.returnSort, term);\n }\n\n if (term.elided) {\n this.elidedOf.set(term.returnSort, term);\n }\n\n for (const binder of term.binders) {\n if (binder.binds) {\n this.bindableSorts.add(binderSort(binder));\n }\n }\n }\n\n for (const notation of spec.notations) {\n this.canonical.set(notation.term, notation);\n }\n\n for (const coercion of spec.coercions) {\n this.coercionNames.add(coercion.name);\n }\n\n this.provableSort =\n [...spec.sorts.values()].find((sort) =>\n sort.modifiers.includes(\"provable\"),\n )?.name ?? null;\n }\n\n /**\n * A sentential connective: an infix constructor joining two things of\n * the provable sort. This is the class forallx's bracket convention and\n * the display printer's spacing both key on — `∧` is one, `=` over\n * terms is not.\n */\n isConnective(term: string): boolean {\n const info = this.spec.terms.get(term);\n const provable = this.provableSort;\n const notation = this.canonical.get(term);\n\n return (\n provable !== null &&\n info !== undefined &&\n notation !== undefined &&\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n info.binders.length === 2 &&\n info.binders.every(\n (binder) =>\n !binder.binds &&\n \"sort\" in binder.type &&\n binder.type.sort === provable,\n )\n );\n }\n\n /** The coercion path from one sort to another; unique per mm0.md. */\n coerce(from: string, to: string): readonly string[] | null {\n if (from === to) {\n return [];\n }\n\n const key = `${from}>${to}`;\n const cached = this.coercionPaths.get(key);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const previous = new Map<string, { sort: string; name: string }>();\n const queue = [from];\n\n while (queue.length > 0) {\n const sort = queue.shift();\n\n if (sort === undefined || sort === to) {\n break;\n }\n\n for (const coercion of this.spec.coercions) {\n if (coercion.from === sort && !previous.has(coercion.to)) {\n previous.set(coercion.to, { sort, name: coercion.name });\n queue.push(coercion.to);\n }\n }\n }\n\n let path: string[] | null = null;\n\n if (previous.has(to)) {\n path = [];\n let at = to;\n\n while (at !== from) {\n const step = previous.get(at);\n\n if (step === undefined) {\n path = null;\n break;\n }\n\n path.unshift(step.name);\n at = step.sort;\n }\n }\n\n this.coercionPaths.set(key, path);\n return path;\n }\n\n /**\n * Parse surface text. `lints: false` skips the spec's refusal\n * conventions (bracket discipline, chain refusal, closed sentences) —\n * for reading text that is grammatical but not surface-idiomatic.\n *\n * `mode: \"engine\"` reads this library's own engine-mode output instead:\n * the theory's delimiters rather than the surface set, no elaboration,\n * and lints off unless asked for. Engine text is whitespace-separated\n * and fully parenthesized, so it needs no wide delimiter set — and a\n * surface elab rule would misread it, Quine's `( ?x:var )` happily\n * eating the `(x)` inside `(F (x))`.\n */\n parse(\n text: string,\n options: { readonly lints?: boolean; readonly mode?: ParseMode } = {},\n ): ParseResult {\n const mode = options.mode ?? \"surface\";\n const lints = options.lints ?? mode === \"surface\";\n\n if (mode === \"engine\") {\n return new Parse(this, this.engineScanner, text, lints).run();\n }\n\n if (this.spec.elabRules.length === 0) {\n return new Parse(this, this.scanner, text, lints).run();\n }\n\n // Elaborate first, then map every span in the outcome back through\n // the origin map, so nothing downstream sees elaborated offsets.\n const elaborated = elaborate(this, text);\n const result = new Parse(\n this,\n this.scanner,\n elaborated.text,\n lints,\n ).run();\n const diagnostics = result.diagnostics.map((diag) => ({\n ...diag,\n span: remapSpan(elaborated.origin, diag.span),\n }));\n\n if (!result.ok) {\n return { ok: false, diagnostics };\n }\n\n const remapTerm = (term: Term): Term =>\n term.kind === \"variable\"\n ? { ...term, span: remapSpan(elaborated.origin, term.span) }\n : {\n ...term,\n span: remapSpan(elaborated.origin, term.span),\n args: term.args.map(remapTerm),\n };\n\n return { ok: true, term: remapTerm(result.term), diagnostics };\n }\n}\n\nclass Parse {\n private position = 0;\n private diagnostics: Diagnostic[] = [];\n /**\n * The deepest-reaching diagnostic a failed trial produced. When a\n * fallback reading succeeds but leaves trailing input short of where a\n * higher-priority reading got to, that earlier, more specific error is\n * the one the writer should see — `F(a` is an unclosed argument list,\n * not a stray `(` after the sentence letter F.\n */\n private bestTrialFailure: { end: number; diag: Diagnostic } | null = null;\n\n constructor(\n private readonly lang: SurfaceLanguage,\n private readonly scanner: Scanner,\n private readonly text: string,\n private readonly lintsEnabled: boolean,\n ) {}\n\n run(): ParseResult {\n const parsed = this.parseExpr(0);\n\n if (parsed !== null) {\n const point = this.scanner.at(this.text, this.position);\n\n if (!point.atEnd) {\n const trial = this.bestTrialFailure;\n\n if (trial !== null && trial.end > point.start) {\n this.diagnostics.push(trial.diag);\n } else if (point.readings.length === 0) {\n this.report(\n \"unrecognized_chunk\",\n { chunk: point.chunk },\n { start: point.start, end: point.start + point.chunk.length },\n );\n } else {\n const reading = point.readings[0];\n const token =\n reading === undefined\n ? (this.text[point.start] ?? \"\")\n : reading.kind === \"token\"\n ? reading.token\n : reading.name;\n\n this.report(\n \"unexpected_token\",\n { token },\n {\n start: point.start,\n end: point.start + (reading?.length ?? 1),\n },\n );\n }\n\n return { ok: false, diagnostics: this.diagnostics };\n }\n }\n\n if (parsed === null) {\n if (this.diagnostics.length === 0) {\n this.report(\"expected_formula\", {}, { start: 0, end: 0 });\n }\n\n return { ok: false, diagnostics: this.diagnostics };\n }\n\n let term = parsed;\n const provable = this.lang.provableSort;\n\n if (provable !== null && term.sort !== provable) {\n const wrapped = this.coerceTerm(term, provable);\n\n if (wrapped === null) {\n this.report(\"term_not_sentence\", { actual: term.sort }, term.span);\n return { ok: false, diagnostics: this.diagnostics };\n }\n\n term = wrapped;\n }\n\n if (this.lintsEnabled) {\n this.lint(term);\n }\n\n if (this.diagnostics.length > 0) {\n return { ok: false, diagnostics: this.diagnostics };\n }\n\n return { ok: true, term, diagnostics: this.diagnostics };\n }\n\n // ── plumbing ──────────────────────────────────────────────────────────\n\n private report(\n id: string,\n params: Record<string, string>,\n span: Span,\n ): null {\n this.diagnostics.push(diagnostic(id, TEMPLATES[id] ?? id, params, span));\n return null;\n }\n\n /** Run a trial parse; on failure, rewind input and drop its diagnostics. */\n private attempt<T>(body: () => T | null): T | null {\n const position = this.position;\n const kept = this.diagnostics.length;\n const result = body();\n\n if (result === null) {\n for (const diag of this.diagnostics.slice(kept)) {\n if (diag.span.end > (this.bestTrialFailure?.end ?? -1)) {\n this.bestTrialFailure = { end: diag.span.end, diag };\n }\n }\n\n this.position = position;\n this.diagnostics.length = kept;\n }\n\n return result;\n }\n\n private coerceTerm(term: Term, target: string): Term | null {\n const path = this.lang.coerce(term.sort, target);\n\n if (path === null) {\n return null;\n }\n\n let wrapped = term;\n\n for (const name of path) {\n const info = this.lang.spec.terms.get(name);\n\n wrapped = {\n kind: \"app\",\n term: name,\n args: [wrapped],\n sort: info?.returnSort ?? target,\n span: wrapped.span,\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n };\n }\n\n return wrapped;\n }\n\n private coerceOrReport(term: Term, target: string): Term | null {\n const wrapped = this.coerceTerm(term, target);\n\n if (wrapped === null) {\n return this.report(\n \"sort_mismatch\",\n { actual: term.sort, expected: target },\n term.span,\n );\n }\n\n return wrapped;\n }\n\n // ── the precedence parser ─────────────────────────────────────────────\n\n private parseExpr(min: number): Term | null {\n let left = this.parsePrimary(min);\n\n if (left === null) {\n return null;\n }\n\n for (;;) {\n const point = this.scanner.at(this.text, this.position);\n\n if (point.atEnd) {\n return left;\n }\n\n const reading = point.readings.find((r) => r.kind === \"token\");\n\n if (reading === undefined || reading.kind !== \"token\") {\n return left;\n }\n\n const entry = this.lang.infixes.get(reading.token);\n\n if (entry === undefined || entry.prec < min) {\n return left;\n }\n\n this.position = point.start + reading.length;\n\n const right = this.parseExpr(\n entry.fixity === \"infixl\" ? entry.prec + 1 : entry.prec,\n );\n\n if (right === null) {\n return null;\n }\n\n const binders = entry.info.binders;\n const leftSort = binderSort(binders[0]);\n const rightSort = binderSort(binders[1]);\n const coercedLeft = this.coerceOrReport(left, leftSort);\n const coercedRight = this.coerceOrReport(right, rightSort);\n\n if (coercedLeft === null || coercedRight === null) {\n return null;\n }\n\n left = {\n kind: \"app\",\n term: entry.info.name,\n args: [coercedLeft, coercedRight],\n sort: entry.info.returnSort,\n span: { start: left.span.start, end: right.span.end },\n grouped: false,\n fixity: entry.fixity,\n prec: entry.prec,\n token: reading.token,\n } satisfies AppTerm;\n }\n }\n\n private parsePrimary(min: number): Term | null {\n const point = this.scanner.at(this.text, this.position);\n\n if (point.atEnd) {\n return this.report(\n \"expected_formula\",\n {},\n {\n start: point.start,\n end: point.start,\n },\n );\n }\n\n // The chunk's boundaries were fixed by the delimiters, so the whole of\n // what the writer wrote between them is what nothing recognizes — not\n // just its first character.\n if (point.readings.length === 0) {\n return this.report(\n \"unrecognized_chunk\",\n { chunk: point.chunk },\n { start: point.start, end: point.start + point.chunk.length },\n );\n }\n\n // Try each reading with backtracking; if none succeeds, re-run the\n // first viable one so its diagnostics — the most specific available —\n // are the ones the writer sees.\n const viable = point.readings.filter((reading) =>\n this.isViablePrimary(reading),\n );\n\n for (const reading of viable) {\n const result = this.attempt(() =>\n this.parsePrimaryReading(point.start, reading, min),\n );\n\n if (result !== null) {\n return result;\n }\n }\n\n const first = viable[0];\n\n if (first !== undefined) {\n return this.parsePrimaryReading(point.start, first, min);\n }\n\n const reading = point.readings[0];\n const token =\n reading?.kind === \"token\" ? reading.token : (reading?.name ?? \"\");\n\n return this.report(\n \"expected_formula_found\",\n { token },\n {\n start: point.start,\n end: point.start + (reading?.length ?? 1),\n },\n );\n }\n\n private isViablePrimary(reading: Reading): boolean {\n if (reading.kind === \"name\") {\n return true;\n }\n\n return (\n this.lang.closeOf.has(reading.token) ||\n this.lang.heads.has(reading.token)\n );\n }\n\n private parsePrimaryReading(\n start: number,\n reading: Reading,\n min: number,\n ): Term | null {\n if (reading.kind === \"name\") {\n return this.parseName(start, reading);\n }\n\n const close = this.lang.closeOf.get(reading.token);\n\n if (close !== undefined) {\n return this.parseGroup(start, close, reading.length);\n }\n\n const head = this.lang.heads.get(reading.token);\n\n if (head === undefined) {\n return this.report(\n \"expected_formula_found\",\n { token: reading.token },\n {\n start,\n end: start + reading.length,\n },\n );\n }\n\n this.position = start + reading.length;\n\n return head.kind === \"prefix\"\n ? this.parsePrefix(start, reading.token, head, min)\n : this.parseGeneral(start, reading.token, head, min);\n }\n\n private parseGroup(\n start: number,\n close: string,\n openLength: number,\n ): Term | null {\n this.position = start + openLength;\n\n const inner = this.parseExpr(0);\n\n if (inner === null) {\n return null;\n }\n\n const point = this.scanner.at(this.text, this.position);\n const reading = point.readings.find(\n (r) => r.kind === \"token\" && r.token === close,\n );\n\n if (reading === undefined) {\n return this.report(\n \"expected_bracket\",\n { bracket: close },\n {\n start: point.start,\n end: point.start + 1,\n },\n );\n }\n\n this.position = point.start + reading.length;\n\n return {\n ...inner,\n grouped: true,\n span: { start, end: this.position },\n };\n }\n\n private parsePrefix(\n start: number,\n token: string,\n entry: PrefixEntry,\n min: number,\n ): Term | null {\n if (precNum(entry.prec) < min) {\n return this.report(\n \"needs_parentheses\",\n { token },\n {\n start,\n end: this.position,\n },\n );\n }\n\n const binders = entry.info.binders;\n const args: Term[] = [];\n\n for (let i = 0; i < binders.length; i += 1) {\n const binder = binders[i];\n\n if (binder === undefined) {\n continue;\n }\n\n if (binder.binds) {\n const variable = this.expectBoundVariable(binderSort(binder));\n\n if (variable === null) {\n return null;\n }\n\n args.push(variable);\n continue;\n }\n\n // mm0.md: a prefix notation's intermediate arguments parse at max,\n // its last at the notation's own precedence.\n const slotPrec =\n i === binders.length - 1\n ? precNum(entry.prec)\n : Number.POSITIVE_INFINITY;\n const arg = this.parseExpr(slotPrec);\n\n if (arg === null) {\n return null;\n }\n\n const coerced = this.coerceOrReport(arg, binderSort(binder));\n\n if (coerced === null) {\n return null;\n }\n\n args.push(coerced);\n }\n\n return {\n kind: \"app\",\n term: entry.info.name,\n args,\n sort: entry.info.returnSort,\n span: {\n start,\n end: args[args.length - 1]?.span.end ?? this.position,\n },\n grouped: false,\n fixity: \"prefix\",\n prec: precNum(entry.prec),\n token,\n };\n }\n\n private parseGeneral(\n start: number,\n token: string,\n entry: GeneralEntry,\n min: number,\n ): Term | null {\n const headPrec = this.headPrecOf(token);\n\n if (headPrec !== null && headPrec < min) {\n return this.report(\n \"needs_parentheses\",\n { token },\n {\n start,\n end: this.position,\n },\n );\n }\n\n const byIndex = new Map<number, Term>();\n\n for (const part of entry.parts) {\n if (part.kind === \"constant\") {\n const point = this.scanner.at(this.text, this.position);\n const reading = point.readings.find(\n (r) => r.kind === \"token\" && r.token === part.token,\n );\n\n if (reading === undefined) {\n return this.report(\n \"expected_bracket\",\n { bracket: part.token },\n {\n start: point.start,\n end: point.start + 1,\n },\n );\n }\n\n this.position = point.start + reading.length;\n continue;\n }\n\n const { binder, index, prec } = part.slot;\n\n if (binder.binds) {\n const variable = this.expectBoundVariable(binderSort(binder));\n\n if (variable === null) {\n return null;\n }\n\n byIndex.set(index, variable);\n continue;\n }\n\n const arg = this.parseExpr(prec);\n\n if (arg === null) {\n return null;\n }\n\n const coerced = this.coerceOrReport(arg, binderSort(binder));\n\n if (coerced === null) {\n return null;\n }\n\n byIndex.set(index, coerced);\n }\n\n const args: Term[] = [];\n\n for (let i = 0; i < entry.info.binders.length; i += 1) {\n const arg = byIndex.get(i);\n\n if (arg === undefined) {\n return this.report(\n \"spec_notation_incomplete\",\n { term: entry.info.name },\n { start, end: this.position },\n );\n }\n\n args.push(arg);\n }\n\n return {\n kind: \"app\",\n term: entry.info.name,\n args,\n sort: entry.info.returnSort,\n span: { start, end: args[args.length - 1]?.span.end ?? this.position },\n grouped: false,\n fixity: \"general\",\n prec: headPrec,\n token,\n };\n }\n\n private headPrecOf(token: string): number | null {\n for (const notation of this.lang.spec.notations) {\n if (notation.form === \"general\") {\n const head = notation.literals[0];\n\n if (head?.kind === \"constant\" && head.token === token) {\n return precNum(head.prec);\n }\n }\n }\n\n return null;\n }\n\n private expectBoundVariable(sort: string): VariableTerm | null {\n const point = this.scanner.at(this.text, this.position);\n const reading = point.readings.find(\n (r): r is Reading & { kind: \"name\" } =>\n r.kind === \"name\" && r.ref.kind === \"var\" && r.ref.sort === sort,\n );\n\n if (reading === undefined || reading.kind !== \"name\") {\n return this.report(\n \"expected_variable\",\n {},\n {\n start: point.start,\n end: point.start + 1,\n },\n );\n }\n\n this.position = point.start + reading.length;\n\n return {\n kind: \"variable\",\n name: reading.name,\n sort,\n span: { start: point.start, end: this.position },\n grouped: false,\n binder: true,\n };\n }\n\n /**\n * A lexicon name: a `@vars` token (a variable of its sort), or a\n * declared term with no notation of its own — a sentence letter,\n * predicate, function symbol, or constant. A term's arguments come\n * parenthesized (application syntax, so the argument is not marked\n * `grouped` and the binary-only lint does not apply inside; the\n * canonical pair is always the first declared one), or juxtaposed when\n * the argument sort has an `@syntax juxtaposed` combiner, or not at all\n * when it has an `@syntax elided` term. Context settles the `A`-as-∀\n * ambiguity exactly as in Carnap: the quantifier reading was tried\n * first, and fell through to here only if it failed.\n */\n private parseName(\n start: number,\n reading: Reading & { kind: \"name\" },\n ): Term | null {\n this.position = start + reading.length;\n\n if (reading.ref.kind === \"var\") {\n return {\n kind: \"variable\",\n name: reading.name,\n sort: reading.ref.sort,\n span: { start, end: this.position },\n grouped: false,\n binder: false,\n };\n }\n\n const info = this.lang.spec.terms.get(reading.ref.term);\n\n if (info === undefined) {\n return this.report(\n \"expected_formula_found\",\n { token: reading.name },\n { start, end: start + reading.length },\n );\n }\n\n const argBinders = info.binders.filter((binder) => !binder.binds);\n const args: Term[] = [];\n\n for (const binder of argBinders) {\n const target = binderSort(binder);\n const point = this.scanner.at(this.text, this.position);\n const open = this.lang.spec.groupingPairs[0]?.[0] ?? \"(\";\n const close = this.lang.spec.groupingPairs[0]?.[1] ?? \")\";\n const openReading = point.readings.find(\n (r) => r.kind === \"token\" && r.token === open,\n );\n\n if (openReading !== undefined) {\n this.position = point.start + openReading.length;\n\n const arg = this.parseExpr(0);\n\n if (arg === null) {\n return null;\n }\n\n const closePoint = this.scanner.at(this.text, this.position);\n const closeReading = closePoint.readings.find(\n (r) => r.kind === \"token\" && r.token === close,\n );\n\n if (closeReading === undefined) {\n return this.report(\n \"expected_bracket\",\n { bracket: close },\n {\n start: closePoint.start,\n end: closePoint.start + 1,\n },\n );\n }\n\n this.position = closePoint.start + closeReading.length;\n\n const coerced = this.coerceOrReport(arg, target);\n\n if (coerced === null) {\n return null;\n }\n\n args.push(coerced);\n continue;\n }\n\n // Juxtaposed gluing — `Fxy`, the pre-2019 forallx shape. Operands\n // (self-delimiting single-token expressions) are consumed greedily\n // while they coerce into the argument sort; several fold through\n // the sort's declared combiner.\n const combiner =\n argBinders.length === 1\n ? this.lang.juxtaposedOf.get(target)\n : undefined;\n\n if (combiner !== undefined) {\n const leaves: Term[] = [];\n\n for (;;) {\n const leaf = this.glueOperand(target);\n\n if (leaf === null) {\n break;\n }\n\n leaves.push(leaf);\n }\n\n const first = leaves[0];\n\n if (first !== undefined) {\n let folded = first;\n\n for (const leaf of leaves.slice(1)) {\n folded = {\n kind: \"app\",\n term: combiner.name,\n args: [folded, leaf],\n sort: combiner.returnSort,\n span: { start: folded.span.start, end: leaf.span.end },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n };\n }\n\n args.push(folded);\n continue;\n }\n // No operand at all: fall through to elision, so a bare letter\n // can still be a sentence letter in a juxtaposed dialect.\n }\n\n const elided = this.lang.elidedOf.get(target);\n\n if (elided !== undefined) {\n args.push({\n kind: \"app\",\n term: elided.name,\n args: [],\n sort: elided.returnSort,\n span: { start, end: start + reading.length },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n });\n continue;\n }\n\n return this.report(\n \"expected_formula_found\",\n { token: reading.name },\n { start, end: start + reading.length },\n );\n }\n\n return {\n kind: \"app\",\n term: reading.name,\n args,\n sort: info.returnSort,\n span: { start, end: this.position },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n };\n }\n\n /**\n * One juxtaposed operand: a self-delimiting single-token expression — a\n * variable, a nullary lexicon name, or a nullary notation (an\n * empty-set-style constant) — whose sort coerces into the target.\n * Anything larger (a parenthesized group, a term applied to arguments\n * of its own) is deliberately not an operand yet: nested juxtaposition\n * is ambiguous under variadic sequences and stays deferred.\n */\n private glueOperand(target: string): Term | null {\n const point = this.scanner.at(this.text, this.position);\n\n for (const reading of point.readings) {\n if (reading.kind === \"name\") {\n if (reading.ref.kind === \"var\") {\n if (this.lang.coerce(reading.ref.sort, target) === null) {\n continue;\n }\n\n this.position = point.start + reading.length;\n\n return this.coerceOrReport(\n {\n kind: \"variable\",\n name: reading.name,\n sort: reading.ref.sort,\n span: { start: point.start, end: this.position },\n grouped: false,\n binder: false,\n },\n target,\n );\n }\n\n const info = this.lang.spec.terms.get(reading.ref.term);\n\n if (\n info === undefined ||\n info.binders.some((binder) => !binder.binds) ||\n this.lang.coerce(info.returnSort, target) === null\n ) {\n continue;\n }\n\n this.position = point.start + reading.length;\n\n return this.coerceOrReport(\n {\n kind: \"app\",\n term: info.name,\n args: [],\n sort: info.returnSort,\n span: { start: point.start, end: this.position },\n grouped: false,\n fixity: null,\n prec: null,\n token: null,\n },\n target,\n );\n }\n\n const head = this.lang.heads.get(reading.token);\n\n if (\n head?.kind === \"general\" &&\n head.parts.length === 0 &&\n head.info.binders.length === 0 &&\n this.lang.coerce(head.info.returnSort, target) !== null\n ) {\n this.position = point.start + reading.length;\n\n return this.coerceOrReport(\n {\n kind: \"app\",\n term: head.info.name,\n args: [],\n sort: head.info.returnSort,\n span: { start: point.start, end: this.position },\n grouped: false,\n fixity: \"general\",\n prec: null,\n token: reading.token,\n },\n target,\n );\n }\n }\n\n return null;\n }\n\n // ── lints ─────────────────────────────────────────────────────────────\n\n private lint(term: Term): void {\n const lints = this.lang.spec.lints;\n const assocNone = this.lang.spec.assocNone;\n const provable = this.lang.provableSort;\n\n walkTerm(term, (node, bound) => {\n if (node.kind === \"variable\") {\n // A leaf of a sort no quantifier binds — a constant from a\n // `@vars` pool, like Calgary's names — cannot be *free*: freedom\n // is only meaningful where binding is possible.\n if (\n lints.includes(\"closed-sentences\") &&\n !node.binder &&\n this.lang.bindableSorts.has(node.sort) &&\n !bound.has(node.name)\n ) {\n this.report(\"free_variable\", { name: node.name }, node.span);\n }\n\n return;\n }\n\n // The chain refusal: an operand produced by an operator at the same\n // assoc-none level, without its own brackets, has no reading.\n if (\n typeof node.prec === \"number\" &&\n assocNone.has(node.prec) &&\n (node.fixity === \"infixl\" || node.fixity === \"infixr\")\n ) {\n for (const arg of node.args) {\n if (\n arg.kind === \"app\" &&\n typeof arg.prec === \"number\" &&\n arg.prec === node.prec &&\n (arg.fixity === \"infixl\" || arg.fixity === \"infixr\") &&\n !arg.grouped\n ) {\n const operator =\n arg.token ?? this.canonicalToken(arg.term) ?? arg.term;\n\n this.report(\"chain_refused\", { operator }, arg.span);\n }\n }\n }\n\n if (lints.includes(\"parenthesize-binary-only\") && node.grouped) {\n const binderSorts = this.lang.spec.terms\n .get(node.term)\n ?.binders.map(binderSort);\n const connective =\n (node.fixity === \"infixl\" || node.fixity === \"infixr\") &&\n provable !== null &&\n binderSorts !== undefined &&\n binderSorts.length === 2 &&\n binderSorts.every((sort) => sort === provable);\n\n if (!connective) {\n this.report(\n \"group_binary_only\",\n {},\n {\n start: node.span.start,\n end: node.span.start + 1,\n },\n );\n }\n }\n });\n }\n\n /** The last-declared notation token for a term — its canonical spelling. */\n private canonicalToken(term: string): string | null {\n let token: string | null = null;\n\n for (const notation of this.lang.spec.notations) {\n if (notation.term === term && notation.form === \"simple\") {\n token = notation.token;\n }\n }\n\n return token;\n }\n}\n"]}
@@ -65,6 +65,17 @@ export type SyntaxAnnotation = {
65
65
  /** A bidirectional token rule: elaborate in, delaborate out. */
66
66
  readonly kind: "elab";
67
67
  readonly rule: ElabRule;
68
+ } | {
69
+ /**
70
+ * Surface delimiters: where a chunk of *student* input ends. Same
71
+ * shape and same meaning as MM0's own `delimiter` statement, and
72
+ * unioned with it — but an entry may be any string, not just a single
73
+ * byte, so `∧` and `<->` can self-delimit where the engine's
74
+ * byte table cannot hold them.
75
+ */
76
+ readonly kind: "delimiter";
77
+ readonly left: readonly string[];
78
+ readonly right: readonly string[];
68
79
  } | {
69
80
  /** Supplied when an argument of its sort is missing; drops on print. */
70
81
  readonly kind: "elided";
@@ -32,6 +32,8 @@ const TEMPLATES = {
32
32
  syntax_bad_assoc_none: "@syntax assoc-none wants one precedence number",
33
33
  syntax_unknown_lint: "unknown lint {name}; known lints: {known}",
34
34
  syntax_bad_display: "@syntax display wants drop-outer-parens or rotate-brackets <pairs…>",
35
+ syntax_bad_delimiter: "@syntax delimiter wants: delimiter $ <entries…> $, or delimiter $ <left…> $ $ <right…> $",
36
+ syntax_empty_delimiter: "a @syntax delimiter math string must list entries",
35
37
  syntax_bad_elab: "@syntax elab wants: elab $ <pattern> $ => $ <template> $ [input-only]",
36
38
  syntax_bad_pattern_element: "cannot read pattern element {element}",
37
39
  syntax_bad_template_element: "cannot read template element {element}",
@@ -104,6 +106,17 @@ function parseTemplate(text) {
104
106
  return elements;
105
107
  }
106
108
  const ELAB = /^\$(.*?)\$\s*=>\s*\$(.*?)\$\s*(input-only)?\s*$/s;
109
+ /** `$ … $`, or `$ left… $ $ right… $` — MM0's own two shapes. */
110
+ const DELIMITER = /^\$([^$]*)\$(?:\s*\$([^$]*)\$)?\s*$/;
111
+ /**
112
+ * Every entry written out, one at a time. There is deliberately no range
113
+ * shorthand: a spike of `A-Z`-style ranges read `<->` as the range `<`…`>`
114
+ * and silently turned one delimiter into three. A declaration that decides
115
+ * how input is cut up is worth its verbosity.
116
+ */
117
+ function delimiterEntries(text) {
118
+ return text.split(/\s+/).filter((entry) => entry.length > 0);
119
+ }
107
120
  /**
108
121
  * Parse one annotation payload (the text after `--|`). Returns null for a
109
122
  * foreign annotation — anything that does not begin `@syntax`.
@@ -131,6 +144,19 @@ export function parseSyntaxAnnotation(text, span) {
131
144
  }
132
145
  return ok({ kind: "brackets", pairs });
133
146
  }
147
+ case "delimiter": {
148
+ const match = DELIMITER.exec(rest.slice("delimiter".length).trim());
149
+ if (match === null) {
150
+ return fail("syntax_bad_delimiter", {}, span);
151
+ }
152
+ const first = delimiterEntries(match[1] ?? "");
153
+ const second = match[2] === undefined ? null : delimiterEntries(match[2]);
154
+ if (first.length === 0 || second?.length === 0) {
155
+ return fail("syntax_empty_delimiter", {}, span);
156
+ }
157
+ // One list means both sides, as in MM0.
158
+ return ok({ kind: "delimiter", left: first, right: second ?? first });
159
+ }
134
160
  case "assoc-none": {
135
161
  const number = words[1];
136
162
  if (words.length !== 2 ||