@aufbau/syntax 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,21 +33,37 @@ export function surfaceVocabulary(spec) {
33
33
  tokens.add(open);
34
34
  tokens.add(close);
35
35
  }
36
- const coercions = new Set(spec.coercions.map((c) => c.name));
37
36
  const names = new Map();
38
37
  for (const sort of spec.sorts.values()) {
39
38
  for (const token of sort.vars) {
40
39
  names.set(token, { kind: "var", sort: sort.name });
41
40
  }
42
41
  }
42
+ // Every term is a lexicon name: MM0's `FUNC expression(max){n}` applies
43
+ // any constructor by name, notation or no notation, bound binders or
44
+ // none — `sb x t p` beside `[t / x] p`. A `@vars` token keeps the name.
43
45
  for (const term of spec.terms.values()) {
44
- if (!notated.has(term.name) &&
45
- !coercions.has(term.name) &&
46
- !term.binders.some((binder) => binder.binds) &&
47
- !names.has(term.name)) {
46
+ if (!names.has(term.name)) {
48
47
  names.set(term.name, { kind: "term", term: term.name });
49
48
  }
50
49
  }
51
50
  return { names, tokens };
52
51
  }
52
+ /**
53
+ * The terms whose name is their *only* spelling: no notation, not a
54
+ * coercion (inserted silently), no bound binder (a quantifier-shaped term
55
+ * is written by its notation). These are the names the surface delimiters
56
+ * must leave whole; any other term's name is a secondary spelling, MM0's
57
+ * application syntax, and is reachable wherever the engine's own
58
+ * delimiters apply even when a textbook's letter delimiters split it.
59
+ */
60
+ export function nameOnlyTerms(spec) {
61
+ const notated = new Set(spec.notations.map((notation) => notation.term));
62
+ const coercions = new Set(spec.coercions.map((c) => c.name));
63
+ return new Set([...spec.terms.values()]
64
+ .filter((term) => !notated.has(term.name) &&
65
+ !coercions.has(term.name) &&
66
+ !term.binders.some((binder) => binder.binds))
67
+ .map((term) => term.name));
68
+ }
53
69
  //# sourceMappingURL=vocabulary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vocabulary.js","sourceRoot":"","sources":["../src/vocabulary.ts"],"names":[],"mappings":"AAA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I,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QACvC,IACE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YACvB,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YACzB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;YAC5C,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EACrB,CAAC;YACD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * The surface vocabulary a spec declares: the tokens and the lexicon names\n * a chunk of input can be classified as.\n *\n * Derived, never annotated. The tokens are the constants of every notation\n * plus the grouping brackets. The names are every token in a sort's `@vars`\n * pool, and every declared term that has no notation of its own, binds\n * nothing, and is not a coercion — a term *with* a notation is spelled by\n * that notation; a term without one is spelled by its name, which is MM0's\n * own application rule read character-level.\n *\n * It lives apart from the scanner because the spec reader needs it too: a\n * declared delimiter that names nothing here is an authoring error, and a\n * lexicon name that the delimiters would split is unreachable.\n */\n\nimport type { Spec } from \"./reader/spec.js\";\n\nexport type NameRef =\n | { readonly kind: \"term\"; readonly term: string }\n | { readonly kind: \"var\"; readonly sort: string };\n\nexport interface Vocabulary {\n /** Lexicon names, and what each refers to. */\n readonly names: ReadonlyMap<string, NameRef>;\n /** Notation constants and grouping brackets. */\n readonly tokens: ReadonlySet<string>;\n}\n\nexport function surfaceVocabulary(spec: Spec): Vocabulary {\n const tokens = new Set<string>();\n const notated = new Set<string>();\n\n for (const notation of spec.notations) {\n notated.add(notation.term);\n\n if (notation.form === \"simple\") {\n tokens.add(notation.token);\n } else {\n for (const literal of notation.literals) {\n if (literal.kind === \"constant\") {\n tokens.add(literal.token);\n }\n }\n }\n }\n\n for (const [open, close] of spec.groupingPairs) {\n tokens.add(open);\n tokens.add(close);\n }\n\n const coercions = new Set(spec.coercions.map((c) => c.name));\n const names = new Map<string, NameRef>();\n\n for (const sort of spec.sorts.values()) {\n for (const token of sort.vars) {\n names.set(token, { kind: \"var\", sort: sort.name });\n }\n }\n\n for (const term of spec.terms.values()) {\n if (\n !notated.has(term.name) &&\n !coercions.has(term.name) &&\n !term.binders.some((binder) => binder.binds) &&\n !names.has(term.name)\n ) {\n names.set(term.name, { kind: \"term\", term: term.name });\n }\n }\n\n return { names, tokens };\n}\n"]}
