@aufbau/syntax 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,47 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ Initial development. The layer stack is complete and tested end to end:
6
+
7
+ - MM0 statement reader (`parseSpec`) with `@syntax` annotations and spec
8
+ validation.
9
+ - Character-level scanner: no-whitespace textbook input, declared-name
10
+ and `@vars` lexicon tokens, alternative readings.
11
+ - Surface parser: a port of MM0's dynamic math parser with declared
12
+ extensions only (grouping pairs, assoc-none levels, a closed lint set,
13
+ per-term `elided` and `juxtaposed`), coercion insertion, and
14
+ backtracking disambiguation.
15
+ - Printer: display mode (canonical-last spellings, full-paren-drop-outer,
16
+ derived spacing, elision, juxtaposed atoms) and engine mode, with
17
+ round-trip laws under test.
18
+ - Bidirectional token-elaboration layer (`@syntax elab`) with source-span
19
+ origin mapping.
20
+ - Engine helpers: `stripSyntaxAnnotations`, `boundVariableBinders`;
21
+ alignment with the real Aufbau compiler is proven in
22
+ `tests/engine-align.test.ts`.
23
+ - Example specs: `forallx-calgary-2019`, `forallx-magnus`, `carnap-prop`.
24
+ - Packaging and CI: the published package is code only — `dist/` — with the
25
+ specs in this repository demoted to examples and fixtures, since a spec
26
+ encodes a textbook's conventions and belongs to the application teaching
27
+ from it. A `tsc` build to `dist/` (JavaScript plus declarations),
28
+ a Node smoke test of the built artifact, and the two GitHub Actions
29
+ workflows Aufbau uses — tests on every push and pull request, canary
30
+ publishes from `main`, stable publishes from a `v1.2.3` tag, both with npm
31
+ provenance. See `docs/releasing.md`.
32
+
33
+ Replaced before any release: the original `@syntax family` letter-schema
34
+ mechanism (letter ranges, subscript lexing, template elaboration,
35
+ combiner discovery by shape). The lexicon is now ordinary MM0 — declared
36
+ terms plus the engine's `@vars` pools — with two per-term annotations,
37
+ `elided` and `juxtaposed`, carrying what the declarations cannot say.
38
+ Deliberate casualties: subscripted atoms (`x_1`, `P0`; the vocabulary is
39
+ finite) and one-letter-two-kinds (bare `P` is now the seq-taking
40
+ declaration applied to the elided empty sequence, so trees read
41
+ `P(snil)`).
42
+
43
+ Also renamed before any release: `@syntax rewrite` is now `@syntax elab`.
44
+ The engine's `@rewrite` marks directed rules over *terms* for proof-search
45
+ normalization, and theories carrying both annotations read badly; this
46
+ layer only ever rewrites tokens, elaborating surface spelling on the way
47
+ in and delaborating on the way out.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # @aufbau/syntax
2
+
3
+ Surface syntax over MM0, for teaching logic.
4
+
5
+ An [MM0](https://github.com/digama0/mm0) theory file already fixes a
6
+ language's signature, lexicon, binding structure, precedences, and
7
+ canonical notation — the letters are ordinary term declarations, the
8
+ variables the engine's own `@vars` pools. This library reads such a file —
9
+ plus a small set of `@syntax` annotations in
10
+ [Aufbau](https://github.com/gleachkr/Aufbau)'s `--|` comment channel — and
11
+ derives from it the two things MM0's own math parser cannot give a logic
12
+ classroom:
13
+
14
+ - a **student surface language**: character-level, whitespace-free textbook
15
+ notation (`∀xF(x)`, `Fxyz`, `~~P`), alias spellings, per-textbook bracket
16
+ and parenthesization conventions;
17
+ - a **display language**: canonical pretty-printing with the textbook's own
18
+ conventions (dropped outer parentheses, juxtaposed arguments, rotated
19
+ brackets).
20
+
21
+ Everything a student types is parsed into a term tree over the declared
22
+ signature and can be printed back out — either sugared for display, or in
23
+ engine mode as spaced canonical text the Aufbau compiler parses directly.
24
+ One spec file per textbook system; no code per system.
25
+
26
+ ## The layer stack
27
+
28
+ 1. **Statement reader** — parses the MM0 statement grammar (sorts, terms,
29
+ notations, coercions, delimiters) and `--|` annotations into a `Spec`.
30
+ `@syntax` annotations are understood structurally; all others (`@acui`,
31
+ `@congr`, …) pass through as data — except `@vars`, which is read *and*
32
+ passed through: the engine's variable pools are the surface lexicon's
33
+ variables.
34
+ 2. **Scanner** — character-level maximal munch over the declared tokens and
35
+ lexicon names. No whitespace requirement; glue dissolves here.
36
+ 3. **Elaboration layer** — bidirectional token-pattern rules (`@syntax
37
+ elab`) for textbook sugar that really is local (`(x)Fx` ⇄ `∀xF(x)`,
38
+ `(∀x)` ⇄ `∀x`). Regular by design: one pass per rule, spans threaded
39
+ through, linear rules delaborate for printing. Juxtaposition is
40
+ deliberately *not* here — it needs the parser's backtracking — hence
41
+ the `juxtaposed` flag below.
42
+ 4. **Math parser** — a faithful port of MM0's dynamic precedence parser,
43
+ extended by declared conventions only: variant grouping pairs,
44
+ `assoc-none` precedence levels, a closed set of lints, and per-term
45
+ `elided` (bare `P` is `P(snil)`) and `juxtaposed` (adjacency at a sort
46
+ denotes its combiner — `Rxy`) flags.
47
+ 5. **Printer** — last-declared notation is canonical; minimal parentheses
48
+ by precedence; display options; invertible elab rules delaborate.
49
+
50
+ ## Status
51
+
52
+ Pre-release, but the layer stack is complete and tested end to end: three
53
+ example specs (`forallx-calgary-2019`, `forallx-magnus`, `carnap-prop`),
54
+ a behavioral corpus transcribed from the parsers this library replaces,
55
+ round-trip laws for both print modes, and an acceptance test in which the
56
+ real Aufbau compiler parses this library's engine output and certifies it
57
+ tree-identical to hand-written spellings (`tests/engine-align.test.ts`).
58
+
59
+ ```ts
60
+ import { parseSpec, printTerm, SurfaceLanguage } from "@aufbau/syntax";
61
+
62
+ const { spec, diagnostics } = parseSpec(specSource); // an .mm0 + @syntax
63
+ const language = new SurfaceLanguage(spec);
64
+
65
+ const result = language.parse("AxEy~R(x,y)"); // student input
66
+ if (result.ok) {
67
+ printTerm(language, result.term, "display"); // "∀x∃y¬R(x,y)"
68
+ printTerm(language, result.term, "engine"); // for the compiler
69
+ }
70
+ ```
71
+
72
+ See `docs/syntax-annotations.md` for the annotation reference and
73
+ `docs/authoring-a-spec.md` for how to write a new system.
74
+
75
+ ## Installing
76
+
77
+ ```sh
78
+ bun add @aufbau/syntax # released
79
+ bun add @aufbau/syntax@canary # the build of the current main
80
+ ```
81
+
82
+ The package is code and nothing else: compiled JavaScript and declarations
83
+ (`dist/`, emitted by `tsc` — there is nothing to bundle, since there are no
84
+ runtime dependencies). Every release is published from CI with npm
85
+ provenance; see `docs/releasing.md`.
86
+
87
+ **The specs in this repository are examples, not a catalogue.** They exist to
88
+ exercise the layer stack and to show what a spec looks like; they are not
89
+ published, and no application should depend on one. A spec encodes a
90
+ *textbook's* conventions, which is the application's subject matter, not the
91
+ library's — so an application keeps its own specs in its own tree, in whatever
92
+ form its build wants (a string constant, a bundled asset, a database row),
93
+ and hands the source text to `parseSpec`. This library's business ends at
94
+ "given this spec, parse and print".
95
+
96
+ ## Development
97
+
98
+ There is a flake, as in the other Aufbau repositories — `nix develop`, or
99
+ `direnv allow` and let the `.envrc` do it. The shell carries the toolchain CI
100
+ runs with — Bun for the suite, Node 24 for the release scripts and the smoke
101
+ test — so a failure here is a failure there. When a `flake.lock` bump moves
102
+ Bun off the version `.github/workflows/test.yml` pins, move the workflow too.
103
+
104
+ ```sh
105
+ bun install
106
+ bun run validate # bun test + tsc --noEmit + biome ci
107
+ bun run build # dist/, what actually ships
108
+ node scripts/smoke.mjs # the built package, exercised from plain Node
109
+ ```
110
+
111
+ Relative imports inside `src/` carry `.js` extensions. `tsc` emits import
112
+ specifiers verbatim, so that is what makes the published `dist/` loadable by
113
+ Node's ESM resolver as well as by bundlers — Bun's own resolution is more
114
+ forgiving than the world's, which is why the smoke test runs under Node.
115
+
116
+ `src/` is platform-global-free — no DOM, no Bun, no Workers APIs — because
117
+ its consumers are browsers, Cloudflare Workers, and Bun alike. A test
118
+ enforces this.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Diagnostics carried by every layer of the library.
3
+ *
4
+ * Each diagnostic is structured — a stable id, its parameters, and a source
5
+ * span — so a consumer can reword or translate it. `message` is the id's
6
+ * English template with the parameters filled in, so a consumer that does
7
+ * neither still has something to show.
8
+ */
9
+ /** Half-open range of UTF-16 code-unit offsets into the source text. */
10
+ export interface Span {
11
+ readonly start: number;
12
+ readonly end: number;
13
+ }
14
+ export interface Diagnostic {
15
+ readonly id: string;
16
+ readonly message: string;
17
+ readonly params: Readonly<Record<string, string>>;
18
+ readonly span: Span;
19
+ }
20
+ /**
21
+ * Fill `{name}` holes in a template. A hole with no matching parameter is
22
+ * left as written, which makes a mismatched template visible in output
23
+ * rather than silently blank.
24
+ */
25
+ export declare function fillTemplate(template: string, params: Readonly<Record<string, string>>): string;
26
+ export declare function diagnostic(id: string, template: string, params: Readonly<Record<string, string>>, span: Span): Diagnostic;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Diagnostics carried by every layer of the library.
3
+ *
4
+ * Each diagnostic is structured — a stable id, its parameters, and a source
5
+ * span — so a consumer can reword or translate it. `message` is the id's
6
+ * English template with the parameters filled in, so a consumer that does
7
+ * neither still has something to show.
8
+ */
9
+ /**
10
+ * Fill `{name}` holes in a template. A hole with no matching parameter is
11
+ * left as written, which makes a mismatched template visible in output
12
+ * rather than silently blank.
13
+ */
14
+ export function fillTemplate(template, params) {
15
+ return template.replace(/\{(\w+)\}/g, (hole, name) => {
16
+ const value = params[name];
17
+ return value === undefined ? hole : value;
18
+ });
19
+ }
20
+ export function diagnostic(id, template, params, span) {
21
+ return { id, message: fillTemplate(template, params), params, span };
22
+ }
23
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,MAAwC;IAExC,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAY,EAAE,EAAE;QAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,EAAU,EACV,QAAgB,EAChB,MAAwC,EACxC,IAAU;IAEV,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AACvE,CAAC","sourcesContent":["/**\n * Diagnostics carried by every layer of the library.\n *\n * Each diagnostic is structured — a stable id, its parameters, and a source\n * span — so a consumer can reword or translate it. `message` is the id's\n * English template with the parameters filled in, so a consumer that does\n * neither still has something to show.\n */\n\n/** Half-open range of UTF-16 code-unit offsets into the source text. */\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\nexport interface Diagnostic {\n readonly id: string;\n readonly message: string;\n readonly params: Readonly<Record<string, string>>;\n readonly span: Span;\n}\n\n/**\n * Fill `{name}` holes in a template. A hole with no matching parameter is\n * left as written, which makes a mismatched template visible in output\n * rather than silently blank.\n */\nexport function fillTemplate(\n template: string,\n params: Readonly<Record<string, string>>,\n): string {\n return template.replace(/\\{(\\w+)\\}/g, (hole, name: string) => {\n const value = params[name];\n return value === undefined ? hole : value;\n });\n}\n\nexport function diagnostic(\n id: string,\n template: string,\n params: Readonly<Record<string, string>>,\n span: Span,\n): Diagnostic {\n return { id, message: fillTemplate(template, params), params, span };\n}\n"]}
package/dist/elab.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The bidirectional token-elaboration layer — `@syntax elab` rules.
3
+ *
4
+ * Forward (elaboration, before the parser): each rule makes one
5
+ * left-to-right pass over the text, matching at token boundaries only.
6
+ * Where a rule matches, its template is spliced in — literals in their own
7
+ * spelling, captures copied from the source — separated by spaces so the
8
+ * result re-scans cleanly. No fixpoints: matching resumes *after* each
9
+ * replacement, and rules run in declaration order, so the layer terminates
10
+ * by construction. An origin map carries every emitted offset back to
11
+ * the source, so diagnostics and term spans point at what the writer
12
+ * actually typed.
13
+ *
14
+ * Backward (delaboration, after the display printer): the same rules run
15
+ * inverted — template as pattern, pattern as replacement — in reverse
16
+ * declaration order, joined tight, skipping `input-only` rules. A linear
17
+ * rule is a lens: the Quine rule `( ?x:var ) => ∀ ?x` read backward *is*
18
+ * the display convention that writes `∀x` as `(x)`.
19
+ *
20
+ * Captures match single lexicon names — a `@vars` token or a nullary
21
+ * declared term — whose sort coerces into the capture's named sort. The
22
+ * layer is deliberately regular — nesting facts belong to the parser.
23
+ */
24
+ import type { SurfaceLanguage } from "./parse.js";
25
+ export interface Elaborated {
26
+ /** For each offset of `text`, the source offset it came from. */
27
+ readonly origin: readonly number[];
28
+ readonly text: string;
29
+ }
30
+ /**
31
+ * Apply every elaboration rule forward, in declaration order, returning
32
+ * the elaborated text and the offset map back to the source.
33
+ */
34
+ export declare function elaborate(lang: SurfaceLanguage, text: string): Elaborated;
35
+ /**
36
+ * Apply every invertible rule backward over display text, last declared
37
+ * first, joining replacements tight (display is character-level anyway).
38
+ */
39
+ export declare function delaborate(lang: SurfaceLanguage, text: string): string;
40
+ /** An elaborated-text span mapped back to source offsets. */
41
+ export declare function remapSpan(origin: readonly number[], span: {
42
+ readonly start: number;
43
+ readonly end: number;
44
+ }): {
45
+ start: number;
46
+ end: number;
47
+ };