@lokascript/framework 4.5.0 → 4.7.0

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.
Files changed (123) hide show
  1. package/CHANGELOG.md +220 -8
  2. package/dist/api/create-dsl.d.ts +59 -1
  3. package/dist/api/create-dsl.d.ts.map +1 -1
  4. package/dist/api/domain-registry.d.ts.map +1 -1
  5. package/dist/api/index.d.ts +1 -0
  6. package/dist/api/index.d.ts.map +1 -1
  7. package/dist/api/index.js +1938 -724
  8. package/dist/api/index.js.map +1 -1
  9. package/dist/api/reading.d.ts +8 -0
  10. package/dist/api/reading.d.ts.map +1 -0
  11. package/dist/api/translation-loss.d.ts +84 -0
  12. package/dist/api/translation-loss.d.ts.map +1 -0
  13. package/dist/core/index.d.ts +1 -0
  14. package/dist/core/index.d.ts.map +1 -1
  15. package/dist/core/index.js +1047 -684
  16. package/dist/core/index.js.map +1 -1
  17. package/dist/core/matching/confidence-model.d.ts +54 -0
  18. package/dist/core/matching/confidence-model.d.ts.map +1 -0
  19. package/dist/core/matching/index.d.ts +12 -0
  20. package/dist/core/matching/index.d.ts.map +1 -0
  21. package/dist/core/matching/match-skeleton.d.ts +114 -0
  22. package/dist/core/matching/match-skeleton.d.ts.map +1 -0
  23. package/dist/core/matching/stock-confidence.d.ts +15 -0
  24. package/dist/core/matching/stock-confidence.d.ts.map +1 -0
  25. package/dist/core/matching/stock-reader.d.ts +56 -0
  26. package/dist/core/matching/stock-reader.d.ts.map +1 -0
  27. package/dist/core/matching/stock-reading.d.ts +44 -0
  28. package/dist/core/matching/stock-reading.d.ts.map +1 -0
  29. package/dist/core/matching/value-reader.d.ts +62 -0
  30. package/dist/core/matching/value-reader.d.ts.map +1 -0
  31. package/dist/core/pattern-matching/index.js +561 -660
  32. package/dist/core/pattern-matching/index.js.map +1 -1
  33. package/dist/core/pattern-matching/pattern-matcher.d.ts +0 -117
  34. package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
  35. package/dist/core/types.d.ts +48 -0
  36. package/dist/core/types.d.ts.map +1 -1
  37. package/dist/core/types.js.map +1 -1
  38. package/dist/generation/index.d.ts +2 -0
  39. package/dist/generation/index.d.ts.map +1 -1
  40. package/dist/generation/index.js +583 -1
  41. package/dist/generation/index.js.map +1 -1
  42. package/dist/generation/pattern-render.d.ts +72 -0
  43. package/dist/generation/pattern-render.d.ts.map +1 -0
  44. package/dist/generation/schema-patterns.d.ts +152 -0
  45. package/dist/generation/schema-patterns.d.ts.map +1 -0
  46. package/dist/index.cjs +2132 -890
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.js +2110 -887
  49. package/dist/index.js.map +1 -1
  50. package/dist/ir/index.js.map +1 -1
  51. package/dist/parsing/index.js +561 -660
  52. package/dist/parsing/index.js.map +1 -1
  53. package/dist/testing/gate/index.d.ts +8 -0
  54. package/dist/testing/gate/index.d.ts.map +1 -0
  55. package/dist/testing/gate/index.js +632 -0
  56. package/dist/testing/gate/index.js.map +1 -0
  57. package/dist/testing/gate/lint/format.d.ts +7 -0
  58. package/dist/testing/gate/lint/format.d.ts.map +1 -0
  59. package/dist/testing/gate/lint/index.d.ts +30 -0
  60. package/dist/testing/gate/lint/index.d.ts.map +1 -0
  61. package/dist/testing/gate/lint/rules/extractor-coverage.d.ts +18 -0
  62. package/dist/testing/gate/lint/rules/extractor-coverage.d.ts.map +1 -0
  63. package/dist/testing/gate/lint/rules/index.d.ts +14 -0
  64. package/dist/testing/gate/lint/rules/index.d.ts.map +1 -0
  65. package/dist/testing/gate/lint/rules/keyword-classification.d.ts +19 -0
  66. package/dist/testing/gate/lint/rules/keyword-classification.d.ts.map +1 -0
  67. package/dist/testing/gate/lint/rules/keyword-coverage.d.ts +13 -0
  68. package/dist/testing/gate/lint/rules/keyword-coverage.d.ts.map +1 -0
  69. package/dist/testing/gate/lint/rules/marker-tokenization.d.ts +20 -0
  70. package/dist/testing/gate/lint/rules/marker-tokenization.d.ts.map +1 -0
  71. package/dist/testing/gate/lint/rules/position-ordering.d.ts +25 -0
  72. package/dist/testing/gate/lint/rules/position-ordering.d.ts.map +1 -0
  73. package/dist/testing/gate/lint/rules/renderer-coherence.d.ts +24 -0
  74. package/dist/testing/gate/lint/rules/renderer-coherence.d.ts.map +1 -0
  75. package/dist/testing/gate/lint/rules/schema-rules.d.ts +10 -0
  76. package/dist/testing/gate/lint/rules/schema-rules.d.ts.map +1 -0
  77. package/dist/testing/gate/lint/types.d.ts +74 -0
  78. package/dist/testing/gate/lint/types.d.ts.map +1 -0
  79. package/dist/testing/gate/round-trip.d.ts +163 -0
  80. package/dist/testing/gate/round-trip.d.ts.map +1 -0
  81. package/package.json +7 -3
  82. package/src/__test__/fixtures/sql-dsl.ts +11 -2
  83. package/src/__test__/sql-integration.test.ts +2 -2
  84. package/src/api/create-dsl-engine.test.ts +86 -0
  85. package/src/api/create-dsl.test.ts +120 -0
  86. package/src/api/create-dsl.ts +314 -39
  87. package/src/api/domain-registry.test.ts +70 -5
  88. package/src/api/domain-registry.ts +82 -1
  89. package/src/api/index.ts +1 -0
  90. package/src/api/reading.ts +29 -0
  91. package/src/api/translation-loss.test.ts +89 -0
  92. package/src/api/translation-loss.ts +128 -0
  93. package/src/core/index.ts +1 -0
  94. package/src/core/matching/confidence-model.ts +58 -0
  95. package/src/core/matching/index.ts +12 -0
  96. package/src/core/matching/match-skeleton.test.ts +179 -0
  97. package/src/core/matching/match-skeleton.ts +621 -0
  98. package/src/core/matching/stock-confidence.ts +238 -0
  99. package/src/core/matching/stock-reader.test.ts +181 -0
  100. package/src/core/matching/stock-reader.ts +186 -0
  101. package/src/core/matching/stock-reading.ts +681 -0
  102. package/src/core/matching/value-reader.ts +85 -0
  103. package/src/core/pattern-matching/pattern-matcher.ts +11 -876
  104. package/src/core/types.ts +48 -0
  105. package/src/generation/index.ts +2 -0
  106. package/src/generation/pattern-render.ts +378 -0
  107. package/src/generation/schema-patterns.test.ts +99 -0
  108. package/src/generation/schema-patterns.ts +962 -0
  109. package/src/testing/gate/index.ts +8 -0
  110. package/src/testing/gate/lint/format.ts +23 -0
  111. package/src/testing/gate/lint/index.ts +73 -0
  112. package/src/testing/gate/lint/lint.test.ts +131 -0
  113. package/src/testing/gate/lint/rules/extractor-coverage.ts +63 -0
  114. package/src/testing/gate/lint/rules/index.ts +37 -0
  115. package/src/testing/gate/lint/rules/keyword-classification.ts +52 -0
  116. package/src/testing/gate/lint/rules/keyword-coverage.ts +38 -0
  117. package/src/testing/gate/lint/rules/marker-tokenization.ts +129 -0
  118. package/src/testing/gate/lint/rules/position-ordering.ts +87 -0
  119. package/src/testing/gate/lint/rules/renderer-coherence.ts +100 -0
  120. package/src/testing/gate/lint/rules/schema-rules.ts +35 -0
  121. package/src/testing/gate/lint/types.ts +83 -0
  122. package/src/testing/gate/round-trip.test.ts +118 -0
  123. package/src/testing/gate/round-trip.ts +438 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * How a read-back is compared (internal: not exported from the package). `translate` and the