1
+ {"version":3,"file":"vocabulary.js","sourceRoot":"","sources":["../src/vocabulary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAeH,MAAM,UAAU,iBAAiB,CAAC,IAAU;IAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE3B,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACxC,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBAChC,MAAM,CAAC,GAAG,CAAC,OA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,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7D,OAAO,IAAI,GAAG,CACZ,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;SACrB,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QACvB,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QACzB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAC/C;SACA,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAC5B,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The surface vocabulary a spec declares: the tokens and the lexicon names\n * a chunk of input can be classified as.\n *\n * Derived, never annotated. The tokens are the constants of every notation\n * plus the grouping brackets. The names are every token in a sort's `@vars`\n * pool, and every declared term that has no notation of its own, binds\n * nothing, and is not a coercion — a term *with* a notation is spelled by\n * that notation; a term without one is spelled by its name, which is MM0's\n * own application rule read character-level.\n *\n * It lives apart from the scanner because the spec reader needs it too: a\n * declared delimiter that names nothing here is an authoring error, and a\n * lexicon name that the delimiters would split is unreachable.\n */\n\nimport type { Spec } from \"./reader/spec.js\";\n\nexport type NameRef =\n | { readonly kind: \"term\"; readonly term: string }\n | { readonly kind: \"var\"; readonly sort: string };\n\nexport interface Vocabulary {\n /** Lexicon names, and what each refers to. */\n readonly names: ReadonlyMap<string, NameRef>;\n /** Notation constants and grouping brackets. */\n readonly tokens: ReadonlySet<string>;\n}\n\nexport function surfaceVocabulary(spec: Spec): Vocabulary {\n const tokens = new Set<string>();\n const notated = new Set<string>();\n\n for (const notation of spec.notations) {\n notated.add(notation.term);\n\n if (notation.form === \"simple\") {\n tokens.add(notation.token);\n } else {\n for (const literal of notation.literals) {\n if (literal.kind === \"constant\") {\n tokens.add(literal.token);\n }\n }\n }\n }\n\n for (const [open, close] of spec.groupingPairs) {\n tokens.add(open);\n tokens.add(close);\n }\n\n const names = new Map<string, NameRef>();\n\n for (const sort of spec.sorts.values()) {\n for (const token of sort.vars) {\n names.set(token, { kind: \"var\", sort: sort.name });\n }\n }\n\n // Every term is a lexicon name: MM0's `FUNC expression(max){n}` applies\n // any constructor by name, notation or no notation, bound binders or\n // none — `sb x t p` beside `[t / x] p`. A `@vars` token keeps the name.\n for (const term of spec.terms.values()) {\n if (!names.has(term.name)) {\n names.set(term.name, { kind: \"term\", term: term.name });\n }\n }\n\n return { names, tokens };\n}\n\n/**\n * The terms whose name is their *only* spelling: no notation, not a\n * coercion (inserted silently), no bound binder (a quantifier-shaped term\n * is written by its notation). These are the names the surface delimiters\n * must leave whole; any other term's name is a secondary spelling, MM0's\n * application syntax, and is reachable wherever the engine's own\n * delimiters apply even when a textbook's letter delimiters split it.\n */\nexport function nameOnlyTerms(spec: Spec): ReadonlySet<string> {\n const notated = new Set(spec.notations.map((notation) => notation.term));\n const coercions = new Set(spec.coercions.map((c) => c.name));\n\n return new Set(\n [...spec.terms.values()]\n .filter(\n (term) =>\n !notated.has(term.name) &&\n !coercions.has(term.name) &&\n !term.binders.some((binder) => binder.binds),\n )\n .map((term) => term.name),\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aufbau/syntax",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
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": {