@lokascript/framework 4.6.0 → 4.8.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.
- package/CHANGELOG.md +121 -1
- package/dist/api/create-dsl.d.ts +18 -2
- package/dist/api/create-dsl.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1799 -713
- package/dist/api/index.js.map +1 -1
- package/dist/api/translation-loss.d.ts +84 -0
- package/dist/api/translation-loss.d.ts.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1057 -684
- package/dist/core/index.js.map +1 -1
- package/dist/core/matching/confidence-model.d.ts +54 -0
- package/dist/core/matching/confidence-model.d.ts.map +1 -0
- package/dist/core/matching/index.d.ts +12 -0
- package/dist/core/matching/index.d.ts.map +1 -0
- package/dist/core/matching/match-skeleton.d.ts +114 -0
- package/dist/core/matching/match-skeleton.d.ts.map +1 -0
- package/dist/core/matching/stock-confidence.d.ts +15 -0
- package/dist/core/matching/stock-confidence.d.ts.map +1 -0
- package/dist/core/matching/stock-reader.d.ts +63 -0
- package/dist/core/matching/stock-reader.d.ts.map +1 -0
- package/dist/core/matching/stock-reading.d.ts +44 -0
- package/dist/core/matching/stock-reading.d.ts.map +1 -0
- package/dist/core/matching/value-reader.d.ts +62 -0
- package/dist/core/matching/value-reader.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.js +561 -660
- package/dist/core/pattern-matching/index.js.map +1 -1
- package/dist/core/pattern-matching/pattern-matcher.d.ts +0 -117
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
- package/dist/core/types.d.ts +53 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/generation/index.d.ts +2 -0
- package/dist/generation/index.d.ts.map +1 -1
- package/dist/generation/index.js +593 -1
- package/dist/generation/index.js.map +1 -1
- package/dist/generation/pattern-render.d.ts +72 -0
- package/dist/generation/pattern-render.d.ts.map +1 -0
- package/dist/generation/schema-patterns.d.ts +152 -0
- package/dist/generation/schema-patterns.d.ts.map +1 -0
- package/dist/index.cjs +2016 -904
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1998 -903
- package/dist/index.js.map +1 -1
- package/dist/ir/index.js.map +1 -1
- package/dist/parsing/index.js +561 -660
- package/dist/parsing/index.js.map +1 -1
- package/dist/testing/gate/index.d.ts +8 -0
- package/dist/testing/gate/index.d.ts.map +1 -0
- package/dist/testing/gate/index.js +664 -0
- package/dist/testing/gate/index.js.map +1 -0
- package/dist/testing/gate/lint/format.d.ts +7 -0
- package/dist/testing/gate/lint/format.d.ts.map +1 -0
- package/dist/testing/gate/lint/index.d.ts +30 -0
- package/dist/testing/gate/lint/index.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/extractor-coverage.d.ts +18 -0
- package/dist/testing/gate/lint/rules/extractor-coverage.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/index.d.ts +14 -0
- package/dist/testing/gate/lint/rules/index.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/keyword-classification.d.ts +19 -0
- package/dist/testing/gate/lint/rules/keyword-classification.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/keyword-coverage.d.ts +13 -0
- package/dist/testing/gate/lint/rules/keyword-coverage.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/marker-tokenization.d.ts +20 -0
- package/dist/testing/gate/lint/rules/marker-tokenization.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/position-ordering.d.ts +25 -0
- package/dist/testing/gate/lint/rules/position-ordering.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/renderer-coherence.d.ts +24 -0
- package/dist/testing/gate/lint/rules/renderer-coherence.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/schema-rules.d.ts +10 -0
- package/dist/testing/gate/lint/rules/schema-rules.d.ts.map +1 -0
- package/dist/testing/gate/lint/types.d.ts +74 -0
- package/dist/testing/gate/lint/types.d.ts.map +1 -0
- package/dist/testing/gate/round-trip.d.ts +184 -0
- package/dist/testing/gate/round-trip.d.ts.map +1 -0
- package/package.json +6 -2
- package/src/__test__/fixtures/sql-dsl.ts +8 -2
- package/src/api/create-dsl-engine.test.ts +150 -0
- package/src/api/create-dsl.test.ts +7 -0
- package/src/api/create-dsl.ts +173 -22
- package/src/api/index.ts +1 -0
- package/src/api/translation-loss.test.ts +89 -0
- package/src/api/translation-loss.ts +128 -0
- package/src/core/index.ts +1 -0
- package/src/core/matching/confidence-model.ts +58 -0
- package/src/core/matching/index.ts +12 -0
- package/src/core/matching/match-skeleton.test.ts +179 -0
- package/src/core/matching/match-skeleton.ts +621 -0
- package/src/core/matching/stock-confidence.ts +238 -0
- package/src/core/matching/stock-reader.test.ts +265 -0
- package/src/core/matching/stock-reader.ts +205 -0
- package/src/core/matching/stock-reading.ts +681 -0
- package/src/core/matching/value-reader.ts +85 -0
- package/src/core/pattern-matching/pattern-matcher.ts +11 -876
- package/src/core/types.ts +53 -0
- package/src/generation/index.ts +2 -0
- package/src/generation/pattern-render.ts +378 -0
- package/src/generation/schema-patterns.test.ts +139 -0
- package/src/generation/schema-patterns.ts +974 -0
- package/src/testing/gate/index.ts +8 -0
- package/src/testing/gate/lint/format.ts +23 -0
- package/src/testing/gate/lint/index.ts +73 -0
- package/src/testing/gate/lint/lint.test.ts +131 -0
- package/src/testing/gate/lint/rules/extractor-coverage.ts +63 -0
- package/src/testing/gate/lint/rules/index.ts +37 -0
- package/src/testing/gate/lint/rules/keyword-classification.ts +52 -0
- package/src/testing/gate/lint/rules/keyword-coverage.ts +38 -0
- package/src/testing/gate/lint/rules/marker-tokenization.ts +129 -0
- package/src/testing/gate/lint/rules/position-ordering.ts +87 -0
- package/src/testing/gate/lint/rules/renderer-coherence.ts +100 -0
- package/src/testing/gate/lint/rules/schema-rules.ts +35 -0
- package/src/testing/gate/lint/types.ts +83 -0
- package/src/testing/gate/round-trip.test.ts +208 -0
- package/src/testing/gate/round-trip.ts +503 -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
|
+
}
|