3
+ * registry's translate tool both require a rendering to read back as its source; this is their rule.
4
+ */
5
+ import type { SemanticNode } from '../core/types';
6
+ /** How `back` differs from `source`; empty when it reads the same. */
7
+ export declare function readingDifference(source: SemanticNode, back: SemanticNode): string;
8
+ //# sourceMappingURL=reading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reading.d.ts","sourceRoot":"","sources":["../../src/api/reading.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAYlD,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAWlF"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Fail-loud translation: what a translation checks before it returns (domains
3
+ * rethink Phase 4.5, `docs-internal/DOMAINS_RETHINK.md`). Moved from
4
+ * `@lokascript/semantic`'s `explicit/lossy.ts`, whose `translate` runs it with
5
+ * hyperscript's rules; `createMultilingualDSL`'s `translate` keeps its own
6
+ * read-back (`TranslationReadBackError`).
7
+ *
8
+ * A parse that matches a prefix of a script and leaves the rest unread used to
9
+ * come back from `translate()` as though it were the whole: `toggle .a .b`
10
+ * became `toggle .a`. A surface that cannot carry a script now says so: the
11
+ * translation throws a {@link LossyTranslationError}, which carries the output
12
+ * it would have returned and what it loses. Four checks, cheapest first:
13
+ *
14
+ * - `truncation` the parse of the input left input bound to no role (its
15
+ * `unconsumed-input` diagnostics);
16
+ * - `core-only` the input holds a form the grammar's writer has no spelling
17
+ * for (hyperscript: a form only `@hyperfixi/core` ran, which
18
+ * upstream reads with another meaning) — `rules.unwritable`;
19
+ * - `read-back` the output, read in the target language, does not read,
20
+ * leaves input unread, or differs from what was written
21
+ * (`rules.differences`, in order);
22
+ * - `invariant` a value the translation must write verbatim is missing
23
+ * from the output (`rules.missingValues`).
24
+ *
25
+ * None of them can say a translation is right. Each says one way it is wrong.
26
+ */
27
+ export type TranslationLossKind = 'truncation' | 'core-only' | 'read-back' | 'invariant';
28
+ /** One way a translation loses part of its input. */
29
+ export interface TranslationLoss {
30
+ kind: TranslationLossKind;
31
+ /**
32
+ * What is lost: the input left unread (`truncation`); the forms nothing
33
+ * writes (`core-only`, as `swap <strategy>`); the output left unread or what
34
+ * it reads back without or with in excess (`read-back`, as `-cmd` / `+cmd`);
35
+ * or the verbatim values missing from the output (`invariant`).
36
+ */
37
+ lost: string[];
38
+ }
39
+ export declare class LossyTranslationError extends Error {
40
+ /** The output `translate()` would have returned: NOT the whole script. */
41
+ readonly partial: string;
42
+ readonly loss: TranslationLoss;
43
+ readonly from: string;
44
+ readonly to: string;
45
+ readonly name = "LossyTranslationError";
46
+ constructor(
47
+ /** The output `translate()` would have returned: NOT the whole script. */
48
+ partial: string, loss: TranslationLoss, from: string, to: string);
49
+ }
50
+ /** What the checks read of a parse: its diagnostics. */
51
+ export interface LossCheckedNode {
52
+ readonly diagnostics?: ReadonlyArray<{
53
+ readonly code?: string;
54
+ readonly message: string;
55
+ }>;
56
+ }
57
+ /** The spans a parse left bound to no role (its top node carries them all). */
58
+ export declare function unconsumedSpans(node: LossCheckedNode): string[];
59
+ /** A grammar's rules for `findTranslationLoss`, for its node type `N`. */
60
+ export interface TranslationLossRules<N extends LossCheckedNode> {
61
+ /** The forms in `node` the grammar's writer has no spelling for (`core-only`). */
62
+ unwritable?(node: N): string[];
63
+ /**
64
+ * `node` as it was written into the target language, to compare its
65
+ * read-back with (hyperscript: in upstream's spelling for English). Default:
66
+ * `node` itself.
67
+ */
68
+ written?(node: N): N;
69
+ /**
70
+ * How the read-back differs from what was written, checked in order: the
71
+ * first that finds a difference is the loss (hyperscript: commands, then
72
+ * roles, then clauses kept as written).
73
+ */
74
+ readonly differences: ReadonlyArray<(written: N, back: N) => string[]>;
75
+ /** The values `input` holds that `output` must write verbatim and does not (`invariant`). */
76
+ missingValues?(input: string, output: string): string[];
77
+ }
78
+ /**
79
+ * How a translation of `input` (parsed as `node`) into `output` loses part of
80
+ * it, or undefined. `readBack` parses the output in the target language; it
81
+ * throws when the output does not read.
82
+ */
83
+ export declare function findTranslationLoss<N extends LossCheckedNode>(input: string, node: N, output: string, readBack: (output: string) => N, rules: TranslationLossRules<N>): TranslationLoss | undefined;
84
+ //# sourceMappingURL=translation-loss.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translation-loss.d.ts","sourceRoot":"","sources":["../../src/api/translation-loss.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAEzF,qDAAqD;AACrD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B;;;;;OAKG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAI5C,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAA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E,oBAAoB,CAAC,CAAC,CAAC,GAC7B,eAAe,GAAG,SAAS,CAuB7B"}
@@ -4,4 +4,5 @@
4
4
  export * from './types';
5
5
  export * from './tokenization';
6
6
  export * from './pattern-matching';
7
+ export * from './matching';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}