@aufbau/syntax 0.0.2 → 0.0.3

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.map CHANGED
@@ -1 +1 @@
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,CAAC,IAAI,CAAC;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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"]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Content":["/**\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 /**\n * The first sort the file marks `provable` — MM0's own way of saying\n * \"assertable\". It is `parse`'s default target sort and nothing else; a\n * caller that wants another sort names it, and a file with several\n * provable sorts is expected to.\n */\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 connective: an infix constructor closed over a `provable` sort —\n * two arguments of that sort, and a result of the same one. This is the\n * class forallx's bracket convention and the display printer's spacing\n * both key on: `∧` is one; `=` over terms is not (its arguments are of\n * another sort); a turnstile from two formulas to a judgement is not\n * (it does not return what it takes); and the argument comma is not\n * (`seq` is not provable), which is what keeps `R(a,b)` from printing\n * as `R((a , b))`.\n *\n * Nothing here privileges one sort. A theory that states judgements in\n * a provable sort of their own gets a judgement-level conjunction\n * spaced and bracketed on the same terms as a formula-level one, which\n * is right.\n */\n isConnective(term: string): boolean {\n const info = this.spec.terms.get(term);\n const notation = this.canonical.get(term);\n\n return (\n info !== undefined &&\n this.isProvableSort(info.returnSort) &&\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 === info.returnSort,\n )\n );\n }\n\n /** Whether the sort carries MM0's `provable` modifier. */\n isProvableSort(sort: string): boolean {\n return this.spec.sorts.get(sort)?.modifiers.includes(\"provable\") === true;\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. `sort` is what the result is read at: the text\n * must parse to that sort, or coerce into it, or it is refused. It\n * defaults to `provableSort` — the first sort the file marks `provable`,\n * MM0's own way of saying \"assertable\" — which is the whole story for a\n * spec with one such sort. A file with several (a theory whose\n * judgements are `Γ ⊢ φ` in a sort of their own) has a genuine choice to\n * make per call, and the caller is who knows: a translation exercise\n * reads at the formula sort, a proof widget at the judgement sort.\n *\n * `lints: false` skips the spec's refusal conventions (bracket\n * discipline, chain refusal, closed sentences) — for reading text that\n * 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: {\n readonly lints?: boolean;\n readonly mode?: ParseMode;\n readonly sort?: string;\n } = {},\n ): ParseResult {\n const mode = options.mode ?? \"surface\";\n const lints = options.lints ?? mode === \"surface\";\n const sort = options.sort ?? this.provableSort;\n\n if (mode === \"engine\") {\n return new Parse(this, this.engineScanner, text, lints, sort).run();\n }\n\n if (this.spec.elabRules.length === 0) {\n return new Parse(this, this.scanner, text, lints, sort).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 sort,\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 /** The sort the result is read at; null leaves the target open. */\n private readonly sort: string | null,\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 target = this.sort;\n\n if (target !== null && term.sort !== target) {\n const wrapped = this.coerceTerm(term, target);\n\n if (wrapped === null) {\n this.report(\n \"term_not_sentence\",\n { actual: term.sort, expected: target },\n term.span,\n );\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\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 // The same class the printer brackets — see `isConnective`, which\n // this reads through the parse's own fixity rather than the\n // canonical notation's.\n const connective =\n (node.fixity === \"infixl\" || node.fixity === \"infixr\") &&\n this.lang.isConnective(node.term);\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"]}
@@ -14,7 +14,7 @@
14
14
  * share one sort (adjacency of that sort's expressions denotes it);
15
15
  * - `elided` attaches to a nullary term (supplied when an argument of
16
16
  * its sort is missing, dropped again when printing);
17
- * - `role` attaches to a `term` or `def`;
17
+ * - `role` attaches to a `sort`, a `term`, or a `def`;
18
18
  * - everything else is spec-wide and may sit on any statement.
19
19
  *
20
20
  * The lexicon itself needs no `@syntax` at all: letters are ordinary term
@@ -14,7 +14,7 @@
14
14
  * share one sort (adjacency of that sort's expressions denotes it);
15
15
  * - `elided` attaches to a nullary term (supplied when an argument of
16
16
  * its sort is missing, dropped again when printing);
17
- * - `role` attaches to a `term` or `def`;
17
+ * - `role` attaches to a `sort`, a `term`, or a `def`;
18
18
  * - everything else is spec-wide and may sit on any statement.
19
19
  *
20
20
  * The lexicon itself needs no `@syntax` at all: letters are ordinary term
@@ -1 +1 @@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,EACtC,IAAI,CACL,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["/**\n * The `@syntax` annotation vocabulary — the \"little extra metadata\" that\n * turns an MM0 theory into a full surface-language spec.\n *\n * Annotations ride MM0's `--|` doc-comment channel, the same one Aufbau uses\n * for `@acui`, `@congr`, `@rewrite`, and the rest. Anything that is not\n * `@syntax` is *foreign*: preserved untouched for whoever owns it, never\n * interpreted here. The library also owns stripping `@syntax` lines before a theory is\n * handed to the engine, which currently rejects annotations it does not\n * know.\n *\n * Attachment rules (checked by the spec builder, not here):\n * - `juxtaposed` attaches to a binary term whose arguments and result\n * share one sort (adjacency of that sort's expressions denotes it);\n * - `elided` attaches to a nullary term (supplied when an argument of\n * its sort is missing, dropped again when printing);\n * - `role` attaches to a `term` or `def`;\n * - everything else is spec-wide and may sit on any statement.\n *\n * The lexicon itself needs no `@syntax` at all: letters are ordinary term\n * declarations, and variables ride the engine's own `@vars` annotation.\n */\n\nimport { type Diagnostic, diagnostic, type Span } from \"../diagnostics.js\";\n\nexport const LINT_NAMES = [\n \"parenthesize-binary-only\",\n \"closed-sentences\",\n] as const;\n\nexport type LintName = (typeof LINT_NAMES)[number];\n\n/** A capture in an elab pattern: `?ts:tm+` — name, class, quantifier. */\nexport interface RuleCapture {\n readonly kind: \"capture\";\n readonly name: string;\n /** A sort name; a leaf whose sort coerces into it matches. */\n readonly class: string;\n readonly quantifier: \"\" | \"+\" | \"?\";\n}\n\nexport interface RuleLiteral {\n readonly kind: \"literal\";\n readonly token: string;\n}\n\nexport type RulePatternElement = RuleCapture | RuleLiteral;\n\n/** A capture reference in an elab template: `?ts` or joined `?ts,*`. */\nexport interface RuleReference {\n readonly kind: \"reference\";\n readonly name: string;\n /** For a `+` capture, the token to join repeats with; null joins bare. */\n readonly separator: string | null;\n}\n\nexport type RuleTemplateElement = RuleLiteral | RuleReference;\n\nexport interface ElabRule {\n readonly inputOnly: boolean;\n readonly pattern: readonly RulePatternElement[];\n readonly span: Span;\n readonly template: readonly RuleTemplateElement[];\n}\n\nexport type SyntaxAnnotation =\n | {\n readonly kind: \"assoc-none\";\n readonly prec: number;\n }\n | {\n readonly kind: \"brackets\";\n readonly pairs: readonly (readonly [string, string])[];\n }\n | {\n readonly kind: \"display-drop-outer-parens\";\n }\n | {\n readonly kind: \"display-rotate-brackets\";\n readonly pairs: readonly (readonly [string, string])[];\n }\n | {\n /** A bidirectional token rule: elaborate in, delaborate out. */\n readonly kind: \"elab\";\n readonly rule: ElabRule;\n }\n | {\n /**\n * Surface delimiters: where a chunk of *student* input ends. Same\n * shape and same meaning as MM0's own `delimiter` statement, and\n * unioned with it — but an entry may be any string, not just a single\n * byte, so `∧` and `<->` can self-delimit where the engine's\n * byte table cannot hold them.\n */\n readonly kind: \"delimiter\";\n readonly left: readonly string[];\n readonly right: readonly string[];\n }\n | {\n /** Supplied when an argument of its sort is missing; drops on print. */\n readonly kind: \"elided\";\n }\n | {\n /** Adjacency of this combiner's sort denotes it — `Fxy`, `ab`. */\n readonly kind: \"juxtaposed\";\n }\n | {\n readonly kind: \"lint\";\n readonly name: LintName;\n }\n | {\n readonly kind: \"role\";\n readonly role: string;\n };\n\nconst TEMPLATES: Record<string, string> = {\n syntax_unknown_subcommand: \"unknown @syntax subcommand {subcommand}\",\n syntax_bad_flag: \"@syntax {flag} takes no arguments\",\n syntax_bad_brackets:\n \"bracket pairs come as: <open> <close> [<open> <close>…]\",\n syntax_bad_assoc_none: \"@syntax assoc-none wants one precedence number\",\n syntax_unknown_lint: \"unknown lint {name}; known lints: {known}\",\n syntax_bad_display:\n \"@syntax display wants drop-outer-parens or rotate-brackets <pairs…>\",\n syntax_bad_delimiter:\n \"@syntax delimiter wants: delimiter $ <entries…> $, or delimiter $ <left…> $ $ <right…> $\",\n syntax_empty_delimiter: \"a @syntax delimiter math string must list entries\",\n syntax_bad_elab:\n \"@syntax elab wants: elab $ <pattern> $ => $ <template> $ [input-only]\",\n syntax_bad_pattern_element: \"cannot read pattern element {element}\",\n syntax_bad_template_element: \"cannot read template element {element}\",\n syntax_bad_role: \"@syntax role wants one role name\",\n};\n\nfunction fail(\n id: string,\n params: Record<string, string>,\n span: Span,\n): { annotation: null; diagnostic: Diagnostic } {\n const template = TEMPLATES[id] ?? id;\n return {\n annotation: null,\n diagnostic: diagnostic(id, template, params, span),\n };\n}\n\nfunction ok(annotation: SyntaxAnnotation): {\n annotation: SyntaxAnnotation;\n diagnostic: null;\n} {\n return { annotation, diagnostic: null };\n}\n\nexport type SyntaxAnnotationResult =\n | { readonly annotation: SyntaxAnnotation; readonly diagnostic: null }\n | { readonly annotation: null; readonly diagnostic: Diagnostic };\n\nfunction parsePairs(\n words: readonly string[],\n): (readonly [string, string])[] | null {\n if (words.length === 0 || words.length % 2 !== 0) {\n return null;\n }\n\n const pairs: (readonly [string, string])[] = [];\n\n for (let i = 0; i < words.length; i += 2) {\n const open = words[i];\n const close = words[i + 1];\n\n if (open === undefined || close === undefined || open === close) {\n return null;\n }\n\n pairs.push([open, close]);\n }\n\n return pairs;\n}\n\nconst CAPTURE =\n /^\\?([A-Za-z_][A-Za-z0-9_]*):([A-Za-z_][A-Za-z0-9_]*)([+?]?)$/;\nconst REFERENCE = /^\\?([A-Za-z_][A-Za-z0-9_]*)(?:(.)\\*)?$/;\n\nfunction parsePattern(text: string): readonly RulePatternElement[] | string {\n const elements: RulePatternElement[] = [];\n\n for (const word of text.split(/\\s+/).filter((w) => w.length > 0)) {\n if (word.startsWith(\"?\")) {\n const match = CAPTURE.exec(word);\n\n if (match === null) {\n return word;\n }\n\n elements.push({\n kind: \"capture\",\n name: match[1] ?? \"\",\n class: match[2] ?? \"\",\n quantifier: (match[3] ?? \"\") as \"\" | \"+\" | \"?\",\n });\n continue;\n }\n\n elements.push({ kind: \"literal\", token: word });\n }\n\n return elements;\n}\n\nfunction parseTemplate(\n text: string,\n): readonly RuleTemplateElement[] | string {\n const elements: RuleTemplateElement[] = [];\n\n for (const word of text.split(/\\s+/).filter((w) => w.length > 0)) {\n if (word.startsWith(\"?\")) {\n const match = REFERENCE.exec(word);\n\n if (match === null) {\n return word;\n }\n\n elements.push({\n kind: \"reference\",\n name: match[1] ?? \"\",\n separator: match[2] ?? null,\n });\n continue;\n }\n\n elements.push({ kind: \"literal\", token: word });\n }\n\n return elements;\n}\n\nconst ELAB = /^\\$(.*?)\\$\\s*=>\\s*\\$(.*?)\\$\\s*(input-only)?\\s*$/s;\n\n/** `$ … $`, or `$ left… $ $ right… $` — MM0's own two shapes. */\nconst DELIMITER = /^\\$([^$]*)\\$(?:\\s*\\$([^$]*)\\$)?\\s*$/;\n\n/**\n * Every entry written out, one at a time. There is deliberately no range\n * shorthand: a spike of `A-Z`-style ranges read `<->` as the range `<`…`>`\n * and silently turned one delimiter into three. A declaration that decides\n * how input is cut up is worth its verbosity.\n */\nfunction delimiterEntries(text: string): string[] {\n return text.split(/\\s+/).filter((entry) => entry.length > 0);\n}\n\n/**\n * Parse one annotation payload (the text after `--|`). Returns null for a\n * foreign annotation — anything that does not begin `@syntax`.\n */\nexport function parseSyntaxAnnotation(\n text: string,\n span: Span,\n): SyntaxAnnotationResult | null {\n const trimmed = text.trim();\n\n if (!trimmed.startsWith(\"@syntax\")) {\n return null;\n }\n\n const rest = trimmed.slice(\"@syntax\".length).trim();\n const words = rest.split(/\\s+/).filter((w) => w.length > 0);\n const subcommand = words[0];\n\n switch (subcommand) {\n case \"juxtaposed\":\n case \"elided\": {\n if (words.length !== 1) {\n return fail(\"syntax_bad_flag\", { flag: subcommand }, span);\n }\n\n return ok({ kind: subcommand });\n }\n\n case \"brackets\": {\n const pairs = parsePairs(words.slice(1));\n\n if (pairs === null) {\n return fail(\"syntax_bad_brackets\", {}, span);\n }\n\n return ok({ kind: \"brackets\", pairs });\n }\n\n case \"delimiter\": {\n const match = DELIMITER.exec(rest.slice(\"delimiter\".length).trim());\n\n if (match === null) {\n return fail(\"syntax_bad_delimiter\", {}, span);\n }\n\n const first = delimiterEntries(match[1] ?? \"\");\n const second =\n match[2] === undefined ? null : delimiterEntries(match[2]);\n\n if (first.length === 0 || second?.length === 0) {\n return fail(\"syntax_empty_delimiter\", {}, span);\n }\n\n // One list means both sides, as in MM0.\n return ok({ kind: \"delimiter\", left: first, right: second ?? first });\n }\n\n case \"assoc-none\": {\n const number = words[1];\n\n if (\n words.length !== 2 ||\n number === undefined ||\n !/^\\d+$/.test(number)\n ) {\n return fail(\"syntax_bad_assoc_none\", {}, span);\n }\n\n return ok({ kind: \"assoc-none\", prec: Number.parseInt(number, 10) });\n }\n\n case \"lint\": {\n const name = words[1];\n\n if (\n words.length !== 2 ||\n name === undefined ||\n !(LINT_NAMES as readonly string[]).includes(name)\n ) {\n return fail(\n \"syntax_unknown_lint\",\n { name: name ?? \"\", known: LINT_NAMES.join(\", \") },\n span,\n );\n }\n\n return ok({ kind: \"lint\", name: name as LintName });\n }\n\n case \"display\": {\n if (words[1] === \"drop-outer-parens\" && words.length === 2) {\n return ok({ kind: \"display-drop-outer-parens\" });\n }\n\n if (words[1] === \"rotate-brackets\") {\n const pairs = parsePairs(words.slice(2));\n\n if (pairs !== null) {\n return ok({ kind: \"display-rotate-brackets\", pairs });\n }\n }\n\n return fail(\"syntax_bad_display\", {}, span);\n }\n\n case \"elab\": {\n const match = ELAB.exec(rest.slice(\"elab\".length).trim());\n\n if (match === null) {\n return fail(\"syntax_bad_elab\", {}, span);\n }\n\n const pattern = parsePattern(match[1] ?? \"\");\n\n if (typeof pattern === \"string\") {\n return fail(\"syntax_bad_pattern_element\", { element: pattern }, span);\n }\n\n const template = parseTemplate(match[2] ?? \"\");\n\n if (typeof template === \"string\") {\n return fail(\n \"syntax_bad_template_element\",\n { element: template },\n span,\n );\n }\n\n return ok({\n kind: \"elab\",\n rule: {\n inputOnly: match[3] === \"input-only\",\n pattern,\n span,\n template,\n },\n });\n }\n\n case \"role\": {\n const role = words[1];\n\n if (words.length !== 2 || role === undefined) {\n return fail(\"syntax_bad_role\", {}, span);\n }\n\n return ok({ kind: \"role\", role });\n }\n\n default:\n return fail(\n \"syntax_unknown_subcommand\",\n { subcommand: subcommand ?? \"(none)\" },\n span,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"annotations.js","sourceRoot":"","sources":["../../src/reader/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAmB,UAAU,EAAa,MAAM,mBAAmB,CAAC;AAE3E,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,0BAA0B;IAC1B,kBAAkB;CACV,CAAC;AAuFX,MAAM,SAAS,GAA2B;IACxC,yBAAyB,EAAE,yCAAyC;IACpE,eAAe,EAAE,mCAAmC;IACpD,mBAAmB,EACjB,yDAAyD;IAC3D,qBAAqB,EAAE,gDAAgD;IACvE,mBAAmB,EAAE,2CAA2C;IAChE,kBAAkB,EAChB,qEAAqE;IACvE,oBAAoB,EAClB,0FAA0F;IAC5F,sBAAsB,EAAE,mDAAmD;IAC3E,eAAe,EACb,uEAAuE;IACzE,0BAA0B,EAAE,uCAAuC;IACnE,2BAA2B,EAAE,wCAAwC;IACrE,eAAe,EAAE,kCAAkC;CACpD,CAAC;AAEF,SAAS,IAAI,CACX,EAAU,EACV,MAA8B,EAC9B,IAAU;IAEV,MAAM,QAAQ,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;IACrC,OAAO;QACL,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,SAAS,EAAE,CAAC,UAA4B;IAItC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC;AAMD,SAAS,UAAU,CACjB,KAAwB;IAExB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;I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;YACE,OAAO,IAAI,CACT,2BAA2B,EAC3B,EAAE,UAAU,EAAE,UAAU,IAAI,QAAQ,EAAE,EACtC,IAAI,CACL,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["/**\n * The `@syntax` annotation vocabulary — the \"little extra metadata\" that\n * turns an MM0 theory into a full surface-language spec.\n *\n * Annotations ride MM0's `--|` doc-comment channel, the same one Aufbau uses\n * for `@acui`, `@congr`, `@rewrite`, and the rest. Anything that is not\n * `@syntax` is *foreign*: preserved untouched for whoever owns it, never\n * interpreted here. The library also owns stripping `@syntax` lines before a theory is\n * handed to the engine, which currently rejects annotations it does not\n * know.\n *\n * Attachment rules (checked by the spec builder, not here):\n * - `juxtaposed` attaches to a binary term whose arguments and result\n * share one sort (adjacency of that sort's expressions denotes it);\n * - `elided` attaches to a nullary term (supplied when an argument of\n * its sort is missing, dropped again when printing);\n * - `role` attaches to a `sort`, a `term`, or a `def`;\n * - everything else is spec-wide and may sit on any statement.\n *\n * The lexicon itself needs no `@syntax` at all: letters are ordinary term\n * declarations, and variables ride the engine's own `@vars` annotation.\n */\n\nimport { type Diagnostic, diagnostic, type Span } from \"../diagnostics.js\";\n\nexport const LINT_NAMES = [\n \"parenthesize-binary-only\",\n \"closed-sentences\",\n] as const;\n\nexport type LintName = (typeof LINT_NAMES)[number];\n\n/** A capture in an elab pattern: `?ts:tm+` — name, class, quantifier. */\nexport interface RuleCapture {\n readonly kind: \"capture\";\n readonly name: string;\n /** A sort name; a leaf whose sort coerces into it matches. */\n readonly class: string;\n readonly quantifier: \"\" | \"+\" | \"?\";\n}\n\nexport interface RuleLiteral {\n readonly kind: \"literal\";\n readonly token: string;\n}\n\nexport type RulePatternElement = RuleCapture | RuleLiteral;\n\n/** A capture reference in an elab template: `?ts` or joined `?ts,*`. */\nexport interface RuleReference {\n readonly kind: \"reference\";\n readonly name: string;\n /** For a `+` capture, the token to join repeats with; null joins bare. */\n readonly separator: string | null;\n}\n\nexport type RuleTemplateElement = RuleLiteral | RuleReference;\n\nexport interface ElabRule {\n readonly inputOnly: boolean;\n readonly pattern: readonly RulePatternElement[];\n readonly span: Span;\n readonly template: readonly RuleTemplateElement[];\n}\n\nexport type SyntaxAnnotation =\n | {\n readonly kind: \"assoc-none\";\n readonly prec: number;\n }\n | {\n readonly kind: \"brackets\";\n readonly pairs: readonly (readonly [string, string])[];\n }\n | {\n readonly kind: \"display-drop-outer-parens\";\n }\n | {\n readonly kind: \"display-rotate-brackets\";\n readonly pairs: readonly (readonly [string, string])[];\n }\n | {\n /** A bidirectional token rule: elaborate in, delaborate out. */\n readonly kind: \"elab\";\n readonly rule: ElabRule;\n }\n | {\n /**\n * Surface delimiters: where a chunk of *student* input ends. Same\n * shape and same meaning as MM0's own `delimiter` statement, and\n * unioned with it — but an entry may be any string, not just a single\n * byte, so `∧` and `<->` can self-delimit where the engine's\n * byte table cannot hold them.\n */\n readonly kind: \"delimiter\";\n readonly left: readonly string[];\n readonly right: readonly string[];\n }\n | {\n /** Supplied when an argument of its sort is missing; drops on print. */\n readonly kind: \"elided\";\n }\n | {\n /** Adjacency of this combiner's sort denotes it — `Fxy`, `ab`. */\n readonly kind: \"juxtaposed\";\n }\n | {\n readonly kind: \"lint\";\n readonly name: LintName;\n }\n | {\n readonly kind: \"role\";\n readonly role: string;\n };\n\nconst TEMPLATES: Record<string, string> = {\n syntax_unknown_subcommand: \"unknown @syntax subcommand {subcommand}\",\n syntax_bad_flag: \"@syntax {flag} takes no arguments\",\n syntax_bad_brackets:\n \"bracket pairs come as: <open> <close> [<open> <close>…]\",\n syntax_bad_assoc_none: \"@syntax assoc-none wants one precedence number\",\n syntax_unknown_lint: \"unknown lint {name}; known lints: {known}\",\n syntax_bad_display:\n \"@syntax display wants drop-outer-parens or rotate-brackets <pairs…>\",\n syntax_bad_delimiter:\n \"@syntax delimiter wants: delimiter $ <entries…> $, or delimiter $ <left…> $ $ <right…> $\",\n syntax_empty_delimiter: \"a @syntax delimiter math string must list entries\",\n syntax_bad_elab:\n \"@syntax elab wants: elab $ <pattern> $ => $ <template> $ [input-only]\",\n syntax_bad_pattern_element: \"cannot read pattern element {element}\",\n syntax_bad_template_element: \"cannot read template element {element}\",\n syntax_bad_role: \"@syntax role wants one role name\",\n};\n\nfunction fail(\n id: string,\n params: Record<string, string>,\n span: Span,\n): { annotation: null; diagnostic: Diagnostic } {\n const template = TEMPLATES[id] ?? id;\n return {\n annotation: null,\n diagnostic: diagnostic(id, template, params, span),\n };\n}\n\nfunction ok(annotation: SyntaxAnnotation): {\n annotation: SyntaxAnnotation;\n diagnostic: null;\n} {\n return { annotation, diagnostic: null };\n}\n\nexport type SyntaxAnnotationResult =\n | { readonly annotation: SyntaxAnnotation; readonly diagnostic: null }\n | { readonly annotation: null; readonly diagnostic: Diagnostic };\n\nfunction parsePairs(\n words: readonly string[],\n): (readonly [string, string])[] | null {\n if (words.length === 0 || words.length % 2 !== 0) {\n return null;\n }\n\n const pairs: (readonly [string, string])[] = [];\n\n for (let i = 0; i < words.length; i += 2) {\n const open = words[i];\n const close = words[i + 1];\n\n if (open === undefined || close === undefined || open === close) {\n return null;\n }\n\n pairs.push([open, close]);\n }\n\n return pairs;\n}\n\nconst CAPTURE =\n /^\\?([A-Za-z_][A-Za-z0-9_]*):([A-Za-z_][A-Za-z0-9_]*)([+?]?)$/;\nconst REFERENCE = /^\\?([A-Za-z_][A-Za-z0-9_]*)(?:(.)\\*)?$/;\n\nfunction parsePattern(text: string): readonly RulePatternElement[] | string {\n const elements: RulePatternElement[] = [];\n\n for (const word of text.split(/\\s+/).filter((w) => w.length > 0)) {\n if (word.startsWith(\"?\")) {\n const match = CAPTURE.exec(word);\n\n if (match === null) {\n return word;\n }\n\n elements.push({\n kind: \"capture\",\n name: match[1] ?? \"\",\n class: match[2] ?? \"\",\n quantifier: (match[3] ?? \"\") as \"\" | \"+\" | \"?\",\n });\n continue;\n }\n\n elements.push({ kind: \"literal\", token: word });\n }\n\n return elements;\n}\n\nfunction parseTemplate(\n text: string,\n): readonly RuleTemplateElement[] | string {\n const elements: RuleTemplateElement[] = [];\n\n for (const word of text.split(/\\s+/).filter((w) => w.length > 0)) {\n if (word.startsWith(\"?\")) {\n const match = REFERENCE.exec(word);\n\n if (match === null) {\n return word;\n }\n\n elements.push({\n kind: \"reference\",\n name: match[1] ?? \"\",\n separator: match[2] ?? null,\n });\n continue;\n }\n\n elements.push({ kind: \"literal\", token: word });\n }\n\n return elements;\n}\n\nconst ELAB = /^\\$(.*?)\\$\\s*=>\\s*\\$(.*?)\\$\\s*(input-only)?\\s*$/s;\n\n/** `$ … $`, or `$ left… $ $ right… $` — MM0's own two shapes. */\nconst DELIMITER = /^\\$([^$]*)\\$(?:\\s*\\$([^$]*)\\$)?\\s*$/;\n\n/**\n * Every entry written out, one at a time. There is deliberately no range\n * shorthand: a spike of `A-Z`-style ranges read `<->` as the range `<`…`>`\n * and silently turned one delimiter into three. A declaration that decides\n * how input is cut up is worth its verbosity.\n */\nfunction delimiterEntries(text: string): string[] {\n return text.split(/\\s+/).filter((entry) => entry.length > 0);\n}\n\n/**\n * Parse one annotation payload (the text after `--|`). Returns null for a\n * foreign annotation — anything that does not begin `@syntax`.\n */\nexport function parseSyntaxAnnotation(\n text: string,\n span: Span,\n): SyntaxAnnotationResult | null {\n const trimmed = text.trim();\n\n if (!trimmed.startsWith(\"@syntax\")) {\n return null;\n }\n\n const rest = trimmed.slice(\"@syntax\".length).trim();\n const words = rest.split(/\\s+/).filter((w) => w.length > 0);\n const subcommand = words[0];\n\n switch (subcommand) {\n case \"juxtaposed\":\n case \"elided\": {\n if (words.length !== 1) {\n return fail(\"syntax_bad_flag\", { flag: subcommand }, span);\n }\n\n return ok({ kind: subcommand });\n }\n\n case \"brackets\": {\n const pairs = parsePairs(words.slice(1));\n\n if (pairs === null) {\n return fail(\"syntax_bad_brackets\", {}, span);\n }\n\n return ok({ kind: \"brackets\", pairs });\n }\n\n case \"delimiter\": {\n const match = DELIMITER.exec(rest.slice(\"delimiter\".length).trim());\n\n if (match === null) {\n return fail(\"syntax_bad_delimiter\", {}, span);\n }\n\n const first = delimiterEntries(match[1] ?? \"\");\n const second =\n match[2] === undefined ? null : delimiterEntries(match[2]);\n\n if (first.length === 0 || second?.length === 0) {\n return fail(\"syntax_empty_delimiter\", {}, span);\n }\n\n // One list means both sides, as in MM0.\n return ok({ kind: \"delimiter\", left: first, right: second ?? first });\n }\n\n case \"assoc-none\": {\n const number = words[1];\n\n if (\n words.length !== 2 ||\n number === undefined ||\n !/^\\d+$/.test(number)\n ) {\n return fail(\"syntax_bad_assoc_none\", {}, span);\n }\n\n return ok({ kind: \"assoc-none\", prec: Number.parseInt(number, 10) });\n }\n\n case \"lint\": {\n const name = words[1];\n\n if (\n words.length !== 2 ||\n name === undefined ||\n !(LINT_NAMES as readonly string[]).includes(name)\n ) {\n return fail(\n \"syntax_unknown_lint\",\n { name: name ?? \"\", known: LINT_NAMES.join(\", \") },\n span,\n );\n }\n\n return ok({ kind: \"lint\", name: name as LintName });\n }\n\n case \"display\": {\n if (words[1] === \"drop-outer-parens\" && words.length === 2) {\n return ok({ kind: \"display-drop-outer-parens\" });\n }\n\n if (words[1] === \"rotate-brackets\") {\n const pairs = parsePairs(words.slice(2));\n\n if (pairs !== null) {\n return ok({ kind: \"display-rotate-brackets\", pairs });\n }\n }\n\n return fail(\"syntax_bad_display\", {}, span);\n }\n\n case \"elab\": {\n const match = ELAB.exec(rest.slice(\"elab\".length).trim());\n\n if (match === null) {\n return fail(\"syntax_bad_elab\", {}, span);\n }\n\n const pattern = parsePattern(match[1] ?? \"\");\n\n if (typeof pattern === \"string\") {\n return fail(\"syntax_bad_pattern_element\", { element: pattern }, span);\n }\n\n const template = parseTemplate(match[2] ?? \"\");\n\n if (typeof template === \"string\") {\n return fail(\n \"syntax_bad_template_element\",\n { element: template },\n span,\n );\n }\n\n return ok({\n kind: \"elab\",\n rule: {\n inputOnly: match[3] === \"input-only\",\n pattern,\n span,\n template,\n },\n });\n }\n\n case \"role\": {\n const role = words[1];\n\n if (words.length !== 2 || role === undefined) {\n return fail(\"syntax_bad_role\", {}, span);\n }\n\n return ok({ kind: \"role\", role });\n }\n\n default:\n return fail(\n \"syntax_unknown_subcommand\",\n { subcommand: subcommand ?? \"(none)\" },\n span,\n );\n }\n}\n"]}
@@ -15,6 +15,7 @@ export interface SortInfo {
15
15
  readonly foreignAnnotations: readonly Annotation[];
16
16
  readonly modifiers: readonly string[];
17
17
  readonly name: string;
18
+ readonly roles: readonly string[];
18
19
  readonly span: Span;
19
20
  /**
20
21
  * The sort's variable tokens, read from the engine's own `@vars`
@@ -24,13 +24,15 @@ const TEMPLATES = {
24
24
  elab_duplicate_capture: "capture {name} appears twice in the pattern",
25
25
  elab_unknown_reference: "the template references {name}, which the pattern does not capture",
26
26
  elab_not_invertible: "capture {name} is not used exactly once in the template; mark the rule input-only if that is intended",
27
+ elab_literal_split: "the literal {literal} is not one chunk — the delimiters read it as {chunks}; write those as separate elements",
28
+ elab_literal_looks_like_capture: "the literal {literal} contains ?; a capture is its own element, so write it with spaces around it",
27
29
  juxtaposed_target: "@syntax juxtaposed must sit on a binary term whose arguments and result share one sort",
28
30
  juxtaposed_needs_notation: "a juxtaposed term needs a declared notation, so the engine can read it",
29
31
  juxtaposed_duplicate: "sort {sort} already has a juxtaposed combiner",
30
32
  elided_target: "@syntax elided must sit on a term with no arguments",
31
33
  elided_duplicate: "sort {sort} already has an elided term",
32
34
  vars_term_conflict: "@vars token {token} is also a declared term; a name can be only one",
33
- role_target: "@syntax role must sit on a term",
35
+ role_target: "@syntax role must sit on a sort or a term",
34
36
  delimiter_unknown: "delimiter {token} is neither a notation token, a bracket, nor a lexicon name, so no input can ever be read as it",
35
37
  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",
36
38
  delimiter_unreachable_name: "the delimiters split {name} into {chunks}, so it can never be read as one name",
@@ -133,6 +135,47 @@ function checkSurfaceDelimiters(spec, declarations, diagnostics) {
133
135
  report(diagnostics, "delimiter_unreachable_name", { chunks: segment(name, rules).join(" "), name }, span ?? fallback);
134
136
  }
135
137
  }
138
+ /**
139
+ * Elab literals against the delimiters that will cut up the text they have
140
+ * to match. A literal need not be declared vocabulary — that is the point
141
+ * of the layer — but it is matched one chunk at a time, so a literal the
142
+ * delimiters split can never match anything, and a rule that quietly does
143
+ * nothing is the failure this reader exists to prevent.
144
+ *
145
+ * Template literals are checked too, for every rule that is not
146
+ * `input-only`: delaboration runs the rule inverted, where the template's
147
+ * literals *are* the pattern.
148
+ */
149
+ function checkElabLiterals(spec, diagnostics) {
150
+ const rules = delimiterRules(spec.surfaceDelimiters);
151
+ const check = (token, span) => {
152
+ // `parsePattern` splits on whitespace, so `(?x:var)` arrives as one
153
+ // literal rather than three elements. It would trip the split check
154
+ // below as well, but this names the actual mistake.
155
+ if (token.includes("?")) {
156
+ report(diagnostics, "elab_literal_looks_like_capture", { literal: token }, span);
157
+ return;
158
+ }
159
+ if (!isReachableChunk(token, rules)) {
160
+ report(diagnostics, "elab_literal_split", { chunks: segment(token, rules).join(" "), literal: token }, span);
161
+ }
162
+ };
163
+ for (const rule of spec.elabRules) {
164
+ for (const element of rule.pattern) {
165
+ if (element.kind === "literal") {
166
+ check(element.token, rule.span);
167
+ }
168
+ }
169
+ if (rule.inputOnly) {
170
+ continue;
171
+ }
172
+ for (const element of rule.template) {
173
+ if (element.kind === "literal") {
174
+ check(element.token, rule.span);
175
+ }
176
+ }
177
+ }
178
+ }
136
179
  export function parseSpec(source) {
137
180
  const { statements, diagnostics: parseDiagnostics } = parseStatements(source);
138
181
  const diagnostics = [...parseDiagnostics];
@@ -189,6 +232,7 @@ export function parseSpec(source) {
189
232
  foreignAnnotations: foreign,
190
233
  modifiers: statement.modifiers,
191
234
  name: statement.name,
235
+ roles: [],
192
236
  span: statement.span,
193
237
  vars,
194
238
  });
@@ -325,6 +369,16 @@ export function parseSpec(source) {
325
369
  break;
326
370
  }
327
371
  case "role": {
372
+ if (statement.kind === "sort") {
373
+ const info = sorts.get(statement.name);
374
+ if (info !== undefined) {
375
+ sorts.set(statement.name, {
376
+ ...info,
377
+ roles: [...info.roles, annotation.role],
378
+ });
379
+ }
380
+ break;
381
+ }
328
382
  if (statement.kind !== "term" && statement.kind !== "def") {
329
383
  report(diagnostics, "role_target", {}, span);
330
384
  break;
@@ -513,6 +567,7 @@ export function parseSpec(source) {
513
567
  terms,
514
568
  };
515
569
  checkSurfaceDelimiters(spec, surfaceDeclarations, diagnostics);
570
+ checkElabLiterals(spec, diagnostics);
516
571
  return { diagnostics, spec };
517
572
  }
518
573
  //# sourceMappingURL=spec.js.map