@lokascript/framework 2.0.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/LICENSE +20 -0
- package/README.md +142 -0
- package/dist/aot/aot-orchestrator.d.ts +75 -0
- package/dist/aot/aot-orchestrator.d.ts.map +1 -0
- package/dist/aot/domain-scanner.d.ts +27 -0
- package/dist/aot/domain-scanner.d.ts.map +1 -0
- package/dist/aot/index.d.ts +8 -0
- package/dist/aot/index.d.ts.map +1 -0
- package/dist/aot/types.d.ts +103 -0
- package/dist/aot/types.d.ts.map +1 -0
- package/dist/api/create-dsl.d.ts +91 -0
- package/dist/api/create-dsl.d.ts.map +1 -0
- package/dist/api/dispatcher.d.ts +108 -0
- package/dist/api/dispatcher.d.ts.map +1 -0
- package/dist/api/domain-registry.d.ts +152 -0
- package/dist/api/domain-registry.d.ts.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2082 -0
- package/dist/api/index.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2674 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +32 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.d.ts +6 -0
- package/dist/core/pattern-matching/index.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.js +1239 -0
- package/dist/core/pattern-matching/index.js.map +1 -0
- package/dist/core/pattern-matching/pattern-matcher.d.ts +239 -0
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/index.d.ts +6 -0
- package/dist/core/pattern-matching/utils/index.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/possessive-keywords.d.ts +38 -0
- package/dist/core/pattern-matching/utils/possessive-keywords.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/type-validation.d.ts +63 -0
- package/dist/core/pattern-matching/utils/type-validation.d.ts.map +1 -0
- package/dist/core/tokenization/base-tokenizer.d.ts +344 -0
- package/dist/core/tokenization/base-tokenizer.d.ts.map +1 -0
- package/dist/core/tokenization/char-classifiers.d.ts +56 -0
- package/dist/core/tokenization/char-classifiers.d.ts.map +1 -0
- package/dist/core/tokenization/default-extractors.d.ts +48 -0
- package/dist/core/tokenization/default-extractors.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/index.d.ts +9 -0
- package/dist/core/tokenization/extractors/index.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/operator.d.ts +23 -0
- package/dist/core/tokenization/extractors/operator.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/punctuation.d.ts +22 -0
- package/dist/core/tokenization/extractors/punctuation.d.ts.map +1 -0
- package/dist/core/tokenization/extractors.d.ts +61 -0
- package/dist/core/tokenization/extractors.d.ts.map +1 -0
- package/dist/core/tokenization/index.d.ts +11 -0
- package/dist/core/tokenization/index.d.ts.map +1 -0
- package/dist/core/tokenization/index.js +1345 -0
- package/dist/core/tokenization/index.js.map +1 -0
- package/dist/core/tokenization/morphology/index.d.ts +5 -0
- package/dist/core/tokenization/morphology/index.d.ts.map +1 -0
- package/dist/core/tokenization/morphology/types.d.ts +110 -0
- package/dist/core/tokenization/morphology/types.d.ts.map +1 -0
- package/dist/core/tokenization/token-utils.d.ts +111 -0
- package/dist/core/tokenization/token-utils.d.ts.map +1 -0
- package/dist/core/types.d.ts +382 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +108 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generation/diagnostics.d.ts +120 -0
- package/dist/generation/diagnostics.d.ts.map +1 -0
- package/dist/generation/index.d.ts +7 -0
- package/dist/generation/index.d.ts.map +1 -0
- package/dist/generation/index.js +339 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/generation/pattern-generator.d.ts +48 -0
- package/dist/generation/pattern-generator.d.ts.map +1 -0
- package/dist/generation/renderer.d.ts +115 -0
- package/dist/generation/renderer.d.ts.map +1 -0
- package/dist/grammar/index.d.ts +10 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +391 -0
- package/dist/grammar/index.js.map +1 -0
- package/dist/grammar/transformer.d.ts +56 -0
- package/dist/grammar/transformer.d.ts.map +1 -0
- package/dist/grammar/types.d.ts +236 -0
- package/dist/grammar/types.d.ts.map +1 -0
- package/dist/index.cjs +4454 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4336 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/dictionary.d.ts +82 -0
- package/dist/interfaces/dictionary.d.ts.map +1 -0
- package/dist/interfaces/index.d.ts +10 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/profile-provider.d.ts +67 -0
- package/dist/interfaces/profile-provider.d.ts.map +1 -0
- package/dist/interfaces/value-extractor.d.ts +168 -0
- package/dist/interfaces/value-extractor.d.ts.map +1 -0
- package/dist/multilingual/index.d.ts +8 -0
- package/dist/multilingual/index.d.ts.map +1 -0
- package/dist/multilingual/index.js +1 -0
- package/dist/multilingual/index.js.map +1 -0
- package/dist/parsing/index.d.ts +8 -0
- package/dist/parsing/index.d.ts.map +1 -0
- package/dist/parsing/index.js +1415 -0
- package/dist/parsing/index.js.map +1 -0
- package/dist/parsing/multi-statement.d.ts +265 -0
- package/dist/parsing/multi-statement.d.ts.map +1 -0
- package/dist/schema/command-schema.d.ts +78 -0
- package/dist/schema/command-schema.d.ts.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/test-setup.d.ts +9 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/testing/index.d.ts +50 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +16969 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +122 -0
- package/src/__test__/fixtures/sql-dsl.ts +232 -0
- package/src/__test__/sql-integration.test.ts +189 -0
- package/src/__test__/test-utils.ts +260 -0
- package/src/aot/aot-orchestrator.test.ts +413 -0
- package/src/aot/aot-orchestrator.ts +238 -0
- package/src/aot/domain-scanner.ts +178 -0
- package/src/aot/index.ts +8 -0
- package/src/aot/types.ts +124 -0
- package/src/api/create-dsl.ts +367 -0
- package/src/api/dispatcher.test.ts +336 -0
- package/src/api/dispatcher.ts +222 -0
- package/src/api/domain-registry.test.ts +336 -0
- package/src/api/domain-registry.ts +500 -0
- package/src/api/index.ts +7 -0
- package/src/core/index.ts +7 -0
- package/src/core/logger.ts +130 -0
- package/src/core/pattern-matching/index.ts +6 -0
- package/src/core/pattern-matching/pattern-matcher.test.ts +900 -0
- package/src/core/pattern-matching/pattern-matcher.ts +1548 -0
- package/src/core/pattern-matching/pattern-matcher.ts.backup +1267 -0
- package/src/core/pattern-matching/utils/index.ts +6 -0
- package/src/core/pattern-matching/utils/possessive-keywords.ts +55 -0
- package/src/core/pattern-matching/utils/type-validation.test.ts +316 -0
- package/src/core/pattern-matching/utils/type-validation.ts +134 -0
- package/src/core/tokenization/base-tokenizer.ts +916 -0
- package/src/core/tokenization/char-classifiers.ts +79 -0
- package/src/core/tokenization/create-simple-tokenizer.test.ts +260 -0
- package/src/core/tokenization/default-extractors.ts +69 -0
- package/src/core/tokenization/extractors/index.ts +9 -0
- package/src/core/tokenization/extractors/operator.ts +75 -0
- package/src/core/tokenization/extractors/punctuation.ts +39 -0
- package/src/core/tokenization/extractors.ts +452 -0
- package/src/core/tokenization/index.ts +11 -0
- package/src/core/tokenization/morphology/index.ts +5 -0
- package/src/core/tokenization/morphology/types.ts +211 -0
- package/src/core/tokenization/token-utils.ts +252 -0
- package/src/core/types.ts +589 -0
- package/src/generation/diagnostics.test.ts +171 -0
- package/src/generation/diagnostics.ts +239 -0
- package/src/generation/index.ts +7 -0
- package/src/generation/pattern-generator.test.ts +430 -0
- package/src/generation/pattern-generator.ts +315 -0
- package/src/generation/renderer.test.ts +266 -0
- package/src/generation/renderer.ts +244 -0
- package/src/grammar/index.ts +12 -0
- package/src/grammar/transformer.ts +159 -0
- package/src/grammar/types.ts +630 -0
- package/src/index.ts +157 -0
- package/src/interfaces/dictionary.ts +123 -0
- package/src/interfaces/index.ts +10 -0
- package/src/interfaces/profile-provider.ts +88 -0
- package/src/interfaces/value-extractor.ts +435 -0
- package/src/multilingual/index.ts +9 -0
- package/src/parsing/index.ts +27 -0
- package/src/parsing/multi-statement.test.ts +480 -0
- package/src/parsing/multi-statement.ts +648 -0
- package/src/schema/command-schema.ts +118 -0
- package/src/schema/index.ts +5 -0
- package/src/test-setup.ts +45 -0
- package/src/testing/index.ts +137 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Semantic Types for Multilingual DSLs
|
|
3
|
+
*
|
|
4
|
+
* This module defines the canonical semantic representation that all languages
|
|
5
|
+
* parse to and render from. The semantic layer is language-neutral - it captures
|
|
6
|
+
* the MEANING of DSL commands independent of surface syntax.
|
|
7
|
+
*
|
|
8
|
+
* These types are domain-agnostic - they work for any DSL (SQL, animations, etc.)
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Action type represents the command/operation in a DSL.
|
|
12
|
+
* This is generic - each DSL defines its own set of actions.
|
|
13
|
+
*
|
|
14
|
+
* Examples:
|
|
15
|
+
* - Hyperscript: 'toggle', 'add', 'remove', 'fetch'
|
|
16
|
+
* - SQL: 'select', 'insert', 'update', 'delete'
|
|
17
|
+
* - Animation: 'animate', 'fade', 'slide', 'rotate'
|
|
18
|
+
*/
|
|
19
|
+
export type ActionType = string;
|
|
20
|
+
/**
|
|
21
|
+
* Semantic role represents the grammatical function of a part of a command.
|
|
22
|
+
* This is generic - each DSL can define its own roles, though common ones include:
|
|
23
|
+
*
|
|
24
|
+
* Common roles across DSLs:
|
|
25
|
+
* - action: The verb/command
|
|
26
|
+
* - patient: What is being acted upon
|
|
27
|
+
* - destination: Where something goes
|
|
28
|
+
* - source: Where something comes from
|
|
29
|
+
* - condition: Boolean expressions
|
|
30
|
+
* - quantity: Numeric amounts
|
|
31
|
+
* - duration: Time spans
|
|
32
|
+
*
|
|
33
|
+
* Examples:
|
|
34
|
+
* - Hyperscript: 'patient', 'destination', 'source', 'event', 'style'
|
|
35
|
+
* - SQL: 'columns', 'table', 'condition', 'orderBy', 'limit'
|
|
36
|
+
* - Animation: 'target', 'duration', 'easing', 'delay'
|
|
37
|
+
*/
|
|
38
|
+
export type SemanticRole = string;
|
|
39
|
+
/**
|
|
40
|
+
* A semantic value represents a typed piece of data in a semantic node.
|
|
41
|
+
* Values are language-neutral - they capture what something IS, not how it's written.
|
|
42
|
+
*/
|
|
43
|
+
export type SemanticValue = LiteralValue | SelectorValue | ReferenceValue | PropertyPathValue | ExpressionValue;
|
|
44
|
+
/**
|
|
45
|
+
* Expected value types for role tokens.
|
|
46
|
+
* Shared between RoleSpec (command-schemas) and RolePatternToken.
|
|
47
|
+
*/
|
|
48
|
+
export type ExpectedType = SemanticValue['type'];
|
|
49
|
+
export interface LiteralValue {
|
|
50
|
+
readonly type: 'literal';
|
|
51
|
+
readonly value: string | number | boolean;
|
|
52
|
+
readonly dataType?: 'string' | 'number' | 'boolean' | 'duration';
|
|
53
|
+
}
|
|
54
|
+
export interface SelectorValue {
|
|
55
|
+
readonly type: 'selector';
|
|
56
|
+
readonly value: string;
|
|
57
|
+
readonly selectorKind?: 'id' | 'class' | 'attribute' | 'element' | 'complex' | 'identifier';
|
|
58
|
+
}
|
|
59
|
+
export interface ReferenceValue {
|
|
60
|
+
readonly type: 'reference';
|
|
61
|
+
readonly value: string;
|
|
62
|
+
}
|
|
63
|
+
export interface PropertyPathValue {
|
|
64
|
+
readonly type: 'property-path';
|
|
65
|
+
readonly object: SemanticValue;
|
|
66
|
+
readonly property: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ExpressionValue {
|
|
69
|
+
readonly type: 'expression';
|
|
70
|
+
/** Raw expression string for complex expressions that need further parsing */
|
|
71
|
+
readonly raw: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Base interface for all semantic nodes.
|
|
75
|
+
* Semantic nodes capture the MEANING of DSL constructs.
|
|
76
|
+
*/
|
|
77
|
+
export interface SemanticNode {
|
|
78
|
+
readonly kind: 'command' | 'event-handler' | 'conditional' | 'compound' | 'loop';
|
|
79
|
+
readonly action: ActionType;
|
|
80
|
+
readonly roles: ReadonlyMap<SemanticRole, SemanticValue>;
|
|
81
|
+
readonly metadata?: SemanticMetadata;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Metadata about the source of a semantic node.
|
|
85
|
+
* Useful for debugging, error messages, and round-trip conversion.
|
|
86
|
+
*/
|
|
87
|
+
export interface SemanticMetadata {
|
|
88
|
+
readonly sourceLanguage?: string;
|
|
89
|
+
readonly sourceText?: string;
|
|
90
|
+
readonly sourcePosition?: SourcePosition;
|
|
91
|
+
readonly patternId?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Confidence score for the parse (0-1).
|
|
94
|
+
* Higher values indicate more certain matches.
|
|
95
|
+
* - 1.0: Exact match with all roles captured
|
|
96
|
+
* - 0.8-0.99: High confidence with minor uncertainty
|
|
97
|
+
* - 0.6-0.8: Medium confidence (normalization, defaults applied)
|
|
98
|
+
* - <0.6: Low confidence (may need fallback)
|
|
99
|
+
*/
|
|
100
|
+
readonly confidence?: number;
|
|
101
|
+
}
|
|
102
|
+
export interface SourcePosition {
|
|
103
|
+
readonly start: number;
|
|
104
|
+
readonly end: number;
|
|
105
|
+
readonly line?: number;
|
|
106
|
+
readonly column?: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A command semantic node - represents a single DSL command.
|
|
110
|
+
*/
|
|
111
|
+
export interface CommandSemanticNode extends SemanticNode {
|
|
112
|
+
readonly kind: 'command';
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* An event handler semantic node - represents trigger-based commands.
|
|
116
|
+
* E.g., "on click [commands]" in hyperscript, or "when condition [commands]" in other DSLs.
|
|
117
|
+
*/
|
|
118
|
+
export interface EventHandlerSemanticNode extends SemanticNode {
|
|
119
|
+
readonly kind: 'event-handler';
|
|
120
|
+
readonly body: SemanticNode[];
|
|
121
|
+
readonly eventModifiers?: EventModifiers;
|
|
122
|
+
readonly additionalEvents?: readonly SemanticValue[];
|
|
123
|
+
readonly parameterNames?: readonly string[];
|
|
124
|
+
}
|
|
125
|
+
export interface EventModifiers {
|
|
126
|
+
readonly once?: boolean;
|
|
127
|
+
readonly debounce?: number;
|
|
128
|
+
readonly throttle?: number;
|
|
129
|
+
readonly queue?: 'first' | 'last' | 'all' | 'none';
|
|
130
|
+
readonly from?: SemanticValue;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A conditional semantic node - represents "if [condition] then [body] else [body]".
|
|
134
|
+
*/
|
|
135
|
+
export interface ConditionalSemanticNode extends SemanticNode {
|
|
136
|
+
readonly kind: 'conditional';
|
|
137
|
+
readonly thenBranch: SemanticNode[];
|
|
138
|
+
readonly elseBranch?: SemanticNode[];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A compound semantic node - represents multiple chained statements.
|
|
142
|
+
*/
|
|
143
|
+
export interface CompoundSemanticNode extends SemanticNode {
|
|
144
|
+
readonly kind: 'compound';
|
|
145
|
+
readonly statements: SemanticNode[];
|
|
146
|
+
readonly chainType: 'then' | 'and' | 'async' | 'sequential';
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Loop variant discriminant for different loop types.
|
|
150
|
+
*/
|
|
151
|
+
export type LoopVariant = 'forever' | 'times' | 'for' | 'while' | 'until';
|
|
152
|
+
/**
|
|
153
|
+
* A loop semantic node - represents repeat/for/while loops.
|
|
154
|
+
*/
|
|
155
|
+
export interface LoopSemanticNode extends SemanticNode {
|
|
156
|
+
readonly kind: 'loop';
|
|
157
|
+
readonly loopVariant: LoopVariant;
|
|
158
|
+
readonly body: SemanticNode[];
|
|
159
|
+
readonly loopVariable?: string;
|
|
160
|
+
readonly indexVariable?: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Token kind - categorizes what type of token this is.
|
|
164
|
+
*/
|
|
165
|
+
export type TokenKind = 'keyword' | 'selector' | 'literal' | 'particle' | 'conjunction' | 'event-modifier' | 'identifier' | 'operator' | 'punctuation' | 'url';
|
|
166
|
+
/**
|
|
167
|
+
* A language token - the result of tokenization.
|
|
168
|
+
*/
|
|
169
|
+
export interface LanguageToken {
|
|
170
|
+
readonly value: string;
|
|
171
|
+
readonly kind: TokenKind;
|
|
172
|
+
readonly position: SourcePosition;
|
|
173
|
+
/** Normalized form from explicit keyword map */
|
|
174
|
+
readonly normalized?: string;
|
|
175
|
+
/** Morphologically normalized stem */
|
|
176
|
+
readonly stem?: string;
|
|
177
|
+
/** Confidence in the morphological stem (0.0-1.0) */
|
|
178
|
+
readonly stemConfidence?: number;
|
|
179
|
+
/** Additional metadata for specific token types */
|
|
180
|
+
readonly metadata?: Record<string, unknown>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Token stream - provides sequential access to tokens with backtracking.
|
|
184
|
+
*/
|
|
185
|
+
export interface TokenStream {
|
|
186
|
+
readonly tokens: readonly LanguageToken[];
|
|
187
|
+
readonly language: string;
|
|
188
|
+
/** Look at token at current position + offset without consuming */
|
|
189
|
+
peek(offset?: number): LanguageToken | null;
|
|
190
|
+
/** Consume and return current token, advance position */
|
|
191
|
+
advance(): LanguageToken;
|
|
192
|
+
/** Check if we've consumed all tokens */
|
|
193
|
+
isAtEnd(): boolean;
|
|
194
|
+
/** Save current position for backtracking */
|
|
195
|
+
mark(): StreamMark;
|
|
196
|
+
/** Restore to a saved position */
|
|
197
|
+
reset(mark: StreamMark): void;
|
|
198
|
+
/** Get current position */
|
|
199
|
+
position(): number;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Stream mark for backtracking during parsing.
|
|
203
|
+
*/
|
|
204
|
+
export interface StreamMark {
|
|
205
|
+
readonly position: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Language tokenizer interface - converts text to tokens.
|
|
209
|
+
*/
|
|
210
|
+
export interface LanguageTokenizer {
|
|
211
|
+
readonly language: string;
|
|
212
|
+
readonly direction: 'ltr' | 'rtl';
|
|
213
|
+
/** Convert input string to token stream */
|
|
214
|
+
tokenize(input: string): TokenStream;
|
|
215
|
+
/** Classify a single token */
|
|
216
|
+
classifyToken(token: string): TokenKind;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A language pattern defines how a semantic structure appears in a specific language.
|
|
220
|
+
*/
|
|
221
|
+
export interface LanguagePattern {
|
|
222
|
+
/** Unique identifier for this pattern */
|
|
223
|
+
readonly id: string;
|
|
224
|
+
/** ISO 639-1 language code */
|
|
225
|
+
readonly language: string;
|
|
226
|
+
/** Which command this pattern matches */
|
|
227
|
+
readonly command: ActionType;
|
|
228
|
+
/** Priority for disambiguation (higher = checked first) */
|
|
229
|
+
readonly priority: number;
|
|
230
|
+
/** The pattern template with role placeholders */
|
|
231
|
+
readonly template: PatternTemplate;
|
|
232
|
+
/** Rules for extracting semantic roles from matched tokens */
|
|
233
|
+
readonly extraction: ExtractionRules;
|
|
234
|
+
/** Optional constraints on when this pattern applies */
|
|
235
|
+
readonly constraints?: PatternConstraints;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Pattern template - defines expected token sequence.
|
|
239
|
+
*/
|
|
240
|
+
export interface PatternTemplate {
|
|
241
|
+
/** Human-readable template string */
|
|
242
|
+
readonly format: string;
|
|
243
|
+
/** Parsed token sequence for matching */
|
|
244
|
+
readonly tokens: PatternToken[];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Pattern token - literal, role placeholder, or group.
|
|
248
|
+
*/
|
|
249
|
+
export type PatternToken = LiteralPatternToken | RolePatternToken | GroupPatternToken;
|
|
250
|
+
export interface LiteralPatternToken {
|
|
251
|
+
readonly type: 'literal';
|
|
252
|
+
readonly value: string;
|
|
253
|
+
/** Alternative spellings/forms that also match */
|
|
254
|
+
readonly alternatives?: string[];
|
|
255
|
+
}
|
|
256
|
+
export interface RolePatternToken {
|
|
257
|
+
readonly type: 'role';
|
|
258
|
+
readonly role: SemanticRole;
|
|
259
|
+
readonly optional?: boolean;
|
|
260
|
+
/** Expected value types (for validation) */
|
|
261
|
+
readonly expectedTypes?: Array<ExpectedType>;
|
|
262
|
+
/** When true, captures all remaining tokens until next marker or end */
|
|
263
|
+
readonly greedy?: boolean;
|
|
264
|
+
}
|
|
265
|
+
export interface GroupPatternToken {
|
|
266
|
+
readonly type: 'group';
|
|
267
|
+
readonly tokens: PatternToken[];
|
|
268
|
+
readonly optional?: boolean;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Rules for extracting semantic values from matched tokens.
|
|
272
|
+
*/
|
|
273
|
+
export interface ExtractionRules {
|
|
274
|
+
readonly [role: string]: ExtractionRule;
|
|
275
|
+
}
|
|
276
|
+
export interface ExtractionRule {
|
|
277
|
+
/** Position-based extraction (0-indexed from pattern start) */
|
|
278
|
+
readonly position?: number;
|
|
279
|
+
/** Marker-based extraction (find value after this marker) */
|
|
280
|
+
readonly marker?: string;
|
|
281
|
+
/** Alternative markers that also work */
|
|
282
|
+
readonly markerAlternatives?: string[];
|
|
283
|
+
/** Transform the extracted value */
|
|
284
|
+
readonly transform?: (raw: string) => SemanticValue;
|
|
285
|
+
/** Default value if not found (for optional roles) */
|
|
286
|
+
readonly default?: SemanticValue;
|
|
287
|
+
/** Static value extraction */
|
|
288
|
+
readonly value?: string;
|
|
289
|
+
/** Extract value from a pattern role by name */
|
|
290
|
+
readonly fromRole?: string;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Additional constraints on pattern applicability.
|
|
294
|
+
*/
|
|
295
|
+
export interface PatternConstraints {
|
|
296
|
+
/** Required roles that must be present */
|
|
297
|
+
readonly requiredRoles?: SemanticRole[];
|
|
298
|
+
/** Roles that must NOT be present */
|
|
299
|
+
readonly forbiddenRoles?: SemanticRole[];
|
|
300
|
+
/** Valid selector types for the patient role */
|
|
301
|
+
readonly validPatientTypes?: Array<SelectorValue['selectorKind']>;
|
|
302
|
+
/** Pattern IDs this conflicts with */
|
|
303
|
+
readonly conflictsWith?: string[];
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Result of matching a pattern against tokens.
|
|
307
|
+
*/
|
|
308
|
+
export interface PatternMatchResult {
|
|
309
|
+
readonly pattern: LanguagePattern;
|
|
310
|
+
readonly captured: ReadonlyMap<SemanticRole, SemanticValue>;
|
|
311
|
+
readonly consumedTokens: number;
|
|
312
|
+
readonly confidence: number;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Error when pattern matching fails.
|
|
316
|
+
*/
|
|
317
|
+
export interface PatternMatchError {
|
|
318
|
+
readonly message: string;
|
|
319
|
+
readonly position: SourcePosition;
|
|
320
|
+
readonly expectedPatterns?: string[];
|
|
321
|
+
readonly partialMatch?: Partial<PatternMatchResult>;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Create a literal value
|
|
325
|
+
*/
|
|
326
|
+
export declare function createLiteral(value: string | number | boolean, dataType?: 'string' | 'number' | 'boolean' | 'duration'): LiteralValue;
|
|
327
|
+
/**
|
|
328
|
+
* Create a selector value
|
|
329
|
+
*/
|
|
330
|
+
export declare function createSelector(value: string, selectorKind?: SelectorValue['selectorKind']): SelectorValue;
|
|
331
|
+
/**
|
|
332
|
+
* Create a reference value
|
|
333
|
+
*/
|
|
334
|
+
export declare function createReference(value: string): ReferenceValue;
|
|
335
|
+
/**
|
|
336
|
+
* Create a property path value
|
|
337
|
+
*/
|
|
338
|
+
export declare function createPropertyPath(object: SemanticValue, property: string): PropertyPathValue;
|
|
339
|
+
/**
|
|
340
|
+
* Create an expression value
|
|
341
|
+
*/
|
|
342
|
+
export declare function createExpression(raw: string): ExpressionValue;
|
|
343
|
+
/**
|
|
344
|
+
* Create a command semantic node
|
|
345
|
+
*/
|
|
346
|
+
export declare function createCommandNode(action: ActionType, roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>, metadata?: SemanticMetadata): CommandSemanticNode;
|
|
347
|
+
/**
|
|
348
|
+
* Create an event handler semantic node
|
|
349
|
+
*/
|
|
350
|
+
export declare function createEventHandlerNode(action: ActionType, roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>, body: SemanticNode[], metadata?: SemanticMetadata, eventModifiers?: EventModifiers): EventHandlerSemanticNode;
|
|
351
|
+
/**
|
|
352
|
+
* Create a conditional semantic node
|
|
353
|
+
*/
|
|
354
|
+
export declare function createConditionalNode(action: ActionType, roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>, thenBranch: SemanticNode[], elseBranch?: SemanticNode[], metadata?: SemanticMetadata): ConditionalSemanticNode;
|
|
355
|
+
/**
|
|
356
|
+
* Create a compound semantic node
|
|
357
|
+
*/
|
|
358
|
+
export declare function createCompoundNode(statements: SemanticNode[], chainType?: CompoundSemanticNode['chainType'], metadata?: SemanticMetadata): CompoundSemanticNode;
|
|
359
|
+
/**
|
|
360
|
+
* Extract a string value from a SemanticValue.
|
|
361
|
+
*
|
|
362
|
+
* Handles all value types in the SemanticValue union:
|
|
363
|
+
* - ExpressionValue: returns `raw`
|
|
364
|
+
* - LiteralValue/SelectorValue/ReferenceValue: returns `value` as string
|
|
365
|
+
* - PropertyPathValue: returns `object.property` path
|
|
366
|
+
*
|
|
367
|
+
* This is the standard way to get a display string from any semantic value,
|
|
368
|
+
* eliminating the need for `as any` casts in domain code generators.
|
|
369
|
+
*/
|
|
370
|
+
export declare function extractValue(value: SemanticValue): string;
|
|
371
|
+
/**
|
|
372
|
+
* Extract a string value from a named role on a SemanticNode.
|
|
373
|
+
*
|
|
374
|
+
* Convenience wrapper: looks up the role, returns empty string if missing.
|
|
375
|
+
* Eliminates the common `const x = node.roles.get('role'); const val = x ? extractValue(x as any) : '';` pattern.
|
|
376
|
+
*/
|
|
377
|
+
export declare function extractRoleValue(node: SemanticNode, role: string): string;
|
|
378
|
+
/**
|
|
379
|
+
* Create a loop semantic node
|
|
380
|
+
*/
|
|
381
|
+
export declare function createLoopNode(action: ActionType, roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>, loopVariant: LoopVariant, body: SemanticNode[], loopVariable?: string, indexVariable?: string, metadata?: SemanticMetadata): LoopSemanticNode;
|
|
382
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAMlC;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,aAAa,GACb,cAAc,GACd,iBAAiB,GACjB,eAAe,CAAC;AAEpB;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC1C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;CAClE;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,G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1B,SAAS,GAAE,oBAAoB,CAAC,WAAW,CAAgB,EAC3D,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,oBAAoB,CAStB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAKzD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIzE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,EAC7E,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,YAAY,EAAE,EACpB,YAAY,CAAC,EAAE,MAAM,EACrB,aAAa,CAAC,EAAE,MAAM,EACtB,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,gBAAgB,CAelB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/core/types.ts
|
|
2
|
+
function createLiteral(value, dataType) {
|
|
3
|
+
return dataType ? { type: "literal", value, dataType } : { type: "literal", value };
|
|
4
|
+
}
|
|
5
|
+
function createSelector(value, selectorKind) {
|
|
6
|
+
return selectorKind ? { type: "selector", value, selectorKind } : { type: "selector", value };
|
|
7
|
+
}
|
|
8
|
+
function createReference(value) {
|
|
9
|
+
return { type: "reference", value };
|
|
10
|
+
}
|
|
11
|
+
function createPropertyPath(object, property) {
|
|
12
|
+
return { type: "property-path", object, property };
|
|
13
|
+
}
|
|
14
|
+
function createExpression(raw) {
|
|
15
|
+
return { type: "expression", raw };
|
|
16
|
+
}
|
|
17
|
+
function createCommandNode(action, roles, metadata) {
|
|
18
|
+
const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));
|
|
19
|
+
const node = {
|
|
20
|
+
kind: "command",
|
|
21
|
+
action,
|
|
22
|
+
roles: rolesMap
|
|
23
|
+
};
|
|
24
|
+
if (metadata) {
|
|
25
|
+
return { ...node, metadata };
|
|
26
|
+
}
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
function createEventHandlerNode(action, roles, body, metadata, eventModifiers) {
|
|
30
|
+
const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));
|
|
31
|
+
const base = {
|
|
32
|
+
kind: "event-handler",
|
|
33
|
+
action,
|
|
34
|
+
roles: rolesMap,
|
|
35
|
+
body
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
...base,
|
|
39
|
+
...eventModifiers && { eventModifiers },
|
|
40
|
+
...metadata && { metadata }
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function createConditionalNode(action, roles, thenBranch, elseBranch, metadata) {
|
|
44
|
+
const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));
|
|
45
|
+
const base = {
|
|
46
|
+
kind: "conditional",
|
|
47
|
+
action,
|
|
48
|
+
roles: rolesMap,
|
|
49
|
+
thenBranch
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...base,
|
|
53
|
+
...elseBranch && { elseBranch },
|
|
54
|
+
...metadata && { metadata }
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function createCompoundNode(statements, chainType = "sequential", metadata) {
|
|
58
|
+
const base = {
|
|
59
|
+
kind: "compound",
|
|
60
|
+
action: "compound",
|
|
61
|
+
roles: /* @__PURE__ */ new Map(),
|
|
62
|
+
statements,
|
|
63
|
+
chainType
|
|
64
|
+
};
|
|
65
|
+
return metadata ? { ...base, metadata } : base;
|
|
66
|
+
}
|
|
67
|
+
function extractValue(value) {
|
|
68
|
+
if ("raw" in value && value.raw !== void 0) return String(value.raw);
|
|
69
|
+
if ("value" in value && value.value !== void 0) return String(value.value);
|
|
70
|
+
if (value.type === "property-path") return `${extractValue(value.object)}.${value.property}`;
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
function extractRoleValue(node, role) {
|
|
74
|
+
const value = node.roles.get(role);
|
|
75
|
+
if (!value) return "";
|
|
76
|
+
return extractValue(value);
|
|
77
|
+
}
|
|
78
|
+
function createLoopNode(action, roles, loopVariant, body, loopVariable, indexVariable, metadata) {
|
|
79
|
+
const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));
|
|
80
|
+
const base = {
|
|
81
|
+
kind: "loop",
|
|
82
|
+
action,
|
|
83
|
+
roles: rolesMap,
|
|
84
|
+
loopVariant,
|
|
85
|
+
body
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
...base,
|
|
89
|
+
...loopVariable && { loopVariable },
|
|
90
|
+
...indexVariable && { indexVariable },
|
|
91
|
+
...metadata && { metadata }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
createCommandNode,
|
|
96
|
+
createCompoundNode,
|
|
97
|
+
createConditionalNode,
|
|
98
|
+
createEventHandlerNode,
|
|
99
|
+
createExpression,
|
|
100
|
+
createLiteral,
|
|
101
|
+
createLoopNode,
|
|
102
|
+
createPropertyPath,
|
|
103
|
+
createReference,
|
|
104
|
+
createSelector,
|
|
105
|
+
extractRoleValue,
|
|
106
|
+
extractValue
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/types.ts"],"sourcesContent":["/**\n * Generic Semantic Types for Multilingual DSLs\n *\n * This module defines the canonical semantic representation that all languages\n * parse to and render from. The semantic layer is language-neutral - it captures\n * the MEANING of DSL commands independent of surface syntax.\n *\n * These types are domain-agnostic - they work for any DSL (SQL, animations, etc.)\n */\n\n// =============================================================================\n// Action Types (Generic)\n// =============================================================================\n\n/**\n * Action type represents the command/operation in a DSL.\n * This is generic - each DSL defines its own set of actions.\n *\n * Examples:\n * - Hyperscript: 'toggle', 'add', 'remove', 'fetch'\n * - SQL: 'select', 'insert', 'update', 'delete'\n * - Animation: 'animate', 'fade', 'slide', 'rotate'\n */\nexport type ActionType = string;\n\n/**\n * Semantic role represents the grammatical function of a part of a command.\n * This is generic - each DSL can define its own roles, though common ones include:\n *\n * Common roles across DSLs:\n * - action: The verb/command\n * - patient: What is being acted upon\n * - destination: Where something goes\n * - source: Where something comes from\n * - condition: Boolean expressions\n * - quantity: Numeric amounts\n * - duration: Time spans\n *\n * Examples:\n * - Hyperscript: 'patient', 'destination', 'source', 'event', 'style'\n * - SQL: 'columns', 'table', 'condition', 'orderBy', 'limit'\n * - Animation: 'target', 'duration', 'easing', 'delay'\n */\nexport type SemanticRole = string;\n\n// =============================================================================\n// Semantic Values\n// =============================================================================\n\n/**\n * A semantic value represents a typed piece of data in a semantic node.\n * Values are language-neutral - they capture what something IS, not how it's written.\n */\nexport type SemanticValue =\n | LiteralValue\n | SelectorValue\n | ReferenceValue\n | PropertyPathValue\n | ExpressionValue;\n\n/**\n * Expected value types for role tokens.\n * Shared between RoleSpec (command-schemas) and RolePatternToken.\n */\nexport type ExpectedType = SemanticValue['type'];\n\nexport interface LiteralValue {\n readonly type: 'literal';\n readonly value: string | number | boolean;\n readonly dataType?: 'string' | 'number' | 'boolean' | 'duration';\n}\n\nexport interface SelectorValue {\n readonly type: 'selector';\n readonly value: string; // The selector: #id, .class, [attr], table-name, etc.\n readonly selectorKind?: 'id' | 'class' | 'attribute' | 'element' | 'complex' | 'identifier';\n}\n\nexport interface ReferenceValue {\n readonly type: 'reference';\n readonly value: string; // Generic reference name (DSL-specific)\n}\n\nexport interface PropertyPathValue {\n readonly type: 'property-path';\n readonly object: SemanticValue;\n readonly property: string;\n}\n\nexport interface ExpressionValue {\n readonly type: 'expression';\n /** Raw expression string for complex expressions that need further parsing */\n readonly raw: string;\n}\n\n// =============================================================================\n// Semantic Nodes\n// =============================================================================\n\n/**\n * Base interface for all semantic nodes.\n * Semantic nodes capture the MEANING of DSL constructs.\n */\nexport interface SemanticNode {\n readonly kind: 'command' | 'event-handler' | 'conditional' | 'compound' | 'loop';\n readonly action: ActionType;\n readonly roles: ReadonlyMap<SemanticRole, SemanticValue>;\n readonly metadata?: SemanticMetadata;\n}\n\n/**\n * Metadata about the source of a semantic node.\n * Useful for debugging, error messages, and round-trip conversion.\n */\nexport interface SemanticMetadata {\n readonly sourceLanguage?: string;\n readonly sourceText?: string;\n readonly sourcePosition?: SourcePosition;\n readonly patternId?: string;\n /**\n * Confidence score for the parse (0-1).\n * Higher values indicate more certain matches.\n * - 1.0: Exact match with all roles captured\n * - 0.8-0.99: High confidence with minor uncertainty\n * - 0.6-0.8: Medium confidence (normalization, defaults applied)\n * - <0.6: Low confidence (may need fallback)\n */\n readonly confidence?: number;\n}\n\nexport interface SourcePosition {\n readonly start: number;\n readonly end: number;\n readonly line?: number;\n readonly column?: number;\n}\n\n/**\n * A command semantic node - represents a single DSL command.\n */\nexport interface CommandSemanticNode extends SemanticNode {\n readonly kind: 'command';\n}\n\n/**\n * An event handler semantic node - represents trigger-based commands.\n * E.g., \"on click [commands]\" in hyperscript, or \"when condition [commands]\" in other DSLs.\n */\nexport interface EventHandlerSemanticNode extends SemanticNode {\n readonly kind: 'event-handler';\n readonly body: SemanticNode[];\n readonly eventModifiers?: EventModifiers;\n readonly additionalEvents?: readonly SemanticValue[];\n readonly parameterNames?: readonly string[];\n}\n\nexport interface EventModifiers {\n readonly once?: boolean;\n readonly debounce?: number;\n readonly throttle?: number;\n readonly queue?: 'first' | 'last' | 'all' | 'none';\n readonly from?: SemanticValue;\n}\n\n/**\n * A conditional semantic node - represents \"if [condition] then [body] else [body]\".\n */\nexport interface ConditionalSemanticNode extends SemanticNode {\n readonly kind: 'conditional';\n readonly thenBranch: SemanticNode[];\n readonly elseBranch?: SemanticNode[];\n}\n\n/**\n * A compound semantic node - represents multiple chained statements.\n */\nexport interface CompoundSemanticNode extends SemanticNode {\n readonly kind: 'compound';\n readonly statements: SemanticNode[];\n readonly chainType: 'then' | 'and' | 'async' | 'sequential';\n}\n\n/**\n * Loop variant discriminant for different loop types.\n */\nexport type LoopVariant = 'forever' | 'times' | 'for' | 'while' | 'until';\n\n/**\n * A loop semantic node - represents repeat/for/while loops.\n */\nexport interface LoopSemanticNode extends SemanticNode {\n readonly kind: 'loop';\n readonly loopVariant: LoopVariant;\n readonly body: SemanticNode[];\n readonly loopVariable?: string;\n readonly indexVariable?: string;\n}\n\n// =============================================================================\n// Tokenization Types\n// =============================================================================\n\n/**\n * Token kind - categorizes what type of token this is.\n */\nexport type TokenKind =\n | 'keyword' // Command or modifier keyword\n | 'selector' // CSS selector or identifier (#id, .class, table-name)\n | 'literal' // String or number literal\n | 'particle' // Grammatical particle (を, に, من)\n | 'conjunction' // Grammatical conjunction\n | 'event-modifier' // Event modifier (.once, .debounce(300))\n | 'identifier' // Generic identifier\n | 'operator' // Operators (., +, -, etc.)\n | 'punctuation' // Punctuation (parentheses, etc.)\n | 'url'; // URL or path\n\n/**\n * A language token - the result of tokenization.\n */\nexport interface LanguageToken {\n readonly value: string;\n readonly kind: TokenKind;\n readonly position: SourcePosition;\n /** Normalized form from explicit keyword map */\n readonly normalized?: string;\n /** Morphologically normalized stem */\n readonly stem?: string;\n /** Confidence in the morphological stem (0.0-1.0) */\n readonly stemConfidence?: number;\n /** Additional metadata for specific token types */\n readonly metadata?: Record<string, unknown>;\n}\n\n/**\n * Token stream - provides sequential access to tokens with backtracking.\n */\nexport interface TokenStream {\n readonly tokens: readonly LanguageToken[];\n readonly language: string;\n\n /** Look at token at current position + offset without consuming */\n peek(offset?: number): LanguageToken | null;\n\n /** Consume and return current token, advance position */\n advance(): LanguageToken;\n\n /** Check if we've consumed all tokens */\n isAtEnd(): boolean;\n\n /** Save current position for backtracking */\n mark(): StreamMark;\n\n /** Restore to a saved position */\n reset(mark: StreamMark): void;\n\n /** Get current position */\n position(): number;\n}\n\n/**\n * Stream mark for backtracking during parsing.\n */\nexport interface StreamMark {\n readonly position: number;\n}\n\n/**\n * Language tokenizer interface - converts text to tokens.\n */\nexport interface LanguageTokenizer {\n readonly language: string;\n readonly direction: 'ltr' | 'rtl';\n\n /** Convert input string to token stream */\n tokenize(input: string): TokenStream;\n\n /** Classify a single token */\n classifyToken(token: string): TokenKind;\n}\n\n// =============================================================================\n// Pattern Matching Types\n// =============================================================================\n\n/**\n * A language pattern defines how a semantic structure appears in a specific language.\n */\nexport interface LanguagePattern {\n /** Unique identifier for this pattern */\n readonly id: string;\n /** ISO 639-1 language code */\n readonly language: string;\n /** Which command this pattern matches */\n readonly command: ActionType;\n /** Priority for disambiguation (higher = checked first) */\n readonly priority: number;\n /** The pattern template with role placeholders */\n readonly template: PatternTemplate;\n /** Rules for extracting semantic roles from matched tokens */\n readonly extraction: ExtractionRules;\n /** Optional constraints on when this pattern applies */\n readonly constraints?: PatternConstraints;\n}\n\n/**\n * Pattern template - defines expected token sequence.\n */\nexport interface PatternTemplate {\n /** Human-readable template string */\n readonly format: string;\n /** Parsed token sequence for matching */\n readonly tokens: PatternToken[];\n}\n\n/**\n * Pattern token - literal, role placeholder, or group.\n */\nexport type PatternToken = LiteralPatternToken | RolePatternToken | GroupPatternToken;\n\nexport interface LiteralPatternToken {\n readonly type: 'literal';\n readonly value: string;\n /** Alternative spellings/forms that also match */\n readonly alternatives?: string[];\n}\n\nexport interface RolePatternToken {\n readonly type: 'role';\n readonly role: SemanticRole;\n readonly optional?: boolean;\n /** Expected value types (for validation) */\n readonly expectedTypes?: Array<ExpectedType>;\n /** When true, captures all remaining tokens until next marker or end */\n readonly greedy?: boolean;\n}\n\nexport interface GroupPatternToken {\n readonly type: 'group';\n readonly tokens: PatternToken[];\n readonly optional?: boolean;\n}\n\n/**\n * Rules for extracting semantic values from matched tokens.\n */\nexport interface ExtractionRules {\n readonly [role: string]: ExtractionRule;\n}\n\nexport interface ExtractionRule {\n /** Position-based extraction (0-indexed from pattern start) */\n readonly position?: number;\n /** Marker-based extraction (find value after this marker) */\n readonly marker?: string;\n /** Alternative markers that also work */\n readonly markerAlternatives?: string[];\n /** Transform the extracted value */\n readonly transform?: (raw: string) => SemanticValue;\n /** Default value if not found (for optional roles) */\n readonly default?: SemanticValue;\n /** Static value extraction */\n readonly value?: string;\n /** Extract value from a pattern role by name */\n readonly fromRole?: string;\n}\n\n/**\n * Additional constraints on pattern applicability.\n */\nexport interface PatternConstraints {\n /** Required roles that must be present */\n readonly requiredRoles?: SemanticRole[];\n /** Roles that must NOT be present */\n readonly forbiddenRoles?: SemanticRole[];\n /** Valid selector types for the patient role */\n readonly validPatientTypes?: Array<SelectorValue['selectorKind']>;\n /** Pattern IDs this conflicts with */\n readonly conflictsWith?: string[];\n}\n\n/**\n * Result of matching a pattern against tokens.\n */\nexport interface PatternMatchResult {\n readonly pattern: LanguagePattern;\n readonly captured: ReadonlyMap<SemanticRole, SemanticValue>;\n readonly consumedTokens: number;\n readonly confidence: number; // 0-1, how well the pattern matched\n}\n\n/**\n * Error when pattern matching fails.\n */\nexport interface PatternMatchError {\n readonly message: string;\n readonly position: SourcePosition;\n readonly expectedPatterns?: string[];\n readonly partialMatch?: Partial<PatternMatchResult>;\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Create a literal value\n */\nexport function createLiteral(\n value: string | number | boolean,\n dataType?: 'string' | 'number' | 'boolean' | 'duration'\n): LiteralValue {\n return dataType ? { type: 'literal', value, dataType } : { type: 'literal', value };\n}\n\n/**\n * Create a selector value\n */\nexport function createSelector(\n value: string,\n selectorKind?: SelectorValue['selectorKind']\n): SelectorValue {\n return selectorKind ? { type: 'selector', value, selectorKind } : { type: 'selector', value };\n}\n\n/**\n * Create a reference value\n */\nexport function createReference(value: string): ReferenceValue {\n return { type: 'reference', value };\n}\n\n/**\n * Create a property path value\n */\nexport function createPropertyPath(object: SemanticValue, property: string): PropertyPathValue {\n return { type: 'property-path', object, property };\n}\n\n/**\n * Create an expression value\n */\nexport function createExpression(raw: string): ExpressionValue {\n return { type: 'expression', raw };\n}\n\n/**\n * Create a command semantic node\n */\nexport function createCommandNode(\n action: ActionType,\n roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>,\n metadata?: SemanticMetadata\n): CommandSemanticNode {\n const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));\n const node: CommandSemanticNode = {\n kind: 'command',\n action,\n roles: rolesMap,\n };\n if (metadata) {\n return { ...node, metadata };\n }\n return node;\n}\n\n/**\n * Create an event handler semantic node\n */\nexport function createEventHandlerNode(\n action: ActionType,\n roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>,\n body: SemanticNode[],\n metadata?: SemanticMetadata,\n eventModifiers?: EventModifiers\n): EventHandlerSemanticNode {\n const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));\n const base = {\n kind: 'event-handler' as const,\n action,\n roles: rolesMap,\n body,\n };\n return {\n ...base,\n ...(eventModifiers && { eventModifiers }),\n ...(metadata && { metadata }),\n };\n}\n\n/**\n * Create a conditional semantic node\n */\nexport function createConditionalNode(\n action: ActionType,\n roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>,\n thenBranch: SemanticNode[],\n elseBranch?: SemanticNode[],\n metadata?: SemanticMetadata\n): ConditionalSemanticNode {\n const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));\n const base = {\n kind: 'conditional' as const,\n action,\n roles: rolesMap,\n thenBranch,\n };\n return {\n ...base,\n ...(elseBranch && { elseBranch }),\n ...(metadata && { metadata }),\n };\n}\n\n/**\n * Create a compound semantic node\n */\nexport function createCompoundNode(\n statements: SemanticNode[],\n chainType: CompoundSemanticNode['chainType'] = 'sequential',\n metadata?: SemanticMetadata\n): CompoundSemanticNode {\n const base = {\n kind: 'compound' as const,\n action: 'compound' as const,\n roles: new Map(),\n statements,\n chainType,\n };\n return metadata ? { ...base, metadata } : base;\n}\n\n/**\n * Extract a string value from a SemanticValue.\n *\n * Handles all value types in the SemanticValue union:\n * - ExpressionValue: returns `raw`\n * - LiteralValue/SelectorValue/ReferenceValue: returns `value` as string\n * - PropertyPathValue: returns `object.property` path\n *\n * This is the standard way to get a display string from any semantic value,\n * eliminating the need for `as any` casts in domain code generators.\n */\nexport function extractValue(value: SemanticValue): string {\n if ('raw' in value && value.raw !== undefined) return String(value.raw);\n if ('value' in value && value.value !== undefined) return String(value.value);\n if (value.type === 'property-path') return `${extractValue(value.object)}.${value.property}`;\n return '';\n}\n\n/**\n * Extract a string value from a named role on a SemanticNode.\n *\n * Convenience wrapper: looks up the role, returns empty string if missing.\n * Eliminates the common `const x = node.roles.get('role'); const val = x ? extractValue(x as any) : '';` pattern.\n */\nexport function extractRoleValue(node: SemanticNode, role: string): string {\n const value = node.roles.get(role);\n if (!value) return '';\n return extractValue(value);\n}\n\n/**\n * Create a loop semantic node\n */\nexport function createLoopNode(\n action: ActionType,\n roles: Record<SemanticRole, SemanticValue> | Map<SemanticRole, SemanticValue>,\n loopVariant: LoopVariant,\n body: SemanticNode[],\n loopVariable?: string,\n indexVariable?: string,\n metadata?: SemanticMetadata\n): LoopSemanticNode {\n const rolesMap = roles instanceof Map ? roles : new Map(Object.entries(roles));\n const base = {\n kind: 'loop' as const,\n action,\n roles: rolesMap,\n loopVariant,\n body,\n };\n return {\n ...base,\n ...(loopVariable && { loopVariable }),\n ...(indexVariable && { indexVariable }),\n ...(metadata && { metadata }),\n };\n}\n"],"mappings":";AAwZO,SAAS,cACd,OACA,UACc;AACd,SAAO,WAAW,EAAE,MAAM,WAAW,OAAO,SAAS,IAAI,EAAE,MAAM,WAAW,MAAM;AACpF;AAKO,SAAS,eACd,OACA,cACe;AACf,SAAO,eAAe,EAAE,MAAM,YAAY,OAAO,aAAa,IAAI,EAAE,MAAM,YAAY,MAAM;AAC9F;AAKO,SAAS,gBAAgB,OAA+B;AAC7D,SAAO,EAAE,MAAM,aAAa,MAAM;AACpC;AAKO,SAAS,mBAAmB,QAAuB,UAAqC;AAC7F,SAAO,EAAE,MAAM,iBAAiB,QAAQ,SAAS;AACnD;AAKO,SAAS,iBAAiB,KAA8B;AAC7D,SAAO,EAAE,MAAM,cAAc,IAAI;AACn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tE,MAAI,WAAW,SAAS,MAAM,UAAU,OAAW,QAAO,OAAO,MAAM,KAAK;AAC5E,MAAI,MAAM,SAAS,gBAAiB,QAAO,GAAG,aAAa,MAAM,MAAM,CAAC,IAAI,MAAM,QAAQ;AAC1F,SAAO;AACT;AAQO,SAAS,iBAAiB,MAAoB,MAAsB;AACzE,QAAM,QAAQ,KAAK,MAAM,IAAI,IAAI;AACjC,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,aAAa,KAAK;AAC3B;AAKO,SAAS,eACd,QACA,OACA,aACA,MACA,cACA,eACA,UACkB;AAClB,QAAM,WAAW,iBAAiB,MAAM,QAAQ,IAAI,IAAI,OAAO,QAAQ,KAAK,CAAC;AAC7E,QAAM,OAAO;AAAA,IACX,MAAM;AAAA,IACN;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,EACF;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAI,gBAAgB,EAAE,aAAa;AAAA,IACnC,GAAI,iBAAiB,EAAE,cAAc;AAAA,IACrC,GAAI,YAAY,EAAE,SAAS;AAAA,EAC7B;AACF;","names":[]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured Error Diagnostics
|
|
3
|
+
*
|
|
4
|
+
* Framework-level diagnostic types for reporting errors, warnings, and hints
|
|
5
|
+
* during parsing, validation, and compilation. These provide richer feedback
|
|
6
|
+
* than simple error strings, enabling:
|
|
7
|
+
*
|
|
8
|
+
* - Severity levels (error, warning, info)
|
|
9
|
+
* - Machine-readable error codes
|
|
10
|
+
* - Source location tracking
|
|
11
|
+
* - Actionable suggestions
|
|
12
|
+
* - Programmatic fix lookup
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Severity level for a diagnostic.
|
|
16
|
+
*/
|
|
17
|
+
export type DiagnosticSeverity = 'error' | 'warning' | 'info';
|
|
18
|
+
/**
|
|
19
|
+
* A structured diagnostic message.
|
|
20
|
+
*
|
|
21
|
+
* Diagnostics provide rich error information beyond simple strings.
|
|
22
|
+
* They're used for parser errors, validation warnings, and hints.
|
|
23
|
+
*/
|
|
24
|
+
export interface Diagnostic {
|
|
25
|
+
/** Human-readable message */
|
|
26
|
+
readonly message: string;
|
|
27
|
+
/** Severity level */
|
|
28
|
+
readonly severity: DiagnosticSeverity;
|
|
29
|
+
/** Machine-readable code for programmatic handling (e.g., 'parse-error', 'missing-role') */
|
|
30
|
+
readonly code?: string;
|
|
31
|
+
/** 1-based line number in source */
|
|
32
|
+
readonly line?: number;
|
|
33
|
+
/** 0-based column offset in line */
|
|
34
|
+
readonly column?: number;
|
|
35
|
+
/** Original source text that triggered the diagnostic */
|
|
36
|
+
readonly source?: string;
|
|
37
|
+
/** Actionable suggestions for fixing the issue */
|
|
38
|
+
readonly suggestions?: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Result of a diagnostic-aware validation.
|
|
42
|
+
*/
|
|
43
|
+
export interface DiagnosticResult {
|
|
44
|
+
/** Whether validation passed (no errors, though warnings/info may exist) */
|
|
45
|
+
readonly ok: boolean;
|
|
46
|
+
/** All diagnostics, including errors, warnings, and info */
|
|
47
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
48
|
+
/** Convenience: count of each severity level */
|
|
49
|
+
readonly summary: DiagnosticSummary;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Summary counts by severity.
|
|
53
|
+
*/
|
|
54
|
+
export interface DiagnosticSummary {
|
|
55
|
+
readonly errors: number;
|
|
56
|
+
readonly warnings: number;
|
|
57
|
+
readonly infos: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Collects diagnostics during a parsing/validation/compilation pass.
|
|
61
|
+
*
|
|
62
|
+
* Use this in your domain's validate() or parse() to accumulate
|
|
63
|
+
* structured feedback instead of throwing on the first error.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const collector = createDiagnosticCollector();
|
|
68
|
+
*
|
|
69
|
+
* // During parsing:
|
|
70
|
+
* collector.error('Unknown command: foo', { code: 'unknown-command', line: 3 });
|
|
71
|
+
* collector.warning('Low confidence match', { code: 'low-confidence', line: 5 });
|
|
72
|
+
* collector.info('Consider using "select" instead of "get"', { line: 5 });
|
|
73
|
+
*
|
|
74
|
+
* // Get result:
|
|
75
|
+
* const result = collector.toResult();
|
|
76
|
+
* // { ok: false, diagnostics: [...], summary: { errors: 1, warnings: 1, infos: 1 } }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export interface DiagnosticCollector {
|
|
80
|
+
/** Add an error diagnostic */
|
|
81
|
+
error(message: string, options?: DiagnosticOptions): void;
|
|
82
|
+
/** Add a warning diagnostic */
|
|
83
|
+
warning(message: string, options?: DiagnosticOptions): void;
|
|
84
|
+
/** Add an info diagnostic */
|
|
85
|
+
info(message: string, options?: DiagnosticOptions): void;
|
|
86
|
+
/** Add a diagnostic with explicit severity */
|
|
87
|
+
add(diagnostic: Diagnostic): void;
|
|
88
|
+
/** Whether any errors have been collected */
|
|
89
|
+
hasErrors(): boolean;
|
|
90
|
+
/** Get all collected diagnostics */
|
|
91
|
+
getDiagnostics(): readonly Diagnostic[];
|
|
92
|
+
/** Build a DiagnosticResult from collected diagnostics */
|
|
93
|
+
toResult(): DiagnosticResult;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Options for adding a diagnostic via the collector's convenience methods.
|
|
97
|
+
*/
|
|
98
|
+
export interface DiagnosticOptions {
|
|
99
|
+
readonly code?: string;
|
|
100
|
+
readonly line?: number;
|
|
101
|
+
readonly column?: number;
|
|
102
|
+
readonly source?: string;
|
|
103
|
+
readonly suggestions?: readonly string[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create a new diagnostic collector.
|
|
107
|
+
*/
|
|
108
|
+
export declare function createDiagnosticCollector(): DiagnosticCollector;
|
|
109
|
+
/**
|
|
110
|
+
* Create a diagnostic from an Error object.
|
|
111
|
+
* Useful for converting caught exceptions into structured diagnostics.
|
|
112
|
+
*/
|
|
113
|
+
export declare function fromError(error: unknown, options?: Omit<DiagnosticOptions, 'code'> & {
|
|
114
|
+
code?: string;
|
|
115
|
+
}): Diagnostic;
|
|
116
|
+
/**
|
|
117
|
+
* Filter diagnostics by severity.
|
|
118
|
+
*/
|
|
119
|
+
export declare function filterBySeverity(diagnostics: readonly Diagnostic[], severity: DiagnosticSeverity): readonly Diagnostic[];
|
|
120
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|