@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.
@@ -1 +1 @@
1
- {"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/reader/spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,cAAc,EACd,gBAAgB,EAChB,OAAO,GACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,UAAU,GAGX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAGL,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AA8FzB,MAAM,SAAS,GAA2B;IACxC,qBAAqB,EAAE,4BAA4B;IACnD,YAAY,EAAE,6BAA6B;IAC3C,YAAY,EAAE,6BAA6B;IAC3C,WAAW,EAAE,uDAAuD;IACpE,yBAAyB,EACvB,kEAAkE;IACpE,cAAc,EACZ,uEAAuE;IACzE,8BAA8B,EAC5B,qDAAqD;IACvD,uBAAuB,EACrB,mEAAmE;IACrE,sBAAsB,EAAE,6CAA6C;IACrE,sBAAsB,EACpB,oEAAoE;IACtE,mBAAmB,EACjB,uGAAuG;IACzG,iBAAiB,EACf,wFAAwF;IAC1F,yBAAyB,EACvB,wEAAwE;IAC1E,oBAAoB,EAAE,+CAA+C;IACrE,aAAa,EAAE,qDAAqD;IACpE,gBAAgB,EAAE,wCAAwC;IAC1D,kBAAkB,EAChB,qEAAqE;IACvE,WAAW,EAAE,iCAAiC;IAC9C,iBAAiB,EACf,kHAAkH;IACpH,6BAA6B,EAC3B,qIAAqI;IACvI,0BAA0B,EACxB,gFAAgF;CACnF,CAAC;AAEF,SAAS,MAAM,CACb,WAAyB,EACzB,EAAU,EACV,MAA8B,EAC9B,IAAU,EACV,WAAqB,OAAO;IAE5B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,IAAI,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAS;QACjB,SAAS;QACT,SAAS;QACT,UAAU,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE;QAC5D,OAAO,EAAE,EAAE,eAAe,EAAE,cAAc,EAAE;QAC5C,aAAa;QACb,KAAK;QACL,SAAS;QACT,SAAS;QACT,KAAK;QACL,UAAU;QACV,qEAAqE;QACrE,iBAAiB,EAAE;YACjB,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,WAAW,CAAC,CAAC;YAClD,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,eAAe,EAAE,GAAG,YAAY,CAAC,CAAC;SACtD;QACD,KAAK;KACN,CAAC;IAEF,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,EAAE,WAAW,CAAC,CAAC;IAE/D,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["/**\n * From parsed statements to a `Spec` — the library's central object: the\n * signature, notations, coercions, and `@syntax` surface metadata of one\n * logical system, validated.\n *\n * Validation here is about the spec being *coherent* (token conflicts,\n * dangling names, non-invertible elab rules); whether the theory proves\n * anything is the engine's business, and axiom bodies pass through opaque.\n */\n\nimport {\n type DelimiterSet,\n delimiterRules,\n isReachableChunk,\n segment,\n} from \"../delimiters.js\";\nimport {\n type Diagnostic,\n diagnostic,\n type Severity,\n type Span,\n} from \"../diagnostics.js\";\nimport { surfaceVocabulary } from \"../vocabulary.js\";\nimport {\n type ElabRule,\n type LintName,\n parseSyntaxAnnotation,\n type SyntaxAnnotation,\n} from \"./annotations.js\";\nimport {\n type Annotation,\n type Binder,\n type NotationLiteral,\n type Precedence,\n parseStatements,\n type Statement,\n} from \"./statements.js\";\n\nexport interface SortInfo {\n readonly foreignAnnotations: readonly Annotation[];\n readonly modifiers: readonly string[];\n readonly name: string;\n readonly span: Span;\n /**\n * The sort's variable tokens, read from the engine's own `@vars`\n * annotation (which stays in `foreignAnnotations` untouched — it is the\n * engine's, we only listen in). These are the surface lexicon's\n * identifiers of this sort; whether a quantifier can bind them falls\n * out of the quantifiers' binder sorts, not from here.\n */\n readonly vars: readonly string[];\n}\n\nexport interface TermInfo {\n readonly binders: readonly Binder[];\n /** `@syntax elided`: supplied when an argument of its sort is missing. */\n readonly elided: boolean;\n readonly foreignAnnotations: readonly Annotation[];\n /** True when this came from a `def` rather than a `term`. */\n readonly isDef: boolean;\n /** `@syntax juxtaposed`: adjacency of its sort's leaves denotes it. */\n readonly juxtaposed: boolean;\n readonly name: string;\n readonly returnSort: string;\n readonly roles: readonly string[];\n readonly span: Span;\n}\n\nexport interface CoercionInfo {\n readonly from: string;\n readonly name: string;\n readonly span: Span;\n readonly to: string;\n}\n\nexport type NotationInfo =\n | {\n readonly form: \"general\";\n /** The notation statement's own binders, which its variables name. */\n readonly binders: readonly Binder[];\n readonly literals: readonly NotationLiteral[];\n readonly span: Span;\n readonly term: string;\n }\n | {\n readonly form: \"simple\";\n readonly fixity: \"infixl\" | \"infixr\" | \"prefix\";\n readonly prec: Precedence;\n readonly span: Span;\n readonly term: string;\n readonly token: string;\n };\n\nexport interface Spec {\n readonly assocNone: ReadonlySet<number>;\n readonly coercions: readonly CoercionInfo[];\n /**\n * The theory's own `delimiter` statement — how the *engine* cuts up math\n * strings. Single bytes, because that is all the engine's table holds.\n */\n readonly delimiters: DelimiterSet;\n readonly display: {\n readonly dropOuterParens: boolean;\n readonly rotateBrackets: readonly (readonly [string, string])[] | null;\n };\n /** Always starts with the built-in `(\"(\", \")\")` pair. */\n readonly groupingPairs: readonly (readonly [string, string])[];\n readonly lints: readonly LintName[];\n /** In declaration order; the last notation for a term is canonical. */\n readonly notations: readonly NotationInfo[];\n readonly elabRules: readonly ElabRule[];\n readonly sorts: ReadonlyMap<string, SortInfo>;\n /** Every statement, in order, annotations intact — full fidelity. */\n readonly statements: readonly Statement[];\n /**\n * How *student* input is cut up: `delimiters` unioned with every\n * `@syntax delimiter` the spec declares. A spec that declares none gets\n * the theory's set unchanged — so writing textbook notation tight\n * (`~~P`, `Fxy`) is an explicit opt-in, never something a spec acquires\n * by accident.\n */\n readonly surfaceDelimiters: DelimiterSet;\n readonly terms: ReadonlyMap<string, TermInfo>;\n}\n\nexport interface SpecParse {\n readonly diagnostics: readonly Diagnostic[];\n readonly spec: Spec;\n}\n\nconst TEMPLATES: Record<string, string> = {\n duplicate_declaration: \"{name} is already declared\",\n unknown_sort: \"sort {name} is not declared\",\n unknown_term: \"term {name} is not declared\",\n infix_arity: \"an infix operator needs exactly two regular arguments\",\n unknown_notation_variable:\n \"notation variable {name} is not one of the declaration's binders\",\n token_conflict:\n \"token {token} already has a meaning; a token may carry one parse rule\",\n precedence_mixed_associativity:\n \"precedence {prec} mixes infixl and infixr operators\",\n grouping_token_conflict:\n \"{token} is a grouping bracket and cannot also be a notation token\",\n elab_duplicate_capture: \"capture {name} appears twice in the pattern\",\n elab_unknown_reference:\n \"the template references {name}, which the pattern does not capture\",\n elab_not_invertible:\n \"capture {name} is not used exactly once in the template; mark the rule input-only if that is intended\",\n juxtaposed_target:\n \"@syntax juxtaposed must sit on a binary term whose arguments and result share one sort\",\n juxtaposed_needs_notation:\n \"a juxtaposed term needs a declared notation, so the engine can read it\",\n juxtaposed_duplicate: \"sort {sort} already has a juxtaposed combiner\",\n elided_target: \"@syntax elided must sit on a term with no arguments\",\n elided_duplicate: \"sort {sort} already has an elided term\",\n vars_term_conflict:\n \"@vars token {token} is also a declared term; a name can be only one\",\n role_target: \"@syntax role must sit on a term\",\n delimiter_unknown:\n \"delimiter {token} is neither a notation token, a bracket, nor a lexicon name, so no input can ever be read as it\",\n delimiter_token_not_delimited:\n \"{token} is not a surface delimiter; it is only read when whitespace or a delimiter bounds it, so it will run into an adjacent token\",\n delimiter_unreachable_name:\n \"the delimiters split {name} into {chunks}, so it can never be read as one name\",\n};\n\nfunction report(\n diagnostics: Diagnostic[],\n id: string,\n params: Record<string, string>,\n span: Span,\n severity: Severity = \"error\",\n): void {\n diagnostics.push(\n diagnostic(id, TEMPLATES[id] ?? id, params, span, severity),\n );\n}\n\n/** The binder count an application must fill (bound and regular alike). */\nfunction regularBinders(binders: readonly Binder[]): readonly Binder[] {\n return binders.filter((binder) => !binder.binds);\n}\n\nfunction binderSortOf(binder: Binder): string {\n return \"sort\" in binder.type ? binder.type.sort : \"\";\n}\n\ninterface TokenMeaning {\n readonly key: string;\n readonly term: string;\n}\n\n/**\n * One line per parse rule a token can carry. Two identical lines are a\n * pointless duplicate but not an ambiguity; anything else sharing a token\n * is a conflict.\n */\nfunction meaningOf(notation: NotationInfo): TokenMeaning | null {\n if (notation.form === \"simple\") {\n return {\n key: `${notation.fixity}:${String(notation.prec)}`,\n term: notation.term,\n };\n }\n\n const first = notation.literals[0];\n\n if (first === undefined || first.kind !== \"constant\") {\n return null;\n }\n\n return { key: \"general\", term: notation.term };\n}\n\n/** Where each notation constant was declared, for pointing a diagnostic. */\nfunction tokenSpans(spec: Spec): Map<string, Span> {\n const spans = new Map<string, Span>();\n\n for (const notation of spec.notations) {\n const constants =\n notation.form === \"simple\"\n ? [notation.token]\n : notation.literals\n .filter((literal) => literal.kind === \"constant\")\n .map((literal) => literal.token);\n\n for (const token of constants) {\n if (!spans.has(token)) {\n spans.set(token, notation.span);\n }\n }\n }\n\n return spans;\n}\n\n/**\n * The surface delimiter set, checked against the vocabulary it has to cut\n * up. Only runs when the spec declares `@syntax delimiter`: a spec that\n * declares none is read under the theory's own delimiters, where tokens\n * are whitespace-separated and none of this can bite.\n */\nfunction checkSurfaceDelimiters(\n spec: Spec,\n declarations: readonly { entries: readonly string[]; span: Span }[],\n diagnostics: Diagnostic[],\n): void {\n const fallback = declarations[0]?.span;\n\n if (fallback === undefined) {\n return;\n }\n\n const vocabulary = surfaceVocabulary(spec);\n const rules = delimiterRules(spec.surfaceDelimiters);\n const declared = new Set([\n ...spec.surfaceDelimiters.left,\n ...spec.surfaceDelimiters.right,\n ]);\n\n // A delimiter nothing can be classified as cuts input into pieces the\n // parser must then reject — a boundary with no meaning behind it.\n for (const { entries, span } of declarations) {\n for (const entry of entries) {\n if (!vocabulary.tokens.has(entry) && !vocabulary.names.has(entry)) {\n report(diagnostics, \"delimiter_unknown\", { token: entry }, span);\n }\n }\n }\n\n // A token that is not itself a delimiter still reads when whitespace or a\n // delimiter bounds it — `P->Q` is fine with the letters declared — so this\n // is advice, not breakage. What it warns about is two such tokens\n // meeting: `->~` is one chunk unless one of them delimits.\n const spans = tokenSpans(spec);\n\n for (const token of vocabulary.tokens) {\n if (!declared.has(token)) {\n report(\n diagnostics,\n \"delimiter_token_not_delimited\",\n { token },\n spans.get(token) ?? fallback,\n \"warning\",\n );\n }\n }\n\n // A name the delimiters split apart is unreachable: segmentation happens\n // before anything knows the name exists, so no bracketing recovers it.\n // Elided terms are exempt — they are supplied by the parser and dropped\n // by the printer, never typed.\n for (const [name, ref] of vocabulary.names) {\n if (ref.kind === \"term\" && spec.terms.get(ref.term)?.elided === true) {\n continue;\n }\n\n if (isReachableChunk(name, rules)) {\n continue;\n }\n\n const span =\n ref.kind === \"term\"\n ? spec.terms.get(ref.term)?.span\n : spec.sorts.get(ref.sort)?.span;\n\n report(\n diagnostics,\n \"delimiter_unreachable_name\",\n { chunks: segment(name, rules).join(\" \"), name },\n span ?? fallback,\n );\n }\n}\n\nexport function parseSpec(source: string): SpecParse {\n const { statements, diagnostics: parseDiagnostics } =\n parseStatements(source);\n const diagnostics: Diagnostic[] = [...parseDiagnostics];\n\n const sorts = new Map<string, SortInfo>();\n const terms = new Map<string, TermInfo>();\n const coercions: CoercionInfo[] = [];\n const notations: NotationInfo[] = [];\n const elabRules: ElabRule[] = [];\n const lints: LintName[] = [];\n const assocNone = new Set<number>();\n const delimitersLeft = new Set<string>();\n const delimitersRight = new Set<string>();\n const surfaceLeft = new Set<string>();\n const surfaceRight = new Set<string>();\n const surfaceDeclarations: {\n readonly entries: readonly string[];\n readonly span: Span;\n }[] = [];\n const groupingPairs: (readonly [string, string])[] = [[\"(\", \")\"]];\n let dropOuterParens = false;\n let rotateBrackets: readonly (readonly [string, string])[] | null = null;\n\n // ── First pass: split each statement's annotations, collect declarations.\n\n interface Attached {\n readonly annotation: SyntaxAnnotation;\n readonly span: Span;\n readonly statement: Statement;\n }\n\n const attached: Attached[] = [];\n\n for (const statement of statements) {\n const foreign: Annotation[] = [];\n\n for (const annotation of statement.annotations) {\n const parsed = parseSyntaxAnnotation(annotation.text, annotation.span);\n\n if (parsed === null) {\n foreign.push(annotation);\n continue;\n }\n\n if (parsed.diagnostic !== null) {\n diagnostics.push(parsed.diagnostic);\n continue;\n }\n\n attached.push({\n annotation: parsed.annotation,\n span: annotation.span,\n statement,\n });\n }\n\n switch (statement.kind) {\n case \"sort\": {\n if (sorts.has(statement.name) || terms.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n // The engine's `@vars` pools are this library's variable lexicon\n // too; the lines stay foreign (they are the engine's to keep).\n const vars: string[] = [];\n\n for (const annotation of foreign) {\n const match = /^@vars\\s+(.+)$/.exec(annotation.text.trim());\n\n if (match !== null) {\n vars.push(\n ...(match[1] ?? \"\").split(/\\s+/).filter((w) => w.length > 0),\n );\n }\n }\n\n sorts.set(statement.name, {\n foreignAnnotations: foreign,\n modifiers: statement.modifiers,\n name: statement.name,\n span: statement.span,\n vars,\n });\n break;\n }\n\n case \"term\":\n case \"def\": {\n if (sorts.has(statement.name) || terms.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n const returnSort =\n statement.kind === \"term\"\n ? (statement.returnChain[statement.returnChain.length - 1]\n ?.sort ?? \"\")\n : statement.returnType.sort;\n\n // Arrow sugar on a term (`a > b > c`) desugars to extra anonymous\n // regular binders so arity means one thing everywhere downstream.\n const extra: Binder[] =\n statement.kind === \"term\"\n ? statement.returnChain.slice(0, -1).map((type) => ({\n binds: false,\n dummy: false,\n name: \"_\",\n span: type.span,\n type,\n }))\n : [];\n\n terms.set(statement.name, {\n binders: [...statement.binders, ...extra],\n elided: false,\n foreignAnnotations: foreign,\n isDef: statement.kind === \"def\",\n juxtaposed: false,\n name: statement.name,\n returnSort,\n roles: [],\n span: statement.span,\n });\n break;\n }\n\n case \"coercion\": {\n coercions.push({\n from: statement.from,\n name: statement.name,\n span: statement.span,\n to: statement.to,\n });\n break;\n }\n\n case \"delimiter\": {\n for (const ch of statement.left) {\n delimitersLeft.add(ch);\n }\n for (const ch of statement.right) {\n delimitersRight.add(ch);\n }\n break;\n }\n\n case \"simple-notation\": {\n notations.push({\n form: \"simple\",\n fixity: statement.fixity,\n prec: statement.prec,\n span: statement.span,\n term: statement.term,\n token: statement.token,\n });\n break;\n }\n\n case \"notation\": {\n notations.push({\n form: \"general\",\n binders: statement.binders,\n literals: statement.literals,\n span: statement.span,\n term: statement.term,\n });\n\n for (const literal of statement.literals) {\n if (\n literal.kind === \"variable\" &&\n !statement.binders.some((b) => b.name === literal.name)\n ) {\n report(\n diagnostics,\n \"unknown_notation_variable\",\n { name: literal.name },\n literal.span,\n );\n }\n }\n break;\n }\n\n case \"axiom\":\n case \"theorem\":\n break;\n }\n }\n\n // ── Second pass: interpret @syntax annotations now that names resolve.\n\n const juxtaposedBySort = new Map<string, string>();\n const elidedBySort = new Map<string, string>();\n\n for (const { annotation, span, statement } of attached) {\n switch (annotation.kind) {\n case \"juxtaposed\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n const regular =\n info === undefined ? [] : regularBinders(info.binders);\n const sort = info?.returnSort ?? \"\";\n\n if (\n info === undefined ||\n info.binders.length !== 2 ||\n regular.length !== 2 ||\n regular.some((binder) => binderSortOf(binder) !== sort)\n ) {\n report(diagnostics, \"juxtaposed_target\", {}, span);\n break;\n }\n\n if (!notations.some((notation) => notation.term === info.name)) {\n report(diagnostics, \"juxtaposed_needs_notation\", {}, span);\n break;\n }\n\n if (juxtaposedBySort.has(sort)) {\n report(diagnostics, \"juxtaposed_duplicate\", { sort }, span);\n break;\n }\n\n juxtaposedBySort.set(sort, info.name);\n terms.set(info.name, { ...info, juxtaposed: true });\n break;\n }\n\n case \"elided\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n\n if (info === undefined || regularBinders(info.binders).length !== 0) {\n report(diagnostics, \"elided_target\", {}, span);\n break;\n }\n\n if (elidedBySort.has(info.returnSort)) {\n report(\n diagnostics,\n \"elided_duplicate\",\n { sort: info.returnSort },\n span,\n );\n break;\n }\n\n elidedBySort.set(info.returnSort, info.name);\n terms.set(info.name, { ...info, elided: true });\n break;\n }\n\n case \"role\": {\n if (statement.kind !== \"term\" && statement.kind !== \"def\") {\n report(diagnostics, \"role_target\", {}, span);\n break;\n }\n\n const info = terms.get(statement.name);\n\n if (info !== undefined) {\n terms.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n case \"brackets\": {\n for (const pair of annotation.pairs) {\n const exists = groupingPairs.some(\n ([open, close]) => open === pair[0] && close === pair[1],\n );\n\n if (!exists) {\n groupingPairs.push(pair);\n }\n }\n break;\n }\n\n case \"delimiter\": {\n for (const entry of annotation.left) {\n surfaceLeft.add(entry);\n }\n\n for (const entry of annotation.right) {\n surfaceRight.add(entry);\n }\n\n surfaceDeclarations.push({\n entries: [...new Set([...annotation.left, ...annotation.right])],\n span,\n });\n break;\n }\n\n case \"assoc-none\": {\n assocNone.add(annotation.prec);\n break;\n }\n\n case \"lint\": {\n if (!lints.includes(annotation.name)) {\n lints.push(annotation.name);\n }\n break;\n }\n\n case \"display-drop-outer-parens\": {\n dropOuterParens = true;\n break;\n }\n\n case \"display-rotate-brackets\": {\n rotateBrackets = annotation.pairs;\n break;\n }\n\n case \"elab\": {\n elabRules.push(annotation.rule);\n break;\n }\n }\n }\n\n // ── Validation over the collected spec.\n\n for (const info of terms.values()) {\n for (const binder of info.binders) {\n if (\"sort\" in binder.type && !sorts.has(binder.type.sort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: binder.type.sort },\n binder.type.span,\n );\n }\n }\n\n if (info.returnSort !== \"\" && !sorts.has(info.returnSort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: info.returnSort },\n info.span,\n );\n }\n }\n\n for (const sort of sorts.values()) {\n for (const token of sort.vars) {\n if (terms.has(token)) {\n report(diagnostics, \"vars_term_conflict\", { token }, sort.span);\n }\n }\n }\n\n for (const coercion of coercions) {\n if (!terms.has(coercion.name)) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: coercion.name },\n coercion.span,\n );\n }\n for (const sort of [coercion.from, coercion.to]) {\n if (!sorts.has(sort)) {\n report(diagnostics, \"unknown_sort\", { name: sort }, coercion.span);\n }\n }\n }\n\n const tokenMeanings = new Map<string, { key: string; term: string }>();\n\n for (const notation of notations) {\n const info = terms.get(notation.term);\n\n if (info === undefined) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: notation.term },\n notation.span,\n );\n continue;\n }\n\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n (regularBinders(info.binders).length !== 2 ||\n info.binders.some((b) => b.binds))\n ) {\n report(diagnostics, \"infix_arity\", {}, notation.span);\n }\n\n const token =\n notation.form === \"simple\"\n ? notation.token\n : notation.literals[0]?.kind === \"constant\"\n ? notation.literals[0].token\n : null;\n const meaning = meaningOf(notation);\n\n if (token === null || meaning === null) {\n continue;\n }\n\n const existing = tokenMeanings.get(token);\n\n if (existing !== undefined) {\n if (existing.key !== meaning.key || existing.term !== meaning.term) {\n report(diagnostics, \"token_conflict\", { token }, notation.span);\n }\n continue;\n }\n\n tokenMeanings.set(token, meaning);\n }\n\n const precFixities = new Map<number, Set<\"infixl\" | \"infixr\">>();\n\n for (const notation of notations) {\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n typeof notation.prec === \"number\"\n ) {\n const set = precFixities.get(notation.prec) ?? new Set();\n set.add(notation.fixity);\n precFixities.set(notation.prec, set);\n\n if (set.size > 1) {\n report(\n diagnostics,\n \"precedence_mixed_associativity\",\n { prec: String(notation.prec) },\n notation.span,\n );\n }\n }\n }\n\n for (const [open, close] of groupingPairs) {\n for (const token of [open, close]) {\n if (tokenMeanings.has(token)) {\n report(\n diagnostics,\n \"grouping_token_conflict\",\n { token },\n {\n start: 0,\n end: 0,\n },\n );\n }\n }\n }\n\n for (const rule of elabRules) {\n const captures = new Map<string, number>();\n\n for (const element of rule.pattern) {\n if (element.kind === \"capture\") {\n if (captures.has(element.name)) {\n report(\n diagnostics,\n \"elab_duplicate_capture\",\n { name: element.name },\n rule.span,\n );\n }\n captures.set(element.name, 0);\n }\n }\n\n for (const element of rule.template) {\n if (element.kind === \"reference\") {\n const count = captures.get(element.name);\n\n if (count === undefined) {\n report(\n diagnostics,\n \"elab_unknown_reference\",\n { name: element.name },\n rule.span,\n );\n continue;\n }\n\n captures.set(element.name, count + 1);\n }\n }\n\n if (!rule.inputOnly) {\n for (const [name, count] of captures) {\n if (count !== 1) {\n report(diagnostics, \"elab_not_invertible\", { name }, rule.span);\n }\n }\n }\n }\n\n const spec: Spec = {\n assocNone,\n coercions,\n delimiters: { left: delimitersLeft, right: delimitersRight },\n display: { dropOuterParens, rotateBrackets },\n groupingPairs,\n lints,\n notations,\n elabRules,\n sorts,\n statements,\n // The union: what the engine splits on, plus what the textbook does.\n surfaceDelimiters: {\n left: new Set([...delimitersLeft, ...surfaceLeft]),\n right: new Set([...delimitersRight, ...surfaceRight]),\n },\n terms,\n };\n\n checkSurfaceDelimiters(spec, surfaceDeclarations, diagnostics);\n\n return { diagnostics, spec };\n}\n"]}
1
+ {"version":3,"file":"spec.js","sourceRoot":"","sources":["../../src/reader/spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,cA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C;YACxC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;gBACrC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;oBAChB,MAAM,CAAC,WAAW,EAAE,qBAAqB,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAS;QACjB,SAAS;QACT,SAAS;QACT,UAAU,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE;QAC5D,OAAO,EAAE,EAAE,eAAe,EAAE,cAAc,EAAE;QAC5C,aAAa;QACb,KAAK;QACL,SAAS;QACT,SAAS;QACT,KAAK;QACL,UAAU;QACV,qEAAqE;QACrE,iBAAiB,EAAE;YACjB,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,WAAW,CAAC,CAAC;YAClD,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,eAAe,EAAE,GAAG,YAAY,CAAC,CAAC;SACtD;QACD,KAAK;KACN,CAAC;IAEF,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,EAAE,WAAW,CAAC,CAAC;IAC/D,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAErC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["/**\n * From parsed statements to a `Spec` — the library's central object: the\n * signature, notations, coercions, and `@syntax` surface metadata of one\n * logical system, validated.\n *\n * Validation here is about the spec being *coherent* (token conflicts,\n * dangling names, non-invertible elab rules); whether the theory proves\n * anything is the engine's business, and axiom bodies pass through opaque.\n */\n\nimport {\n type DelimiterSet,\n delimiterRules,\n isReachableChunk,\n segment,\n} from \"../delimiters.js\";\nimport {\n type Diagnostic,\n diagnostic,\n type Severity,\n type Span,\n} from \"../diagnostics.js\";\nimport { surfaceVocabulary } from \"../vocabulary.js\";\nimport {\n type ElabRule,\n type LintName,\n parseSyntaxAnnotation,\n type SyntaxAnnotation,\n} from \"./annotations.js\";\nimport {\n type Annotation,\n type Binder,\n type NotationLiteral,\n type Precedence,\n parseStatements,\n type Statement,\n} from \"./statements.js\";\n\nexport interface SortInfo {\n readonly foreignAnnotations: readonly Annotation[];\n readonly modifiers: readonly string[];\n readonly name: string;\n readonly roles: readonly string[];\n readonly span: Span;\n /**\n * The sort's variable tokens, read from the engine's own `@vars`\n * annotation (which stays in `foreignAnnotations` untouched — it is the\n * engine's, we only listen in). These are the surface lexicon's\n * identifiers of this sort; whether a quantifier can bind them falls\n * out of the quantifiers' binder sorts, not from here.\n */\n readonly vars: readonly string[];\n}\n\nexport interface TermInfo {\n readonly binders: readonly Binder[];\n /** `@syntax elided`: supplied when an argument of its sort is missing. */\n readonly elided: boolean;\n readonly foreignAnnotations: readonly Annotation[];\n /** True when this came from a `def` rather than a `term`. */\n readonly isDef: boolean;\n /** `@syntax juxtaposed`: adjacency of its sort's leaves denotes it. */\n readonly juxtaposed: boolean;\n readonly name: string;\n readonly returnSort: string;\n readonly roles: readonly string[];\n readonly span: Span;\n}\n\nexport interface CoercionInfo {\n readonly from: string;\n readonly name: string;\n readonly span: Span;\n readonly to: string;\n}\n\nexport type NotationInfo =\n | {\n readonly form: \"general\";\n /** The notation statement's own binders, which its variables name. */\n readonly binders: readonly Binder[];\n readonly literals: readonly NotationLiteral[];\n readonly span: Span;\n readonly term: string;\n }\n | {\n readonly form: \"simple\";\n readonly fixity: \"infixl\" | \"infixr\" | \"prefix\";\n readonly prec: Precedence;\n readonly span: Span;\n readonly term: string;\n readonly token: string;\n };\n\nexport interface Spec {\n readonly assocNone: ReadonlySet<number>;\n readonly coercions: readonly CoercionInfo[];\n /**\n * The theory's own `delimiter` statement — how the *engine* cuts up math\n * strings. Single bytes, because that is all the engine's table holds.\n */\n readonly delimiters: DelimiterSet;\n readonly display: {\n readonly dropOuterParens: boolean;\n readonly rotateBrackets: readonly (readonly [string, string])[] | null;\n };\n /** Always starts with the built-in `(\"(\", \")\")` pair. */\n readonly groupingPairs: readonly (readonly [string, string])[];\n readonly lints: readonly LintName[];\n /** In declaration order; the last notation for a term is canonical. */\n readonly notations: readonly NotationInfo[];\n readonly elabRules: readonly ElabRule[];\n readonly sorts: ReadonlyMap<string, SortInfo>;\n /** Every statement, in order, annotations intact — full fidelity. */\n readonly statements: readonly Statement[];\n /**\n * How *student* input is cut up: `delimiters` unioned with every\n * `@syntax delimiter` the spec declares. A spec that declares none gets\n * the theory's set unchanged — so writing textbook notation tight\n * (`~~P`, `Fxy`) is an explicit opt-in, never something a spec acquires\n * by accident.\n */\n readonly surfaceDelimiters: DelimiterSet;\n readonly terms: ReadonlyMap<string, TermInfo>;\n}\n\nexport interface SpecParse {\n readonly diagnostics: readonly Diagnostic[];\n readonly spec: Spec;\n}\n\nconst TEMPLATES: Record<string, string> = {\n duplicate_declaration: \"{name} is already declared\",\n unknown_sort: \"sort {name} is not declared\",\n unknown_term: \"term {name} is not declared\",\n infix_arity: \"an infix operator needs exactly two regular arguments\",\n unknown_notation_variable:\n \"notation variable {name} is not one of the declaration's binders\",\n token_conflict:\n \"token {token} already has a meaning; a token may carry one parse rule\",\n precedence_mixed_associativity:\n \"precedence {prec} mixes infixl and infixr operators\",\n grouping_token_conflict:\n \"{token} is a grouping bracket and cannot also be a notation token\",\n elab_duplicate_capture: \"capture {name} appears twice in the pattern\",\n elab_unknown_reference:\n \"the template references {name}, which the pattern does not capture\",\n elab_not_invertible:\n \"capture {name} is not used exactly once in the template; mark the rule input-only if that is intended\",\n elab_literal_split:\n \"the literal {literal} is not one chunk — the delimiters read it as {chunks}; write those as separate elements\",\n elab_literal_looks_like_capture:\n \"the literal {literal} contains ?; a capture is its own element, so write it with spaces around it\",\n juxtaposed_target:\n \"@syntax juxtaposed must sit on a binary term whose arguments and result share one sort\",\n juxtaposed_needs_notation:\n \"a juxtaposed term needs a declared notation, so the engine can read it\",\n juxtaposed_duplicate: \"sort {sort} already has a juxtaposed combiner\",\n elided_target: \"@syntax elided must sit on a term with no arguments\",\n elided_duplicate: \"sort {sort} already has an elided term\",\n vars_term_conflict:\n \"@vars token {token} is also a declared term; a name can be only one\",\n role_target: \"@syntax role must sit on a sort or a term\",\n delimiter_unknown:\n \"delimiter {token} is neither a notation token, a bracket, nor a lexicon name, so no input can ever be read as it\",\n delimiter_token_not_delimited:\n \"{token} is not a surface delimiter; it is only read when whitespace or a delimiter bounds it, so it will run into an adjacent token\",\n delimiter_unreachable_name:\n \"the delimiters split {name} into {chunks}, so it can never be read as one name\",\n};\n\nfunction report(\n diagnostics: Diagnostic[],\n id: string,\n params: Record<string, string>,\n span: Span,\n severity: Severity = \"error\",\n): void {\n diagnostics.push(\n diagnostic(id, TEMPLATES[id] ?? id, params, span, severity),\n );\n}\n\n/** The binder count an application must fill (bound and regular alike). */\nfunction regularBinders(binders: readonly Binder[]): readonly Binder[] {\n return binders.filter((binder) => !binder.binds);\n}\n\nfunction binderSortOf(binder: Binder): string {\n return \"sort\" in binder.type ? binder.type.sort : \"\";\n}\n\ninterface TokenMeaning {\n readonly key: string;\n readonly term: string;\n}\n\n/**\n * One line per parse rule a token can carry. Two identical lines are a\n * pointless duplicate but not an ambiguity; anything else sharing a token\n * is a conflict.\n */\nfunction meaningOf(notation: NotationInfo): TokenMeaning | null {\n if (notation.form === \"simple\") {\n return {\n key: `${notation.fixity}:${String(notation.prec)}`,\n term: notation.term,\n };\n }\n\n const first = notation.literals[0];\n\n if (first === undefined || first.kind !== \"constant\") {\n return null;\n }\n\n return { key: \"general\", term: notation.term };\n}\n\n/** Where each notation constant was declared, for pointing a diagnostic. */\nfunction tokenSpans(spec: Spec): Map<string, Span> {\n const spans = new Map<string, Span>();\n\n for (const notation of spec.notations) {\n const constants =\n notation.form === \"simple\"\n ? [notation.token]\n : notation.literals\n .filter((literal) => literal.kind === \"constant\")\n .map((literal) => literal.token);\n\n for (const token of constants) {\n if (!spans.has(token)) {\n spans.set(token, notation.span);\n }\n }\n }\n\n return spans;\n}\n\n/**\n * The surface delimiter set, checked against the vocabulary it has to cut\n * up. Only runs when the spec declares `@syntax delimiter`: a spec that\n * declares none is read under the theory's own delimiters, where tokens\n * are whitespace-separated and none of this can bite.\n */\nfunction checkSurfaceDelimiters(\n spec: Spec,\n declarations: readonly { entries: readonly string[]; span: Span }[],\n diagnostics: Diagnostic[],\n): void {\n const fallback = declarations[0]?.span;\n\n if (fallback === undefined) {\n return;\n }\n\n const vocabulary = surfaceVocabulary(spec);\n const rules = delimiterRules(spec.surfaceDelimiters);\n const declared = new Set([\n ...spec.surfaceDelimiters.left,\n ...spec.surfaceDelimiters.right,\n ]);\n\n // A delimiter nothing can be classified as cuts input into pieces the\n // parser must then reject — a boundary with no meaning behind it.\n for (const { entries, span } of declarations) {\n for (const entry of entries) {\n if (!vocabulary.tokens.has(entry) && !vocabulary.names.has(entry)) {\n report(diagnostics, \"delimiter_unknown\", { token: entry }, span);\n }\n }\n }\n\n // A token that is not itself a delimiter still reads when whitespace or a\n // delimiter bounds it — `P->Q` is fine with the letters declared — so this\n // is advice, not breakage. What it warns about is two such tokens\n // meeting: `->~` is one chunk unless one of them delimits.\n const spans = tokenSpans(spec);\n\n for (const token of vocabulary.tokens) {\n if (!declared.has(token)) {\n report(\n diagnostics,\n \"delimiter_token_not_delimited\",\n { token },\n spans.get(token) ?? fallback,\n \"warning\",\n );\n }\n }\n\n // A name the delimiters split apart is unreachable: segmentation happens\n // before anything knows the name exists, so no bracketing recovers it.\n // Elided terms are exempt — they are supplied by the parser and dropped\n // by the printer, never typed.\n for (const [name, ref] of vocabulary.names) {\n if (ref.kind === \"term\" && spec.terms.get(ref.term)?.elided === true) {\n continue;\n }\n\n if (isReachableChunk(name, rules)) {\n continue;\n }\n\n const span =\n ref.kind === \"term\"\n ? spec.terms.get(ref.term)?.span\n : spec.sorts.get(ref.sort)?.span;\n\n report(\n diagnostics,\n \"delimiter_unreachable_name\",\n { chunks: segment(name, rules).join(\" \"), name },\n span ?? fallback,\n );\n }\n}\n\n/**\n * Elab literals against the delimiters that will cut up the text they have\n * to match. A literal need not be declared vocabulary — that is the point\n * of the layer — but it is matched one chunk at a time, so a literal the\n * delimiters split can never match anything, and a rule that quietly does\n * nothing is the failure this reader exists to prevent.\n *\n * Template literals are checked too, for every rule that is not\n * `input-only`: delaboration runs the rule inverted, where the template's\n * literals *are* the pattern.\n */\nfunction checkElabLiterals(spec: Spec, diagnostics: Diagnostic[]): void {\n const rules = delimiterRules(spec.surfaceDelimiters);\n\n const check = (token: string, span: Span): void => {\n // `parsePattern` splits on whitespace, so `(?x:var)` arrives as one\n // literal rather than three elements. It would trip the split check\n // below as well, but this names the actual mistake.\n if (token.includes(\"?\")) {\n report(\n diagnostics,\n \"elab_literal_looks_like_capture\",\n { literal: token },\n span,\n );\n return;\n }\n\n if (!isReachableChunk(token, rules)) {\n report(\n diagnostics,\n \"elab_literal_split\",\n { chunks: segment(token, rules).join(\" \"), literal: token },\n span,\n );\n }\n };\n\n for (const rule of spec.elabRules) {\n for (const element of rule.pattern) {\n if (element.kind === \"literal\") {\n check(element.token, rule.span);\n }\n }\n\n if (rule.inputOnly) {\n continue;\n }\n\n for (const element of rule.template) {\n if (element.kind === \"literal\") {\n check(element.token, rule.span);\n }\n }\n }\n}\n\nexport function parseSpec(source: string): SpecParse {\n const { statements, diagnostics: parseDiagnostics } =\n parseStatements(source);\n const diagnostics: Diagnostic[] = [...parseDiagnostics];\n\n const sorts = new Map<string, SortInfo>();\n const terms = new Map<string, TermInfo>();\n const coercions: CoercionInfo[] = [];\n const notations: NotationInfo[] = [];\n const elabRules: ElabRule[] = [];\n const lints: LintName[] = [];\n const assocNone = new Set<number>();\n const delimitersLeft = new Set<string>();\n const delimitersRight = new Set<string>();\n const surfaceLeft = new Set<string>();\n const surfaceRight = new Set<string>();\n const surfaceDeclarations: {\n readonly entries: readonly string[];\n readonly span: Span;\n }[] = [];\n const groupingPairs: (readonly [string, string])[] = [[\"(\", \")\"]];\n let dropOuterParens = false;\n let rotateBrackets: readonly (readonly [string, string])[] | null = null;\n\n // ── First pass: split each statement's annotations, collect declarations.\n\n interface Attached {\n readonly annotation: SyntaxAnnotation;\n readonly span: Span;\n readonly statement: Statement;\n }\n\n const attached: Attached[] = [];\n\n for (const statement of statements) {\n const foreign: Annotation[] = [];\n\n for (const annotation of statement.annotations) {\n const parsed = parseSyntaxAnnotation(annotation.text, annotation.span);\n\n if (parsed === null) {\n foreign.push(annotation);\n continue;\n }\n\n if (parsed.diagnostic !== null) {\n diagnostics.push(parsed.diagnostic);\n continue;\n }\n\n attached.push({\n annotation: parsed.annotation,\n span: annotation.span,\n statement,\n });\n }\n\n switch (statement.kind) {\n case \"sort\": {\n if (sorts.has(statement.name) || terms.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n // The engine's `@vars` pools are this library's variable lexicon\n // too; the lines stay foreign (they are the engine's to keep).\n const vars: string[] = [];\n\n for (const annotation of foreign) {\n const match = /^@vars\\s+(.+)$/.exec(annotation.text.trim());\n\n if (match !== null) {\n vars.push(\n ...(match[1] ?? \"\").split(/\\s+/).filter((w) => w.length > 0),\n );\n }\n }\n\n sorts.set(statement.name, {\n foreignAnnotations: foreign,\n modifiers: statement.modifiers,\n name: statement.name,\n roles: [],\n span: statement.span,\n vars,\n });\n break;\n }\n\n case \"term\":\n case \"def\": {\n if (sorts.has(statement.name) || terms.has(statement.name)) {\n report(\n diagnostics,\n \"duplicate_declaration\",\n { name: statement.name },\n statement.span,\n );\n break;\n }\n\n const returnSort =\n statement.kind === \"term\"\n ? (statement.returnChain[statement.returnChain.length - 1]\n ?.sort ?? \"\")\n : statement.returnType.sort;\n\n // Arrow sugar on a term (`a > b > c`) desugars to extra anonymous\n // regular binders so arity means one thing everywhere downstream.\n const extra: Binder[] =\n statement.kind === \"term\"\n ? statement.returnChain.slice(0, -1).map((type) => ({\n binds: false,\n dummy: false,\n name: \"_\",\n span: type.span,\n type,\n }))\n : [];\n\n terms.set(statement.name, {\n binders: [...statement.binders, ...extra],\n elided: false,\n foreignAnnotations: foreign,\n isDef: statement.kind === \"def\",\n juxtaposed: false,\n name: statement.name,\n returnSort,\n roles: [],\n span: statement.span,\n });\n break;\n }\n\n case \"coercion\": {\n coercions.push({\n from: statement.from,\n name: statement.name,\n span: statement.span,\n to: statement.to,\n });\n break;\n }\n\n case \"delimiter\": {\n for (const ch of statement.left) {\n delimitersLeft.add(ch);\n }\n for (const ch of statement.right) {\n delimitersRight.add(ch);\n }\n break;\n }\n\n case \"simple-notation\": {\n notations.push({\n form: \"simple\",\n fixity: statement.fixity,\n prec: statement.prec,\n span: statement.span,\n term: statement.term,\n token: statement.token,\n });\n break;\n }\n\n case \"notation\": {\n notations.push({\n form: \"general\",\n binders: statement.binders,\n literals: statement.literals,\n span: statement.span,\n term: statement.term,\n });\n\n for (const literal of statement.literals) {\n if (\n literal.kind === \"variable\" &&\n !statement.binders.some((b) => b.name === literal.name)\n ) {\n report(\n diagnostics,\n \"unknown_notation_variable\",\n { name: literal.name },\n literal.span,\n );\n }\n }\n break;\n }\n\n case \"axiom\":\n case \"theorem\":\n break;\n }\n }\n\n // ── Second pass: interpret @syntax annotations now that names resolve.\n\n const juxtaposedBySort = new Map<string, string>();\n const elidedBySort = new Map<string, string>();\n\n for (const { annotation, span, statement } of attached) {\n switch (annotation.kind) {\n case \"juxtaposed\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n const regular =\n info === undefined ? [] : regularBinders(info.binders);\n const sort = info?.returnSort ?? \"\";\n\n if (\n info === undefined ||\n info.binders.length !== 2 ||\n regular.length !== 2 ||\n regular.some((binder) => binderSortOf(binder) !== sort)\n ) {\n report(diagnostics, \"juxtaposed_target\", {}, span);\n break;\n }\n\n if (!notations.some((notation) => notation.term === info.name)) {\n report(diagnostics, \"juxtaposed_needs_notation\", {}, span);\n break;\n }\n\n if (juxtaposedBySort.has(sort)) {\n report(diagnostics, \"juxtaposed_duplicate\", { sort }, span);\n break;\n }\n\n juxtaposedBySort.set(sort, info.name);\n terms.set(info.name, { ...info, juxtaposed: true });\n break;\n }\n\n case \"elided\": {\n const info =\n statement.kind === \"term\" || statement.kind === \"def\"\n ? terms.get(statement.name)\n : undefined;\n\n if (info === undefined || regularBinders(info.binders).length !== 0) {\n report(diagnostics, \"elided_target\", {}, span);\n break;\n }\n\n if (elidedBySort.has(info.returnSort)) {\n report(\n diagnostics,\n \"elided_duplicate\",\n { sort: info.returnSort },\n span,\n );\n break;\n }\n\n elidedBySort.set(info.returnSort, info.name);\n terms.set(info.name, { ...info, elided: true });\n break;\n }\n\n case \"role\": {\n if (statement.kind === \"sort\") {\n const info = sorts.get(statement.name);\n\n if (info !== undefined) {\n sorts.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n if (statement.kind !== \"term\" && statement.kind !== \"def\") {\n report(diagnostics, \"role_target\", {}, span);\n break;\n }\n\n const info = terms.get(statement.name);\n\n if (info !== undefined) {\n terms.set(statement.name, {\n ...info,\n roles: [...info.roles, annotation.role],\n });\n }\n break;\n }\n\n case \"brackets\": {\n for (const pair of annotation.pairs) {\n const exists = groupingPairs.some(\n ([open, close]) => open === pair[0] && close === pair[1],\n );\n\n if (!exists) {\n groupingPairs.push(pair);\n }\n }\n break;\n }\n\n case \"delimiter\": {\n for (const entry of annotation.left) {\n surfaceLeft.add(entry);\n }\n\n for (const entry of annotation.right) {\n surfaceRight.add(entry);\n }\n\n surfaceDeclarations.push({\n entries: [...new Set([...annotation.left, ...annotation.right])],\n span,\n });\n break;\n }\n\n case \"assoc-none\": {\n assocNone.add(annotation.prec);\n break;\n }\n\n case \"lint\": {\n if (!lints.includes(annotation.name)) {\n lints.push(annotation.name);\n }\n break;\n }\n\n case \"display-drop-outer-parens\": {\n dropOuterParens = true;\n break;\n }\n\n case \"display-rotate-brackets\": {\n rotateBrackets = annotation.pairs;\n break;\n }\n\n case \"elab\": {\n elabRules.push(annotation.rule);\n break;\n }\n }\n }\n\n // ── Validation over the collected spec.\n\n for (const info of terms.values()) {\n for (const binder of info.binders) {\n if (\"sort\" in binder.type && !sorts.has(binder.type.sort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: binder.type.sort },\n binder.type.span,\n );\n }\n }\n\n if (info.returnSort !== \"\" && !sorts.has(info.returnSort)) {\n report(\n diagnostics,\n \"unknown_sort\",\n { name: info.returnSort },\n info.span,\n );\n }\n }\n\n for (const sort of sorts.values()) {\n for (const token of sort.vars) {\n if (terms.has(token)) {\n report(diagnostics, \"vars_term_conflict\", { token }, sort.span);\n }\n }\n }\n\n for (const coercion of coercions) {\n if (!terms.has(coercion.name)) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: coercion.name },\n coercion.span,\n );\n }\n for (const sort of [coercion.from, coercion.to]) {\n if (!sorts.has(sort)) {\n report(diagnostics, \"unknown_sort\", { name: sort }, coercion.span);\n }\n }\n }\n\n const tokenMeanings = new Map<string, { key: string; term: string }>();\n\n for (const notation of notations) {\n const info = terms.get(notation.term);\n\n if (info === undefined) {\n report(\n diagnostics,\n \"unknown_term\",\n { name: notation.term },\n notation.span,\n );\n continue;\n }\n\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n (regularBinders(info.binders).length !== 2 ||\n info.binders.some((b) => b.binds))\n ) {\n report(diagnostics, \"infix_arity\", {}, notation.span);\n }\n\n const token =\n notation.form === \"simple\"\n ? notation.token\n : notation.literals[0]?.kind === \"constant\"\n ? notation.literals[0].token\n : null;\n const meaning = meaningOf(notation);\n\n if (token === null || meaning === null) {\n continue;\n }\n\n const existing = tokenMeanings.get(token);\n\n if (existing !== undefined) {\n if (existing.key !== meaning.key || existing.term !== meaning.term) {\n report(diagnostics, \"token_conflict\", { token }, notation.span);\n }\n continue;\n }\n\n tokenMeanings.set(token, meaning);\n }\n\n const precFixities = new Map<number, Set<\"infixl\" | \"infixr\">>();\n\n for (const notation of notations) {\n if (\n notation.form === \"simple\" &&\n notation.fixity !== \"prefix\" &&\n typeof notation.prec === \"number\"\n ) {\n const set = precFixities.get(notation.prec) ?? new Set();\n set.add(notation.fixity);\n precFixities.set(notation.prec, set);\n\n if (set.size > 1) {\n report(\n diagnostics,\n \"precedence_mixed_associativity\",\n { prec: String(notation.prec) },\n notation.span,\n );\n }\n }\n }\n\n for (const [open, close] of groupingPairs) {\n for (const token of [open, close]) {\n if (tokenMeanings.has(token)) {\n report(\n diagnostics,\n \"grouping_token_conflict\",\n { token },\n {\n start: 0,\n end: 0,\n },\n );\n }\n }\n }\n\n for (const rule of elabRules) {\n const captures = new Map<string, number>();\n\n for (const element of rule.pattern) {\n if (element.kind === \"capture\") {\n if (captures.has(element.name)) {\n report(\n diagnostics,\n \"elab_duplicate_capture\",\n { name: element.name },\n rule.span,\n );\n }\n captures.set(element.name, 0);\n }\n }\n\n for (const element of rule.template) {\n if (element.kind === \"reference\") {\n const count = captures.get(element.name);\n\n if (count === undefined) {\n report(\n diagnostics,\n \"elab_unknown_reference\",\n { name: element.name },\n rule.span,\n );\n continue;\n }\n\n captures.set(element.name, count + 1);\n }\n }\n\n if (!rule.inputOnly) {\n for (const [name, count] of captures) {\n if (count !== 1) {\n report(diagnostics, \"elab_not_invertible\", { name }, rule.span);\n }\n }\n }\n }\n\n const spec: Spec = {\n assocNone,\n coercions,\n delimiters: { left: delimitersLeft, right: delimitersRight },\n display: { dropOuterParens, rotateBrackets },\n groupingPairs,\n lints,\n notations,\n elabRules,\n sorts,\n statements,\n // The union: what the engine splits on, plus what the textbook does.\n surfaceDelimiters: {\n left: new Set([...delimitersLeft, ...surfaceLeft]),\n right: new Set([...delimitersRight, ...surfaceRight]),\n },\n terms,\n };\n\n checkSurfaceDelimiters(spec, surfaceDeclarations, diagnostics);\n checkElabLiterals(spec, diagnostics);\n\n return { diagnostics, spec };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aufbau/syntax",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Surface syntax over MM0: a statement reader, a delimiter scanner, a faithful math-string parser, a pretty-printer, and a bidirectional token-elaboration layer for textbook logical notations.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {