@lokascript/framework 4.6.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 (115) hide show
  1. package/CHANGELOG.md +87 -1
  2. package/dist/api/create-dsl.d.ts +13 -0
  3. package/dist/api/create-dsl.d.ts.map +1 -1
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api/index.js +1756 -710
  7. package/dist/api/index.js.map +1 -1
  8. package/dist/api/translation-loss.d.ts +84 -0
  9. package/dist/api/translation-loss.d.ts.map +1 -0
  10. package/dist/core/index.d.ts +1 -0
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js +1047 -684
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/matching/confidence-model.d.ts +54 -0
  15. package/dist/core/matching/confidence-model.d.ts.map +1 -0
  16. package/dist/core/matching/index.d.ts +12 -0
  17. package/dist/core/matching/index.d.ts.map +1 -0
  18. package/dist/core/matching/match-skeleton.d.ts +114 -0
  19. package/dist/core/matching/match-skeleton.d.ts.map +1 -0
  20. package/dist/core/matching/stock-confidence.d.ts +15 -0
  21. package/dist/core/matching/stock-confidence.d.ts.map +1 -0
  22. package/dist/core/matching/stock-reader.d.ts +56 -0
  23. package/dist/core/matching/stock-reader.d.ts.map +1 -0
  24. package/dist/core/matching/stock-reading.d.ts +44 -0
  25. package/dist/core/matching/stock-reading.d.ts.map +1 -0
  26. package/dist/core/matching/value-reader.d.ts +62 -0
  27. package/dist/core/matching/value-reader.d.ts.map +1 -0
  28. package/dist/core/pattern-matching/index.js +561 -660
  29. package/dist/core/pattern-matching/index.js.map +1 -1
  30. package/dist/core/pattern-matching/pattern-matcher.d.ts +0 -117
  31. package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
  32. package/dist/core/types.d.ts +48 -0
  33. package/dist/core/types.d.ts.map +1 -1
  34. package/dist/core/types.js.map +1 -1
  35. package/dist/generation/index.d.ts +2 -0
  36. package/dist/generation/index.d.ts.map +1 -1
  37. package/dist/generation/index.js +583 -1
  38. package/dist/generation/index.js.map +1 -1
  39. package/dist/generation/pattern-render.d.ts +72 -0
  40. package/dist/generation/pattern-render.d.ts.map +1 -0
  41. package/dist/generation/schema-patterns.d.ts +152 -0
  42. package/dist/generation/schema-patterns.d.ts.map +1 -0
  43. package/dist/index.cjs +1979 -907
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.js +1961 -906
  46. package/dist/index.js.map +1 -1
  47. package/dist/ir/index.js.map +1 -1
  48. package/dist/parsing/index.js +561 -660
  49. package/dist/parsing/index.js.map +1 -1
  50. package/dist/testing/gate/index.d.ts +8 -0
  51. package/dist/testing/gate/index.d.ts.map +1 -0
  52. package/dist/testing/gate/index.js +632 -0
  53. package/dist/testing/gate/index.js.map +1 -0
  54. package/dist/testing/gate/lint/format.d.ts +7 -0
  55. package/dist/testing/gate/lint/format.d.ts.map +1 -0
  56. package/dist/testing/gate/lint/index.d.ts +30 -0
  57. package/dist/testing/gate/lint/index.d.ts.map +1 -0
  58. package/dist/testing/gate/lint/rules/extractor-coverage.d.ts +18 -0
  59. package/dist/testing/gate/lint/rules/extractor-coverage.d.ts.map +1 -0
  60. package/dist/testing/gate/lint/rules/index.d.ts +14 -0
  61. package/dist/testing/gate/lint/rules/index.d.ts.map +1 -0
  62. package/dist/testing/gate/lint/rules/keyword-classification.d.ts +19 -0
  63. package/dist/testing/gate/lint/rules/keyword-classification.d.ts.map +1 -0
  64. package/dist/testing/gate/lint/rules/keyword-coverage.d.ts +13 -0
  65. package/dist/testing/gate/lint/rules/keyword-coverage.d.ts.map +1 -0
  66. package/dist/testing/gate/lint/rules/marker-tokenization.d.ts +20 -0
  67. package/dist/testing/gate/lint/rules/marker-tokenization.d.ts.map +1 -0
  68. package/dist/testing/gate/lint/rules/position-ordering.d.ts +25 -0
  69. package/dist/testing/gate/lint/rules/position-ordering.d.ts.map +1 -0
  70. package/dist/testing/gate/lint/rules/renderer-coherence.d.ts +24 -0
  71. package/dist/testing/gate/lint/rules/renderer-coherence.d.ts.map +1 -0
  72. package/dist/testing/gate/lint/rules/schema-rules.d.ts +10 -0
  73. package/dist/testing/gate/lint/rules/schema-rules.d.ts.map +1 -0
  74. package/dist/testing/gate/lint/types.d.ts +74 -0
  75. package/dist/testing/gate/lint/types.d.ts.map +1 -0
  76. package/dist/testing/gate/round-trip.d.ts +163 -0
  77. package/dist/testing/gate/round-trip.d.ts.map +1 -0
  78. package/package.json +6 -2
  79. package/src/__test__/fixtures/sql-dsl.ts +8 -2
  80. package/src/api/create-dsl-engine.test.ts +86 -0
  81. package/src/api/create-dsl.ts +141 -18
  82. package/src/api/index.ts +1 -0
  83. package/src/api/translation-loss.test.ts +89 -0
  84. package/src/api/translation-loss.ts +128 -0
  85. package/src/core/index.ts +1 -0
  86. package/src/core/matching/confidence-model.ts +58 -0
  87. package/src/core/matching/index.ts +12 -0
  88. package/src/core/matching/match-skeleton.test.ts +179 -0
  89. package/src/core/matching/match-skeleton.ts +621 -0
  90. package/src/core/matching/stock-confidence.ts +238 -0
  91. package/src/core/matching/stock-reader.test.ts +181 -0
  92. package/src/core/matching/stock-reader.ts +186 -0
  93. package/src/core/matching/stock-reading.ts +681 -0
  94. package/src/core/matching/value-reader.ts +85 -0
  95. package/src/core/pattern-matching/pattern-matcher.ts +11 -876
  96. package/src/core/types.ts +48 -0
  97. package/src/generation/index.ts +2 -0
  98. package/src/generation/pattern-render.ts +378 -0
  99. package/src/generation/schema-patterns.test.ts +99 -0
  100. package/src/generation/schema-patterns.ts +962 -0
  101. package/src/testing/gate/index.ts +8 -0
  102. package/src/testing/gate/lint/format.ts +23 -0
  103. package/src/testing/gate/lint/index.ts +73 -0
  104. package/src/testing/gate/lint/lint.test.ts +131 -0
  105. package/src/testing/gate/lint/rules/extractor-coverage.ts +63 -0
  106. package/src/testing/gate/lint/rules/index.ts +37 -0
  107. package/src/testing/gate/lint/rules/keyword-classification.ts +52 -0
  108. package/src/testing/gate/lint/rules/keyword-coverage.ts +38 -0
  109. package/src/testing/gate/lint/rules/marker-tokenization.ts +129 -0
  110. package/src/testing/gate/lint/rules/position-ordering.ts +87 -0
  111. package/src/testing/gate/lint/rules/renderer-coherence.ts +100 -0
  112. package/src/testing/gate/lint/rules/schema-rules.ts +35 -0
  113. package/src/testing/gate/lint/types.ts +83 -0
  114. package/src/testing/gate/round-trip.test.ts +118 -0
  115. package/src/testing/gate/round-trip.ts +438 -0
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The seam between the pattern matcher's skeleton and a grammar's value
3
+ * reading (domains rethink Phase 4.2-4.3, `docs-internal/DOMAINS_RETHINK.md`).
4
+ *
5
+ * The skeleton (`match-skeleton.ts`) walks a pattern: its literals, groups and
6
+ * role slots, with rollback, ranking, spans, memoization and the confidence
7
+ * model. It knows nothing of what a VALUE is in the grammar, nor of the
8
+ * grammar's language profiles: each role slot is read through `readRole`, and
9
+ * the few places the walk needs a grammar fact go through the hooks below.
10
+ * Hyperscript's reader is `@lokascript/semantic`'s `HyperscriptValueReader`.
11
+ */
12
+
13
+ import type {
14
+ LanguagePattern,
15
+ LanguageToken,
16
+ PatternMatchResult,
17
+ PatternToken,
18
+ SemanticRole,
19
+ SemanticValue,
20
+ TokenStream,
21
+ } from '../types';
22
+
23
+ /** A role slot of a pattern. */
24
+ export type RoleSlot = PatternToken & { type: 'role' };
25
+
26
+ /** What the skeleton tells its reader about the match in progress. */
27
+ export interface MatchView {
28
+ /**
29
+ * The pattern tokens still to match after the slot being read, through every
30
+ * enclosing group: a value stops at any marker the pattern still owes.
31
+ */
32
+ patternRest(): readonly PatternToken[];
33
+ /**
34
+ * Whether the slot being read directly follows a literal the pattern
35
+ * matched: its marker (`[por {quantity}]`), or the command's verb.
36
+ */
37
+ slotAfterLiteral(): boolean;
38
+ /** Whether a pattern token (a literal, or a group starting with one) would match the token. */
39
+ wouldMatch(pt: PatternToken | undefined, token: LanguageToken): boolean;
40
+ }
41
+
42
+ /** A grammar's value reading, as the matcher's skeleton calls it. */
43
+ export interface ValueReader {
44
+ /** A pattern is about to be matched: reset what the reader keeps per pattern. */
45
+ beginPattern(pattern: LanguagePattern): void;
46
+ /**
47
+ * Read a value for `slot` at the stream's position into `captured`, and
48
+ * advance past it. False when the slot does not match; an optional slot that
49
+ * reads nothing returns true, captures nothing and consumes nothing.
50
+ *
51
+ * @param next - the pattern token after the slot (through an enclosing
52
+ * group's end), undefined where the pattern truly ends.
53
+ */
54
+ readRole(
55
+ tokens: TokenStream,
56
+ slot: RoleSlot,
57
+ captured: Map<SemanticRole, SemanticValue>,
58
+ next: PatternToken | undefined
59
+ ): boolean;
60
+ /**
61
+ * Slot discipline: may the skeleton try skipping this optional pattern token
62
+ * (a slot, or an optional group of slots) for the token at the stream's head?
63
+ * The skeleton then matches the rest of the pattern without it, and keeps the
64
+ * skip only when that reaches a clause end (`atClauseEnd`). For a marker-less
65
+ * optional slot facing a verb it must not eat.
66
+ */
67
+ maySkipSlot(
68
+ patternToken: PatternToken,
69
+ token: LanguageToken | null,
70
+ next: PatternToken | undefined
71
+ ): boolean;
72
+ /** Does a clause end at the stream's position (its end, or the next clause's first word)? */
73
+ atClauseEnd(tokens: TokenStream): boolean;
74
+ /** Skip what the grammar reads as nothing before a sequence (Arabic proclitics). */
75
+ skipLeading?(tokens: TokenStream, sequence: readonly PatternToken[]): void;
76
+ /** Before `sequence[index]` is matched (hyperscript: an event head's source clause). */
77
+ beforePatternToken?(
78
+ tokens: TokenStream,
79
+ sequence: readonly PatternToken[],
80
+ index: number,
81
+ captured: Map<SemanticRole, SemanticValue>
82
+ ): void;
83
+ /** Fields the reader adds to the pattern's match result (hyperscript: `eventSource`). */
84
+ resultFields?(): Partial<PatternMatchResult>;
85
+ }