@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,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Utilities
|
|
3
|
+
*
|
|
4
|
+
* Core token creation, stream implementation, and character classification.
|
|
5
|
+
* These are the foundational building blocks used by all tokenizers.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { LanguageToken, TokenKind, TokenStream, StreamMark, SourcePosition } from '../types';
|
|
9
|
+
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Time Unit Configuration
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for a native language time unit pattern.
|
|
16
|
+
* Used by tryNumberWithTimeUnits() to match language-specific time units.
|
|
17
|
+
*/
|
|
18
|
+
export interface TimeUnitMapping {
|
|
19
|
+
/** The pattern to match (e.g., 'segundos', 'ミリ秒') */
|
|
20
|
+
readonly pattern: string;
|
|
21
|
+
/** The standard suffix to use (ms, s, m, h) */
|
|
22
|
+
readonly suffix: string;
|
|
23
|
+
/** Length of the pattern (for optimization) */
|
|
24
|
+
readonly length: number;
|
|
25
|
+
/** Whether to check for word boundary after the pattern */
|
|
26
|
+
readonly checkBoundary?: boolean;
|
|
27
|
+
/** Character that cannot follow the pattern (e.g., 's' for 'm' to avoid 'ms') */
|
|
28
|
+
readonly notFollowedBy?: string;
|
|
29
|
+
/** Whether to do case-insensitive matching */
|
|
30
|
+
readonly caseInsensitive?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// Token Stream Implementation
|
|
35
|
+
// =============================================================================
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Concrete implementation of TokenStream.
|
|
39
|
+
*/
|
|
40
|
+
export class TokenStreamImpl implements TokenStream {
|
|
41
|
+
readonly tokens: readonly LanguageToken[];
|
|
42
|
+
readonly language: string;
|
|
43
|
+
private pos: number = 0;
|
|
44
|
+
|
|
45
|
+
constructor(tokens: LanguageToken[], language: string) {
|
|
46
|
+
this.tokens = tokens;
|
|
47
|
+
this.language = language;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
peek(offset: number = 0): LanguageToken | null {
|
|
51
|
+
const index = this.pos + offset;
|
|
52
|
+
if (index < 0 || index >= this.tokens.length) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return this.tokens[index];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
advance(): LanguageToken {
|
|
59
|
+
if (this.isAtEnd()) {
|
|
60
|
+
throw new Error('Unexpected end of token stream');
|
|
61
|
+
}
|
|
62
|
+
return this.tokens[this.pos++];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
isAtEnd(): boolean {
|
|
66
|
+
return this.pos >= this.tokens.length;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
mark(): StreamMark {
|
|
70
|
+
return { position: this.pos };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
reset(mark: StreamMark): void {
|
|
74
|
+
this.pos = mark.position;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
position(): number {
|
|
78
|
+
return this.pos;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get remaining tokens as an array.
|
|
83
|
+
*/
|
|
84
|
+
remaining(): LanguageToken[] {
|
|
85
|
+
return this.tokens.slice(this.pos);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Consume tokens while predicate is true.
|
|
90
|
+
*/
|
|
91
|
+
takeWhile(predicate: (token: LanguageToken) => boolean): LanguageToken[] {
|
|
92
|
+
const result: LanguageToken[] = [];
|
|
93
|
+
while (!this.isAtEnd() && predicate(this.peek()!)) {
|
|
94
|
+
result.push(this.advance());
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Skip tokens while predicate is true.
|
|
101
|
+
*/
|
|
102
|
+
skipWhile(predicate: (token: LanguageToken) => boolean): void {
|
|
103
|
+
while (!this.isAtEnd() && predicate(this.peek()!)) {
|
|
104
|
+
this.advance();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// =============================================================================
|
|
110
|
+
// Shared Tokenization Utilities
|
|
111
|
+
// =============================================================================
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Create a source position from start and end offsets.
|
|
115
|
+
*/
|
|
116
|
+
export function createPosition(start: number, end: number): SourcePosition {
|
|
117
|
+
return { start, end };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Options for creating a token with optional morphological data.
|
|
122
|
+
*/
|
|
123
|
+
export interface CreateTokenOptions {
|
|
124
|
+
/** Explicitly normalized form from keyword map */
|
|
125
|
+
normalized?: string;
|
|
126
|
+
/** Morphologically normalized stem */
|
|
127
|
+
stem?: string;
|
|
128
|
+
/** Confidence in the stem (0.0-1.0) */
|
|
129
|
+
stemConfidence?: number;
|
|
130
|
+
/** Additional metadata for specific token types (e.g., event modifier data) */
|
|
131
|
+
metadata?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Token creation options (object style).
|
|
136
|
+
*/
|
|
137
|
+
export interface TokenCreationParams extends CreateTokenOptions {
|
|
138
|
+
value: string;
|
|
139
|
+
kind: TokenKind;
|
|
140
|
+
position: SourcePosition;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Create a language token (object style).
|
|
145
|
+
*/
|
|
146
|
+
export function createToken(params: TokenCreationParams): LanguageToken;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Create a language token (separate parameters style).
|
|
150
|
+
*/
|
|
151
|
+
export function createToken(
|
|
152
|
+
value: string,
|
|
153
|
+
kind: TokenKind,
|
|
154
|
+
position: SourcePosition,
|
|
155
|
+
normalizedOrOptions?: string | CreateTokenOptions
|
|
156
|
+
): LanguageToken;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Create a language token.
|
|
160
|
+
* Supports both object style and separate parameters style.
|
|
161
|
+
*/
|
|
162
|
+
export function createToken(
|
|
163
|
+
valueOrParams: string | TokenCreationParams,
|
|
164
|
+
kind?: TokenKind,
|
|
165
|
+
position?: SourcePosition,
|
|
166
|
+
normalizedOrOptions?: string | CreateTokenOptions
|
|
167
|
+
): LanguageToken {
|
|
168
|
+
// Handle object style
|
|
169
|
+
if (typeof valueOrParams === 'object') {
|
|
170
|
+
const { value, kind, position, normalized, stem, stemConfidence, metadata } = valueOrParams;
|
|
171
|
+
return {
|
|
172
|
+
value,
|
|
173
|
+
kind,
|
|
174
|
+
position,
|
|
175
|
+
...(normalized !== undefined && { normalized }),
|
|
176
|
+
...(stem !== undefined && { stem }),
|
|
177
|
+
...(stemConfidence !== undefined && { stemConfidence }),
|
|
178
|
+
...(metadata !== undefined && { metadata }),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Handle separate parameters style
|
|
183
|
+
const value = valueOrParams;
|
|
184
|
+
if (!kind || !position) {
|
|
185
|
+
throw new Error('createToken requires kind and position parameters');
|
|
186
|
+
}
|
|
187
|
+
// Handle legacy string argument for backward compatibility
|
|
188
|
+
if (typeof normalizedOrOptions === 'string') {
|
|
189
|
+
return { value, kind, position, normalized: normalizedOrOptions };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Handle options object
|
|
193
|
+
if (normalizedOrOptions) {
|
|
194
|
+
const { normalized, stem, stemConfidence, metadata } = normalizedOrOptions;
|
|
195
|
+
return {
|
|
196
|
+
value,
|
|
197
|
+
kind,
|
|
198
|
+
position,
|
|
199
|
+
...(normalized !== undefined && { normalized }),
|
|
200
|
+
...(stem !== undefined && { stem }),
|
|
201
|
+
...(stemConfidence !== undefined && { stemConfidence }),
|
|
202
|
+
...(metadata !== undefined && { metadata }),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return { value, kind, position };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Check if a character is whitespace.
|
|
211
|
+
*/
|
|
212
|
+
export function isWhitespace(char: string): boolean {
|
|
213
|
+
return /\s/.test(char);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Check if a string starts with a CSS selector prefix.
|
|
218
|
+
* Includes JSX-style element selectors: <form />, <div>
|
|
219
|
+
*/
|
|
220
|
+
export function isSelectorStart(char: string): boolean {
|
|
221
|
+
return (
|
|
222
|
+
char === '#' || char === '.' || char === '[' || char === '@' || char === '*' || char === '<'
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Check if a character is a quote (string delimiter).
|
|
228
|
+
*/
|
|
229
|
+
export function isQuote(char: string): boolean {
|
|
230
|
+
return char === '"' || char === "'" || char === '`' || char === '「' || char === '」';
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Check if a character is a digit.
|
|
235
|
+
*/
|
|
236
|
+
export function isDigit(char: string): boolean {
|
|
237
|
+
return /\d/.test(char);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Check if a character is an ASCII letter.
|
|
242
|
+
*/
|
|
243
|
+
export function isAsciiLetter(char: string): boolean {
|
|
244
|
+
return /[a-zA-Z]/.test(char);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Check if a character is part of an ASCII identifier.
|
|
249
|
+
*/
|
|
250
|
+
export function isAsciiIdentifierChar(char: string): boolean {
|
|
251
|
+
return /[a-zA-Z0-9_-]/.test(char);
|
|
252
|
+
}
|