@lokascript/semantic 1.2.0 → 1.3.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 (43) hide show
  1. package/dist/core.d.ts +1246 -0
  2. package/dist/core.js +3073 -0
  3. package/dist/core.js.map +1 -0
  4. package/dist/languages/bn.d.ts +33 -0
  5. package/dist/languages/bn.js +1101 -0
  6. package/dist/languages/bn.js.map +1 -0
  7. package/dist/languages/es-MX.d.ts +23 -0
  8. package/dist/languages/es-MX.js +1676 -0
  9. package/dist/languages/es-MX.js.map +1 -0
  10. package/dist/languages/es.d.ts +3 -42
  11. package/dist/languages/he.d.ts +70 -0
  12. package/dist/languages/he.js +1331 -0
  13. package/dist/languages/he.js.map +1 -0
  14. package/dist/languages/hi.d.ts +36 -0
  15. package/dist/languages/hi.js +1162 -0
  16. package/dist/languages/hi.js.map +1 -0
  17. package/dist/languages/it.d.ts +53 -0
  18. package/dist/languages/it.js +1600 -0
  19. package/dist/languages/it.js.map +1 -0
  20. package/dist/languages/ms.d.ts +32 -0
  21. package/dist/languages/ms.js +1043 -0
  22. package/dist/languages/ms.js.map +1 -0
  23. package/dist/languages/pl.d.ts +37 -0
  24. package/dist/languages/pl.js +1331 -0
  25. package/dist/languages/pl.js.map +1 -0
  26. package/dist/languages/ru.d.ts +37 -0
  27. package/dist/languages/ru.js +1356 -0
  28. package/dist/languages/ru.js.map +1 -0
  29. package/dist/languages/th.d.ts +35 -0
  30. package/dist/languages/th.js +1076 -0
  31. package/dist/languages/th.js.map +1 -0
  32. package/dist/languages/tl.d.ts +32 -0
  33. package/dist/languages/tl.js +1034 -0
  34. package/dist/languages/tl.js.map +1 -0
  35. package/dist/languages/uk.d.ts +37 -0
  36. package/dist/languages/uk.js +1356 -0
  37. package/dist/languages/uk.js.map +1 -0
  38. package/dist/languages/vi.d.ts +59 -0
  39. package/dist/languages/vi.js +1220 -0
  40. package/dist/languages/vi.js.map +1 -0
  41. package/dist/spanish-BedpM-NU.d.ts +43 -0
  42. package/package.json +53 -1
  43. package/src/core.ts +155 -0
package/dist/core.d.ts ADDED
@@ -0,0 +1,1246 @@
1
+ /**
2
+ * Grammar Types for Semantic Multilingual Parsing
3
+ *
4
+ * These types define the semantic role system used across all 13 supported languages.
5
+ * Originally from @lokascript/i18n, now consolidated here for package independence.
6
+ *
7
+ * Key Linguistic Concepts:
8
+ * - Word Order: SVO, SOV, VSO (and variations)
9
+ * - Adposition Type: Preposition (English) vs Postposition (Japanese/Korean)
10
+ * - Morphology: Isolating (Chinese) vs Agglutinative (Turkish) vs Fusional (Arabic)
11
+ * - Text Direction: LTR vs RTL
12
+ */
13
+ /**
14
+ * Semantic roles in hyperscript commands.
15
+ * These are universal across all 13 supported languages - only the surface form changes.
16
+ *
17
+ * ## Core Thematic Roles (from linguistic theory)
18
+ * | Role | Usage | Purpose | Example |
19
+ * |-------------|-------|-----------------------------|---------------------------|
20
+ * | action | 100% | Command verb | toggle, put, fetch |
21
+ * | patient | 90% | What is acted upon | .active, #count |
22
+ * | destination | 40% | Where something goes | into #output, to .class |
23
+ * | source | 13% | Where something comes from | from #input, from URL |
24
+ * | event | 106% | Trigger events | click, keydown, submit |
25
+ * | condition | 8% | Boolean expressions | if x > 5, when visible |
26
+ * | agent | 0% | Who performs action | Reserved for future use |
27
+ * | goal | 1% | Target value/state | to 'red' (in transition) |
28
+ *
29
+ * ## Quantitative Roles (answer "how much/long")
30
+ * | Role | Usage | Purpose | Example |
31
+ * |----------|-------|----------------|----------------------|
32
+ * | quantity | 7% | Numeric amount | by 5, 3 times |
33
+ * | duration | 1% | Time span | for 5 seconds, 500ms |
34
+ *
35
+ * ## Adverbial/Modifier Roles (answer "how/by what means")
36
+ * | Role | Usage | Purpose | Example |
37
+ * |--------------|-------|---------------------------|-------------------|
38
+ * | style | 2% | Animation/behavior | with fade |
39
+ * | manner | 2% | Insertion position | before, after |
40
+ * | method | 1% | HTTP method/technique | via POST, as GET |
41
+ * | responseType | 1% | Response format | as json, as html |
42
+ *
43
+ * ## Control Flow Roles
44
+ * | Role | Usage | Purpose | Example |
45
+ * |----------|-------|--------------|-----------------------|
46
+ * | loopType | 6% | Loop variant | forever, until, times |
47
+ *
48
+ * ## Design Notes
49
+ * - Low-usage roles (agent, goal, method, responseType) are intentionally kept for:
50
+ * - Linguistic completeness across all 13 languages
51
+ * - Future extensibility (AI agents, server-side execution)
52
+ * - Command-specific semantics (fetch, transition)
53
+ * - Each role has distinct grammatical markers per language (see profiles/index.ts)
54
+ * - Usage percentages based on pattern database analysis
55
+ */
56
+ type SemanticRole = 'action' | 'agent' | 'patient' | 'source' | 'destination' | 'goal' | 'event' | 'condition' | 'quantity' | 'duration' | 'responseType' | 'method' | 'style' | 'manner' | 'loopType' | 'continues';
57
+
58
+ /**
59
+ * Semantic-First Multilingual Hyperscript Types
60
+ *
61
+ * This module defines the canonical semantic representation that all languages
62
+ * parse to and render from. The semantic layer is language-neutral - it captures
63
+ * the MEANING of hyperscript commands independent of surface syntax.
64
+ */
65
+
66
+ /**
67
+ * Canonical action names (English-based internally, but not visible to users)
68
+ * These map to hyperscript commands and are used in the semantic AST.
69
+ */
70
+ type ActionType = 'toggle' | 'add' | 'remove' | 'put' | 'append' | 'prepend' | 'take' | 'make' | 'clone' | 'swap' | 'morph' | 'set' | 'get' | 'increment' | 'decrement' | 'log' | 'show' | 'hide' | 'transition' | 'on' | 'trigger' | 'send' | 'focus' | 'blur' | 'go' | 'wait' | 'fetch' | 'settle' | 'measure' | 'install' | 'if' | 'unless' | 'else' | 'repeat' | 'for' | 'while' | 'continue' | 'halt' | 'throw' | 'call' | 'return' | 'js' | 'async' | 'tell' | 'default' | 'init' | 'behavior' | 'compound';
71
+ /**
72
+ * A semantic value represents a typed piece of data in a semantic node.
73
+ * Values are language-neutral - they capture what something IS, not how it's written.
74
+ */
75
+ type SemanticValue = LiteralValue | SelectorValue | ReferenceValue | PropertyPathValue | ExpressionValue;
76
+ interface LiteralValue {
77
+ readonly type: 'literal';
78
+ readonly value: string | number | boolean;
79
+ readonly dataType?: 'string' | 'number' | 'boolean' | 'duration';
80
+ }
81
+ interface SelectorValue {
82
+ readonly type: 'selector';
83
+ readonly value: string;
84
+ readonly selectorKind: 'id' | 'class' | 'attribute' | 'element' | 'complex';
85
+ }
86
+ interface ReferenceValue {
87
+ readonly type: 'reference';
88
+ readonly value: 'me' | 'you' | 'it' | 'result' | 'event' | 'target' | 'body';
89
+ }
90
+ interface PropertyPathValue {
91
+ readonly type: 'property-path';
92
+ readonly object: SemanticValue;
93
+ readonly property: string;
94
+ }
95
+ interface ExpressionValue {
96
+ readonly type: 'expression';
97
+ /** Raw expression string for complex expressions that need further parsing */
98
+ readonly raw: string;
99
+ }
100
+ /**
101
+ * Base interface for all semantic nodes.
102
+ * Semantic nodes capture the MEANING of hyperscript constructs.
103
+ */
104
+ interface SemanticNode {
105
+ readonly kind: 'command' | 'event-handler' | 'conditional' | 'compound' | 'loop';
106
+ readonly action: ActionType;
107
+ readonly roles: ReadonlyMap<SemanticRole, SemanticValue>;
108
+ readonly metadata?: SemanticMetadata;
109
+ }
110
+ /**
111
+ * Metadata about the source of a semantic node.
112
+ * Useful for debugging, error messages, and round-trip conversion.
113
+ */
114
+ interface SemanticMetadata {
115
+ readonly sourceLanguage?: string;
116
+ readonly sourceText?: string;
117
+ readonly sourcePosition?: SourcePosition;
118
+ readonly patternId?: string;
119
+ /**
120
+ * Confidence score for the parse (0-1).
121
+ * Higher values indicate more certain matches.
122
+ * - 1.0: Exact match with all roles captured
123
+ * - 0.8-0.99: High confidence with minor uncertainty (stem matching, optional roles)
124
+ * - 0.6-0.8: Medium confidence (morphological normalization, defaults applied)
125
+ * - <0.6: Low confidence (may need fallback to traditional parser)
126
+ */
127
+ readonly confidence?: number;
128
+ }
129
+ interface SourcePosition {
130
+ readonly start: number;
131
+ readonly end: number;
132
+ readonly line?: number;
133
+ readonly column?: number;
134
+ }
135
+ /**
136
+ * A command semantic node - represents a single hyperscript command.
137
+ */
138
+ interface CommandSemanticNode extends SemanticNode {
139
+ readonly kind: 'command';
140
+ }
141
+ /**
142
+ * An event handler semantic node - represents "on [event] [commands]".
143
+ */
144
+ interface EventHandlerSemanticNode extends SemanticNode {
145
+ readonly kind: 'event-handler';
146
+ readonly action: 'on';
147
+ readonly body: SemanticNode[];
148
+ readonly eventModifiers?: EventModifiers;
149
+ /**
150
+ * Event parameter names for destructuring.
151
+ * E.g., for "on click(clientX, clientY)", this would be ['clientX', 'clientY']
152
+ */
153
+ readonly parameterNames?: readonly string[];
154
+ }
155
+ interface EventModifiers {
156
+ readonly once?: boolean;
157
+ readonly debounce?: number;
158
+ readonly throttle?: number;
159
+ readonly queue?: 'first' | 'last' | 'all' | 'none';
160
+ readonly from?: SemanticValue;
161
+ }
162
+ /**
163
+ * A conditional semantic node - represents "if [condition] then [body] else [body]".
164
+ */
165
+ interface ConditionalSemanticNode extends SemanticNode {
166
+ readonly kind: 'conditional';
167
+ readonly action: 'if';
168
+ readonly thenBranch: SemanticNode[];
169
+ readonly elseBranch?: SemanticNode[];
170
+ }
171
+ /**
172
+ * A compound semantic node - represents multiple chained statements.
173
+ */
174
+ interface CompoundSemanticNode extends SemanticNode {
175
+ readonly kind: 'compound';
176
+ readonly statements: SemanticNode[];
177
+ readonly chainType: 'then' | 'and' | 'async';
178
+ }
179
+ /**
180
+ * Loop variant discriminant for different loop types.
181
+ */
182
+ type LoopVariant = 'forever' | 'times' | 'for' | 'while' | 'until';
183
+ /**
184
+ * A loop semantic node - represents repeat/for/while loops.
185
+ */
186
+ interface LoopSemanticNode extends SemanticNode {
187
+ readonly kind: 'loop';
188
+ readonly action: 'repeat' | 'for' | 'while';
189
+ /** The type of loop (forever, times, for, while, until) */
190
+ readonly loopVariant: LoopVariant;
191
+ /** Commands to execute in each iteration */
192
+ readonly body: SemanticNode[];
193
+ /** Loop variable name for 'for' loops (e.g., 'item' in 'for item in list') */
194
+ readonly loopVariable?: string;
195
+ /** Index variable name if specified (e.g., 'i' in 'for item with index i') */
196
+ readonly indexVariable?: string;
197
+ }
198
+ /**
199
+ * A pattern defines how a semantic structure appears in a specific language.
200
+ * Patterns enable bidirectional conversion: parse (natural → semantic) and
201
+ * render (semantic → natural).
202
+ */
203
+ interface LanguagePattern {
204
+ /** Unique identifier for this pattern */
205
+ readonly id: string;
206
+ /** ISO 639-1 language code */
207
+ readonly language: string;
208
+ /** Which command this pattern matches */
209
+ readonly command: ActionType;
210
+ /** Priority for disambiguation (higher = checked first) */
211
+ readonly priority: number;
212
+ /** The pattern template with role placeholders */
213
+ readonly template: PatternTemplate;
214
+ /** Rules for extracting semantic roles from matched tokens */
215
+ readonly extraction: ExtractionRules;
216
+ /** Optional constraints on when this pattern applies */
217
+ readonly constraints?: PatternConstraints;
218
+ }
219
+ /**
220
+ * A pattern template defines the expected token sequence.
221
+ *
222
+ * Template syntax:
223
+ * - Literal tokens: "toggle", "を", "على"
224
+ * - Role placeholders: {patient}, {target}, {destination}
225
+ * - Optional groups: [on {target}]
226
+ * - Alternatives in extraction (not in template string)
227
+ *
228
+ * Example templates:
229
+ * - English: "toggle {patient} [on {target}]"
230
+ * - Japanese: "{target} の {patient} を 切り替え"
231
+ * - Arabic: "بدّل {patient} [على {target}]"
232
+ */
233
+ interface PatternTemplate {
234
+ /** Human-readable template string */
235
+ readonly format: string;
236
+ /** Parsed token sequence for matching */
237
+ readonly tokens: PatternToken[];
238
+ }
239
+ type PatternToken = LiteralPatternToken | RolePatternToken | GroupPatternToken;
240
+ interface LiteralPatternToken {
241
+ readonly type: 'literal';
242
+ readonly value: string;
243
+ /** Alternative spellings/forms that also match */
244
+ readonly alternatives?: string[];
245
+ }
246
+ interface RolePatternToken {
247
+ readonly type: 'role';
248
+ readonly role: SemanticRole;
249
+ readonly optional?: boolean;
250
+ /** Expected value types (for validation) */
251
+ readonly expectedTypes?: Array<SemanticValue['type']>;
252
+ }
253
+ interface GroupPatternToken {
254
+ readonly type: 'group';
255
+ readonly tokens: PatternToken[];
256
+ readonly optional?: boolean;
257
+ }
258
+ /**
259
+ * Rules for extracting semantic values from matched tokens.
260
+ */
261
+ interface ExtractionRules {
262
+ readonly [role: string]: ExtractionRule;
263
+ }
264
+ interface ExtractionRule {
265
+ /** Position-based extraction (0-indexed from pattern start) */
266
+ readonly position?: number;
267
+ /** Marker-based extraction (find value after this marker) */
268
+ readonly marker?: string;
269
+ /** Alternative markers that also work */
270
+ readonly markerAlternatives?: string[];
271
+ /** Transform the extracted value */
272
+ readonly transform?: (raw: string) => SemanticValue;
273
+ /** Default value if not found (for optional roles) */
274
+ readonly default?: SemanticValue;
275
+ /** Static value extraction (for event handler wrapped commands) */
276
+ readonly value?: string;
277
+ /** Extract value from a pattern role by name */
278
+ readonly fromRole?: string;
279
+ }
280
+ /**
281
+ * Additional constraints on pattern applicability.
282
+ */
283
+ interface PatternConstraints {
284
+ /** Required roles that must be present */
285
+ readonly requiredRoles?: SemanticRole[];
286
+ /** Roles that must NOT be present */
287
+ readonly forbiddenRoles?: SemanticRole[];
288
+ /** Valid selector types for the patient role */
289
+ readonly validPatientTypes?: Array<SelectorValue['selectorKind']>;
290
+ /** Pattern IDs this conflicts with */
291
+ readonly conflictsWith?: string[];
292
+ }
293
+ /**
294
+ * A token from language-specific tokenization.
295
+ */
296
+ interface LanguageToken {
297
+ readonly value: string;
298
+ readonly kind: TokenKind;
299
+ readonly position: SourcePosition;
300
+ /** Normalized form from explicit keyword map (e.g., 切り替え → toggle) */
301
+ readonly normalized?: string;
302
+ /** Morphologically normalized stem (e.g., 切り替えた → 切り替え) */
303
+ readonly stem?: string;
304
+ /** Confidence in the morphological stem (0.0-1.0) */
305
+ readonly stemConfidence?: number;
306
+ /** Additional metadata for specific token types (e.g., event modifier data) */
307
+ readonly metadata?: Record<string, unknown>;
308
+ }
309
+ type TokenKind = 'keyword' | 'selector' | 'literal' | 'particle' | 'conjunction' | 'event-modifier' | 'identifier' | 'operator' | 'punctuation' | 'url';
310
+ /**
311
+ * A stream of tokens with navigation capabilities.
312
+ */
313
+ interface TokenStream {
314
+ readonly tokens: readonly LanguageToken[];
315
+ readonly language: string;
316
+ /** Look at token at current position + offset without consuming */
317
+ peek(offset?: number): LanguageToken | null;
318
+ /** Consume and return current token, advance position */
319
+ advance(): LanguageToken;
320
+ /** Check if we've consumed all tokens */
321
+ isAtEnd(): boolean;
322
+ /** Save current position for backtracking */
323
+ mark(): StreamMark;
324
+ /** Restore to a saved position */
325
+ reset(mark: StreamMark): void;
326
+ /** Get current position */
327
+ position(): number;
328
+ }
329
+ interface StreamMark {
330
+ readonly position: number;
331
+ }
332
+ /**
333
+ * Result of successfully matching a pattern.
334
+ */
335
+ interface PatternMatchResult {
336
+ readonly pattern: LanguagePattern;
337
+ readonly captured: ReadonlyMap<SemanticRole, SemanticValue>;
338
+ readonly consumedTokens: number;
339
+ readonly confidence: number;
340
+ }
341
+ /**
342
+ * Language-specific tokenizer interface.
343
+ * Each language implements its own tokenizer to handle:
344
+ * - Word boundaries (spaces for English, particles for Japanese)
345
+ * - Character sets (ASCII, CJK, Arabic, etc.)
346
+ * - Special markers (particles, prefixes, suffixes)
347
+ */
348
+ interface LanguageTokenizer {
349
+ readonly language: string;
350
+ readonly direction: 'ltr' | 'rtl';
351
+ /** Convert input string to token stream */
352
+ tokenize(input: string): TokenStream;
353
+ /** Classify a single token */
354
+ classifyToken(token: string): TokenKind;
355
+ }
356
+ /**
357
+ * Create a selector semantic value from a CSS selector string.
358
+ */
359
+ declare function createSelector(value: string): SelectorValue;
360
+ /**
361
+ * Create a literal semantic value.
362
+ */
363
+ declare function createLiteral(value: string | number | boolean, dataType?: LiteralValue['dataType']): LiteralValue;
364
+ /**
365
+ * Create a reference semantic value.
366
+ */
367
+ declare function createReference(value: ReferenceValue['value']): ReferenceValue;
368
+ /**
369
+ * Create a property path semantic value.
370
+ */
371
+ declare function createPropertyPath(object: SemanticValue, property: string): PropertyPathValue;
372
+ /**
373
+ * Create a semantic node with the given action and roles.
374
+ */
375
+ declare function createCommandNode(action: ActionType, roles: Record<string, SemanticValue>, metadata?: SemanticMetadata): CommandSemanticNode;
376
+ /**
377
+ * Create an event handler semantic node.
378
+ */
379
+ declare function createEventHandler(event: SemanticValue, body: SemanticNode[], modifiers?: EventModifiers, metadata?: SemanticMetadata, parameterNames?: string[]): EventHandlerSemanticNode;
380
+
381
+ /**
382
+ * Semantic Result Cache
383
+ *
384
+ * LRU cache for semantic analysis results to optimize repeated parsing.
385
+ *
386
+ * Design:
387
+ * - Cache key: `${language}:${input}` for simple, fast lookups
388
+ * - LRU eviction when max size reached
389
+ * - Optional TTL (time-to-live) for cache entries
390
+ * - Statistics for monitoring cache effectiveness
391
+ * - Thread-safe for browser environments (single-threaded)
392
+ */
393
+
394
+ /**
395
+ * Cache configuration options.
396
+ */
397
+ interface SemanticCacheConfig {
398
+ /** Maximum number of entries to cache. Default: 1000 */
399
+ maxSize?: number;
400
+ /** Time-to-live in milliseconds. 0 = no expiration. Default: 0 */
401
+ ttlMs?: number;
402
+ /** Enable/disable caching. Default: true */
403
+ enabled?: boolean;
404
+ }
405
+ /**
406
+ * Cache statistics.
407
+ */
408
+ interface CacheStats {
409
+ /** Total cache hits */
410
+ hits: number;
411
+ /** Total cache misses */
412
+ misses: number;
413
+ /** Current cache size */
414
+ size: number;
415
+ /** Maximum cache size */
416
+ maxSize: number;
417
+ /** Hit rate (0-1) */
418
+ hitRate: number;
419
+ /** Total evictions due to size limit */
420
+ evictions: number;
421
+ /** Total expirations due to TTL */
422
+ expirations: number;
423
+ /** Whether caching is enabled */
424
+ enabled: boolean;
425
+ }
426
+ /**
427
+ * LRU Cache for semantic analysis results.
428
+ *
429
+ * Uses Map's insertion order for LRU eviction - when we access an entry,
430
+ * we delete and re-insert it to move it to the end (most recently used).
431
+ */
432
+ declare class SemanticCache {
433
+ private cache;
434
+ private config;
435
+ private stats;
436
+ constructor(config?: SemanticCacheConfig);
437
+ /**
438
+ * Generate cache key from input and language.
439
+ */
440
+ private makeKey;
441
+ /**
442
+ * Check if an entry has expired.
443
+ */
444
+ private isExpired;
445
+ /**
446
+ * Evict the least recently used entry.
447
+ */
448
+ private evictLRU;
449
+ /**
450
+ * Get a cached result.
451
+ *
452
+ * @param input - The input string
453
+ * @param language - The language code
454
+ * @returns The cached result, or undefined if not found/expired
455
+ */
456
+ get(input: string, language: string): SemanticAnalysisResult | undefined;
457
+ /**
458
+ * Store a result in the cache.
459
+ *
460
+ * @param input - The input string
461
+ * @param language - The language code
462
+ * @param result - The analysis result to cache
463
+ */
464
+ set(input: string, language: string, result: SemanticAnalysisResult): void;
465
+ /**
466
+ * Check if a result is cached (without updating LRU).
467
+ */
468
+ has(input: string, language: string): boolean;
469
+ /**
470
+ * Remove a specific entry from the cache.
471
+ */
472
+ delete(input: string, language: string): boolean;
473
+ /**
474
+ * Clear all cached entries.
475
+ */
476
+ clear(): void;
477
+ /**
478
+ * Reset statistics.
479
+ */
480
+ resetStats(): void;
481
+ /**
482
+ * Get cache statistics.
483
+ */
484
+ getStats(): CacheStats;
485
+ /**
486
+ * Update cache configuration.
487
+ */
488
+ configure(config: Partial<SemanticCacheConfig>): void;
489
+ /**
490
+ * Enable caching.
491
+ */
492
+ enable(): void;
493
+ /**
494
+ * Disable caching.
495
+ */
496
+ disable(): void;
497
+ /**
498
+ * Get current configuration.
499
+ */
500
+ getConfig(): Readonly<Required<SemanticCacheConfig>>;
501
+ }
502
+ /**
503
+ * Default global cache instance.
504
+ */
505
+ declare const semanticCache: SemanticCache;
506
+ /**
507
+ * Create a cache with custom configuration.
508
+ */
509
+ declare function createSemanticCache(config?: SemanticCacheConfig): SemanticCache;
510
+ /**
511
+ * Decorator/wrapper for adding caching to an analyze function.
512
+ *
513
+ * @param analyzeFn - The analyze function to wrap
514
+ * @param cache - The cache instance to use
515
+ * @returns Wrapped function with caching
516
+ */
517
+ declare function withCache<T extends (input: string, language: string) => SemanticAnalysisResult>(analyzeFn: T, cache?: SemanticCache): T;
518
+
519
+ /**
520
+ * Core Parser Bridge
521
+ *
522
+ * Provides the SemanticAnalyzer interface that integrates semantic parsing
523
+ * into the core hyperscript parser. This bridge enables confidence-driven
524
+ * fallback between semantic and traditional parsing.
525
+ */
526
+
527
+ /**
528
+ * Result of semantic analysis.
529
+ */
530
+ interface SemanticAnalysisResult {
531
+ /** Confidence score (0-1) for this analysis */
532
+ readonly confidence: number;
533
+ /** The parsed command info (if successful) */
534
+ readonly command?: {
535
+ readonly name: ActionType;
536
+ readonly roles: ReadonlyMap<SemanticRole, SemanticValue>;
537
+ };
538
+ /** The full semantic node (if successful) */
539
+ readonly node?: SemanticNode;
540
+ /** Any errors encountered */
541
+ readonly errors?: string[];
542
+ /** Number of tokens consumed */
543
+ readonly tokensConsumed?: number;
544
+ }
545
+ /**
546
+ * Interface for semantic analysis that can be integrated into the core parser.
547
+ * This allows the core parser to optionally use semantic parsing with
548
+ * confidence-based fallback to traditional parsing.
549
+ */
550
+ interface SemanticAnalyzer {
551
+ /**
552
+ * Analyze input in the specified language.
553
+ *
554
+ * @param input The input string to analyze
555
+ * @param language ISO 639-1 language code
556
+ * @returns Analysis result with confidence score
557
+ */
558
+ analyze(input: string, language: string): SemanticAnalysisResult;
559
+ /**
560
+ * Check if semantic parsing is available for a language.
561
+ */
562
+ supportsLanguage(language: string): boolean;
563
+ /**
564
+ * Get the list of supported languages.
565
+ */
566
+ supportedLanguages(): string[];
567
+ /**
568
+ * Get cache statistics.
569
+ */
570
+ getCacheStats(): CacheStats;
571
+ /**
572
+ * Clear the result cache.
573
+ */
574
+ clearCache(): void;
575
+ /**
576
+ * Configure the cache.
577
+ */
578
+ configureCache(config: Partial<SemanticCacheConfig>): void;
579
+ }
580
+ /**
581
+ * Options for creating a SemanticAnalyzer.
582
+ */
583
+ interface SemanticAnalyzerOptions {
584
+ /** Cache configuration. Pass false to disable caching. */
585
+ cache?: SemanticCacheConfig | false;
586
+ }
587
+ /**
588
+ * Implementation of SemanticAnalyzer that wraps the semantic parser.
589
+ * Includes LRU caching for performance optimization on repeated inputs.
590
+ */
591
+ declare class SemanticAnalyzerImpl implements SemanticAnalyzer {
592
+ private readonly patternMatcher;
593
+ private readonly languages;
594
+ private readonly cache;
595
+ constructor(options?: SemanticAnalyzerOptions);
596
+ analyze(input: string, language: string): SemanticAnalysisResult;
597
+ /**
598
+ * Perform analysis without cache lookup.
599
+ */
600
+ private analyzeUncached;
601
+ supportsLanguage(language: string): boolean;
602
+ supportedLanguages(): string[];
603
+ getCacheStats(): CacheStats;
604
+ clearCache(): void;
605
+ configureCache(config: Partial<SemanticCacheConfig>): void;
606
+ private buildSemanticNode;
607
+ }
608
+ /**
609
+ * Create a SemanticAnalyzer instance.
610
+ *
611
+ * @param options - Configuration options including cache settings
612
+ * @returns A new SemanticAnalyzer
613
+ *
614
+ * @example
615
+ * // Default: uses shared global cache
616
+ * const analyzer = createSemanticAnalyzer();
617
+ *
618
+ * @example
619
+ * // Custom cache size
620
+ * const analyzer = createSemanticAnalyzer({ cache: { maxSize: 500 } });
621
+ *
622
+ * @example
623
+ * // Disable caching
624
+ * const analyzer = createSemanticAnalyzer({ cache: false });
625
+ */
626
+ declare function createSemanticAnalyzer(options?: SemanticAnalyzerOptions): SemanticAnalyzer;
627
+
628
+ /**
629
+ * Default confidence threshold for preferring semantic parsing.
630
+ * If confidence is above this, use semantic result; otherwise fallback.
631
+ */
632
+ declare const DEFAULT_CONFIDENCE_THRESHOLD = 0.5;
633
+ /**
634
+ * High confidence threshold for very certain matches.
635
+ */
636
+ declare const HIGH_CONFIDENCE_THRESHOLD = 0.8;
637
+ /**
638
+ * Determine if semantic analysis should be used based on confidence.
639
+ */
640
+ declare function shouldUseSemanticResult(result: SemanticAnalysisResult, threshold?: number): boolean;
641
+ /**
642
+ * Convert semantic roles to the format expected by core parser commands.
643
+ * This maps semantic roles to the positional/modifier structure used by
644
+ * the core command implementations.
645
+ *
646
+ * Role to preposition mapping:
647
+ * - patient → first positional arg
648
+ * - event → first positional arg
649
+ * - destination → 'into' (put) or 'on' (others)
650
+ * - source → 'from'
651
+ * - quantity → 'by'
652
+ * - duration → 'over' or 'for'
653
+ * - method → 'as'
654
+ * - style → 'with'
655
+ * - condition → 'if'
656
+ */
657
+ declare function rolesToCommandArgs(roles: ReadonlyMap<SemanticRole, SemanticValue>, command: ActionType): {
658
+ args: SemanticValue[];
659
+ modifiers: Record<string, SemanticValue>;
660
+ };
661
+
662
+ /**
663
+ * Expression Parser Types
664
+ *
665
+ * Defines AST node types for expressions that can be shared between
666
+ * the semantic package (AST building) and core package (runtime).
667
+ *
668
+ * These types are intentionally minimal and focused on expressions only.
669
+ */
670
+ /**
671
+ * Base interface for all expression AST nodes
672
+ */
673
+ interface ExpressionNode {
674
+ readonly type: string;
675
+ readonly start?: number | undefined;
676
+ readonly end?: number | undefined;
677
+ readonly line?: number | undefined;
678
+ readonly column?: number | undefined;
679
+ }
680
+ interface LiteralNode extends ExpressionNode {
681
+ readonly type: 'literal';
682
+ readonly value: string | number | boolean | null | undefined;
683
+ readonly raw?: string | undefined;
684
+ readonly dataType?: 'string' | 'number' | 'boolean' | 'null' | 'undefined' | 'duration' | undefined;
685
+ }
686
+ type SelectorKind = 'id' | 'class' | 'attribute' | 'element' | 'query' | 'complex';
687
+ interface SelectorNode extends ExpressionNode {
688
+ readonly type: 'selector' | 'cssSelector' | 'idRef' | 'classRef';
689
+ readonly value?: string;
690
+ readonly selector?: string;
691
+ readonly selectorType?: SelectorKind;
692
+ }
693
+ type ContextType = 'me' | 'you' | 'it' | 'its' | 'my' | 'your' | 'result' | 'event' | 'target' | 'body' | 'detail';
694
+ interface ContextReferenceNode extends ExpressionNode {
695
+ readonly type: 'contextReference' | 'symbol';
696
+ readonly contextType?: ContextType;
697
+ readonly name?: string;
698
+ }
699
+ interface PropertyAccessNode extends ExpressionNode {
700
+ readonly type: 'propertyAccess';
701
+ readonly object: ExpressionNode;
702
+ readonly property: string;
703
+ }
704
+
705
+ /**
706
+ * Semantic Value to AST Node Converters
707
+ *
708
+ * Converts SemanticValue types to AST expression nodes.
709
+ * Used by the AST builder to construct expression trees from semantic parsing results.
710
+ */
711
+
712
+ /**
713
+ * Convert a SemanticValue to an AST ExpressionNode.
714
+ *
715
+ * @param value - The semantic value to convert
716
+ * @param warnings - Optional array to collect warnings about potentially incorrect type choices
717
+ * @returns The corresponding AST expression node
718
+ */
719
+ declare function convertValue(value: SemanticValue, warnings?: string[]): ExpressionNode;
720
+ /**
721
+ * Convert a LiteralValue to a LiteralNode.
722
+ */
723
+ declare function convertLiteral(value: LiteralValue): LiteralNode;
724
+ /**
725
+ * Convert a SelectorValue to a SelectorNode.
726
+ *
727
+ * @param value - The selector value to convert
728
+ * @param warnings - Optional array to collect warnings
729
+ */
730
+ declare function convertSelector(value: SelectorValue, warnings?: string[]): SelectorNode;
731
+ /**
732
+ * Convert a ReferenceValue to a ContextReferenceNode.
733
+ */
734
+ declare function convertReference(value: ReferenceValue): ContextReferenceNode;
735
+ /**
736
+ * Convert a PropertyPathValue to a PropertyAccessNode.
737
+ * Recursively converts the object part.
738
+ *
739
+ * @param value - The property path value to convert
740
+ * @param warnings - Optional array to collect warnings
741
+ */
742
+ declare function convertPropertyPath(value: PropertyPathValue, warnings?: string[]): PropertyAccessNode;
743
+ /**
744
+ * Convert an ExpressionValue (raw string) by parsing it with the expression parser.
745
+ * This is the fallback for complex expressions that couldn't be fully parsed
746
+ * at the semantic level.
747
+ */
748
+ declare function convertExpression(value: ExpressionValue): ExpressionNode;
749
+
750
+ /**
751
+ * Command-specific AST Mappers
752
+ *
753
+ * Each command can have a custom mapper that knows how to convert
754
+ * its semantic roles to the appropriate AST structure.
755
+ */
756
+
757
+ /**
758
+ * Result from command mapping, including the AST and any warnings.
759
+ */
760
+ interface CommandMapperResult {
761
+ ast: CommandNode;
762
+ warnings: string[];
763
+ }
764
+ /**
765
+ * Interface for command-specific AST mappers.
766
+ */
767
+ interface CommandMapper {
768
+ /**
769
+ * The action type this mapper handles.
770
+ */
771
+ readonly action: ActionType;
772
+ /**
773
+ * Convert a CommandSemanticNode to a CommandNode.
774
+ *
775
+ * @param node - The semantic command node
776
+ * @param builder - The AST builder (for recursive building if needed)
777
+ * @returns The AST command node with any warnings, or just the AST node for backward compatibility
778
+ */
779
+ toAST(node: CommandSemanticNode, builder: ASTBuilder): CommandMapperResult | CommandNode;
780
+ }
781
+ /**
782
+ * Get the command mapper for an action type.
783
+ *
784
+ * @param action - The action type
785
+ * @returns The mapper, or undefined if no specific mapper exists
786
+ */
787
+ declare function getCommandMapper(action: ActionType): CommandMapper | undefined;
788
+ /**
789
+ * Register a custom command mapper.
790
+ *
791
+ * @param mapper - The command mapper to register
792
+ */
793
+ declare function registerCommandMapper(mapper: CommandMapper): void;
794
+ /**
795
+ * Get all registered command mappers.
796
+ */
797
+ declare function getRegisteredMappers(): Map<ActionType, CommandMapper>;
798
+
799
+ /**
800
+ * Semantic to AST Builder
801
+ *
802
+ * Converts SemanticNodes directly to AST nodes, bypassing the English text
803
+ * generation and re-parsing step.
804
+ *
805
+ * Flow:
806
+ * Japanese → Semantic Parser → SemanticNode → AST Builder → AST
807
+ *
808
+ * Instead of:
809
+ * Japanese → Semantic Parser → SemanticNode → English Text → Parser → AST
810
+ */
811
+
812
+ /**
813
+ * Base AST node interface
814
+ */
815
+ interface ASTNode {
816
+ readonly type: string;
817
+ readonly start?: number;
818
+ readonly end?: number;
819
+ readonly line?: number;
820
+ readonly column?: number;
821
+ [key: string]: unknown;
822
+ }
823
+ /**
824
+ * Command AST node
825
+ */
826
+ interface CommandNode extends ASTNode {
827
+ readonly type: 'command';
828
+ readonly name: string;
829
+ readonly args: ExpressionNode[];
830
+ readonly modifiers?: Record<string, ExpressionNode>;
831
+ readonly isBlocking?: boolean;
832
+ readonly implicitTarget?: ExpressionNode;
833
+ }
834
+ /**
835
+ * Event handler AST node (compatible with @lokascript/core)
836
+ */
837
+ interface EventHandlerNode extends ASTNode {
838
+ readonly type: 'eventHandler';
839
+ /** Primary event name */
840
+ readonly event: string;
841
+ /** All event names when using "on event1 or event2" syntax */
842
+ readonly events?: string[];
843
+ /** CSS selector for event delegation ("from" keyword) */
844
+ readonly selector?: string;
845
+ /** Target for "from" clause (as string or expression) */
846
+ readonly target?: string;
847
+ /** Optional event condition ("[condition]" syntax) */
848
+ readonly condition?: ASTNode;
849
+ /** Attribute name for mutation events ("of @attribute" syntax) */
850
+ readonly attributeName?: string;
851
+ /** Target element to watch for changes ("in <target>" syntax) */
852
+ readonly watchTarget?: ExpressionNode;
853
+ /** Event parameter names to destructure (e.g., ['clientX', 'clientY']) */
854
+ readonly args?: string[];
855
+ /** Event parameters (alias for args) */
856
+ readonly params?: string[];
857
+ /** Handler commands */
858
+ readonly commands: ASTNode[];
859
+ }
860
+ /**
861
+ * Conditional AST node (if/else)
862
+ *
863
+ * Note: For runtime compatibility, buildConditional() now produces a CommandNode
864
+ * with condition and branches as args, matching what IfCommand expects.
865
+ * This interface is retained for reference but not used as output.
866
+ */
867
+ interface ConditionalNode extends ASTNode {
868
+ readonly type: 'if';
869
+ readonly condition: ExpressionNode;
870
+ readonly thenBranch: ASTNode[];
871
+ readonly elseBranch?: ASTNode[];
872
+ }
873
+ /**
874
+ * Command sequence node (runtime-compatible format for chained commands)
875
+ */
876
+ interface CommandSequenceNode extends ASTNode {
877
+ readonly type: 'CommandSequence';
878
+ /** Commands in the sequence */
879
+ readonly commands: ASTNode[];
880
+ }
881
+ /**
882
+ * Block node (for grouping commands)
883
+ */
884
+ interface BlockNode extends ASTNode {
885
+ readonly type: 'block';
886
+ readonly commands: ASTNode[];
887
+ }
888
+ interface ASTBuilderOptions {
889
+ /**
890
+ * Fallback function to parse complex expressions that can't be handled
891
+ * directly by the AST builder. Uses the expression-parser by default.
892
+ */
893
+ parseExpression?: (input: string) => ExpressionNode | null;
894
+ }
895
+ /**
896
+ * Builds AST nodes directly from SemanticNodes.
897
+ */
898
+ declare class ASTBuilder {
899
+ /**
900
+ * Warnings collected during AST building (e.g., type inference issues).
901
+ */
902
+ warnings: string[];
903
+ constructor(_options?: ASTBuilderOptions);
904
+ /**
905
+ * Build an AST from a SemanticNode.
906
+ *
907
+ * @param node - The semantic node to convert
908
+ * @returns The corresponding AST node
909
+ */
910
+ build(node: SemanticNode): ASTNode;
911
+ /**
912
+ * Build a CommandNode from a CommandSemanticNode.
913
+ */
914
+ private buildCommand;
915
+ /**
916
+ * Generic command builder when no specific mapper is available.
917
+ * Maps roles to args in a predictable order.
918
+ */
919
+ private buildGenericCommand;
920
+ /**
921
+ * Map semantic roles to hyperscript modifier keywords.
922
+ */
923
+ private roleToModifierKey;
924
+ /**
925
+ * Build an EventHandlerNode from an EventHandlerSemanticNode.
926
+ */
927
+ private buildEventHandler;
928
+ /**
929
+ * Build a CommandNode from a ConditionalSemanticNode.
930
+ *
931
+ * Produces a command node with:
932
+ * - args[0]: condition expression
933
+ * - args[1]: then block (wrapped in { type: 'block', commands: [...] })
934
+ * - args[2]: else block (optional, same format)
935
+ *
936
+ * This format matches what IfCommand.parseInput() expects.
937
+ */
938
+ private buildConditional;
939
+ /**
940
+ * Build AST nodes from a CompoundSemanticNode.
941
+ *
942
+ * Converts to CommandSequence for runtime compatibility.
943
+ * The runtime recognizes 'CommandSequence' type and executes commands in order.
944
+ */
945
+ private buildCompound;
946
+ /**
947
+ * Build a CommandNode from a LoopSemanticNode.
948
+ *
949
+ * Produces a 'repeat' command with:
950
+ * - args[0]: loop type identifier (forever, times, for, while, until)
951
+ * - args[1]: count/condition/variable depending on loop type
952
+ * - args[2]: collection (for 'for' loops)
953
+ * - args[last]: body block
954
+ *
955
+ * This format matches what the repeat command parser produces.
956
+ */
957
+ private buildLoop;
958
+ /**
959
+ * Build a BlockNode from an array of semantic nodes.
960
+ * Useful for grouping commands in if/else branches.
961
+ */
962
+ buildBlock(nodes: SemanticNode[]): BlockNode;
963
+ }
964
+ /**
965
+ * Result from building an AST, including any warnings.
966
+ */
967
+ interface BuildASTResult {
968
+ ast: ASTNode;
969
+ warnings: string[];
970
+ }
971
+ /**
972
+ * Build an AST from a SemanticNode using default options.
973
+ *
974
+ * @param node - The semantic node to convert
975
+ * @returns The corresponding AST node and any warnings
976
+ */
977
+ declare function buildAST(node: SemanticNode): BuildASTResult;
978
+
979
+ /**
980
+ * Language Profile Types
981
+ *
982
+ * Type definitions for language profiles, separated for tree-shaking.
983
+ */
984
+
985
+ /**
986
+ * Word order in a language (for declarative statements).
987
+ */
988
+ type WordOrder = 'SVO' | 'SOV' | 'VSO' | 'VOS' | 'OSV' | 'OVS';
989
+ /**
990
+ * How grammatical relationships are marked.
991
+ */
992
+ type MarkingStrategy = 'preposition' | 'postposition' | 'particle' | 'case-suffix';
993
+ /**
994
+ * A grammatical marker (preposition, particle, etc.) for a semantic role.
995
+ */
996
+ interface RoleMarker {
997
+ /** Primary marker for this role */
998
+ readonly primary: string;
999
+ /** Alternative markers that also work */
1000
+ readonly alternatives?: string[];
1001
+ /** Position relative to the role value */
1002
+ readonly position: 'before' | 'after';
1003
+ }
1004
+ /**
1005
+ * Verb form configuration for a language.
1006
+ */
1007
+ interface VerbConfig {
1008
+ /** Position of verb in the sentence */
1009
+ readonly position: 'start' | 'end' | 'second';
1010
+ /** Common verb suffixes/conjugations to recognize */
1011
+ readonly suffixes?: string[];
1012
+ /** Whether the language commonly drops subjects */
1013
+ readonly subjectDrop?: boolean;
1014
+ }
1015
+ /**
1016
+ * Configuration for possessive expression construction.
1017
+ * Defines how "X's property" is expressed in a language.
1018
+ */
1019
+ interface PossessiveConfig {
1020
+ /** Possessive marker (e.g., "'s" in English, "の" in Japanese) */
1021
+ readonly marker: string;
1022
+ /** Position of marker: 'after-object' (X's Y), 'between' (X の Y), 'before-property' */
1023
+ readonly markerPosition: 'after-object' | 'between' | 'before-property';
1024
+ /** Special possessive forms (e.g., 'me' → 'my' in English) */
1025
+ readonly specialForms?: Record<string, string>;
1026
+ /** Whether to use possessive adjectives instead of marker (e.g., Spanish mi/tu/su) */
1027
+ readonly usePossessiveAdjectives?: boolean;
1028
+ /**
1029
+ * Possessive keywords mapped to their corresponding reference.
1030
+ * Used by pattern-matcher to recognize possessive expressions.
1031
+ * Example: { my: 'me', your: 'you', its: 'it' }
1032
+ */
1033
+ readonly keywords?: Record<string, string>;
1034
+ }
1035
+ /**
1036
+ * Complete language profile for pattern generation.
1037
+ */
1038
+ interface LanguageProfile {
1039
+ /** ISO 639-1 or BCP 47 language code (e.g., 'es' or 'es-MX') */
1040
+ readonly code: string;
1041
+ /** Human-readable language name */
1042
+ readonly name: string;
1043
+ /** Native name */
1044
+ readonly nativeName: string;
1045
+ /** Text direction */
1046
+ readonly direction: 'ltr' | 'rtl';
1047
+ /** Primary word order */
1048
+ readonly wordOrder: WordOrder;
1049
+ /** How this language marks grammatical roles */
1050
+ readonly markingStrategy: MarkingStrategy;
1051
+ /** Markers for each semantic role */
1052
+ readonly roleMarkers: Partial<Record<SemanticRole, RoleMarker>>;
1053
+ /** Verb configuration */
1054
+ readonly verb: VerbConfig;
1055
+ /** Command keyword translations */
1056
+ readonly keywords: Record<string, KeywordTranslation>;
1057
+ /** Whether the language uses spaces between words */
1058
+ readonly usesSpaces: boolean;
1059
+ /** Special tokenization notes */
1060
+ readonly tokenization?: TokenizationConfig;
1061
+ /** Reference translations (me, it, you, etc.) */
1062
+ readonly references?: Record<string, string>;
1063
+ /** Possessive expression configuration */
1064
+ readonly possessive?: PossessiveConfig;
1065
+ /** Event handler pattern configuration (for simple SVO languages) */
1066
+ readonly eventHandler?: EventHandlerConfig;
1067
+ /**
1068
+ * Default verb form for command keywords. Defaults to 'infinitive'.
1069
+ *
1070
+ * Based on software UI localization research:
1071
+ * - 'infinitive': Spanish, French, German, Portuguese, Russian (industry standard)
1072
+ * - 'imperative': Polish
1073
+ * - 'base': English, Japanese, Korean (no distinction or same form)
1074
+ *
1075
+ * Individual keywords can override this via KeywordTranslation.form
1076
+ */
1077
+ readonly defaultVerbForm?: VerbForm;
1078
+ /**
1079
+ * Base language code to extend (for regional variants).
1080
+ * When set, this profile inherits from the base and overrides specific fields.
1081
+ * Example: 'es-MX' profile with extends: 'es' inherits from Spanish base.
1082
+ */
1083
+ readonly extends?: string;
1084
+ }
1085
+ /**
1086
+ * Configuration for event handler pattern generation.
1087
+ * Supports both SVO and SOV/VSO languages.
1088
+ */
1089
+ interface EventHandlerConfig {
1090
+ /** Primary event keyword (e.g., 'on', 'bei', 'sur') for SVO */
1091
+ readonly keyword?: KeywordTranslation;
1092
+ /** Source filter marker (e.g., 'from', 'von', 'de') */
1093
+ readonly sourceMarker?: RoleMarker;
1094
+ /** Conditional keyword (e.g., 'when', 'wenn', 'quand') */
1095
+ readonly conditionalKeyword?: KeywordTranslation;
1096
+ /** Event marker for SOV/VSO languages (e.g., で (Japanese), 할 때 (Korean), da (Turkish), عند (Arabic)) */
1097
+ readonly eventMarker?: RoleMarker;
1098
+ /** Temporal/conditional markers that can optionally appear with events */
1099
+ readonly temporalMarkers?: string[];
1100
+ /**
1101
+ * Negation marker for expressing negated events (e.g., Arabic عدم = "not/lack of").
1102
+ * Used in patterns like: عند عدم التركيز = "when not focusing" = "on blur"
1103
+ */
1104
+ readonly negationMarker?: RoleMarker;
1105
+ }
1106
+ /**
1107
+ * Verb form used for command keywords.
1108
+ *
1109
+ * Based on software localization research:
1110
+ * - 'infinitive': Standard for most languages (Spanish, French, German, Russian)
1111
+ * Example: "Guardar", "Enregistrer", "Speichern"
1112
+ * - 'imperative': Used by some languages (Polish)
1113
+ * Example: "Zapisz", "Otwórz"
1114
+ * - 'base': For languages where forms are identical (English, Japanese, Korean)
1115
+ * or where the distinction doesn't apply
1116
+ */
1117
+ type VerbForm = 'infinitive' | 'imperative' | 'base';
1118
+ /**
1119
+ * Translation of a command keyword.
1120
+ */
1121
+ interface KeywordTranslation {
1122
+ /** Primary translation (used for output/rendering) */
1123
+ readonly primary: string;
1124
+ /** Alternative forms for parsing (conjugations, synonyms, informal variants) */
1125
+ readonly alternatives?: string[];
1126
+ /** Normalized English form for internal matching */
1127
+ readonly normalized?: string;
1128
+ /**
1129
+ * The grammatical form of 'primary'. Defaults to 'infinitive'.
1130
+ * This documents the form used and enables future form-switching features.
1131
+ * - 'infinitive': Dictionary form (alternar, basculer) - industry standard
1132
+ * - 'imperative': Command form (alterna, bascule) - for Polish, etc.
1133
+ * - 'base': Same form for both (toggle, トグル) - English, Japanese, Korean
1134
+ */
1135
+ readonly form?: VerbForm;
1136
+ }
1137
+ /**
1138
+ * Special tokenization configuration.
1139
+ */
1140
+ interface TokenizationConfig {
1141
+ /** Particles to recognize (for particle languages) */
1142
+ readonly particles?: string[];
1143
+ /** Prefixes to recognize (for prefixing languages) */
1144
+ readonly prefixes?: string[];
1145
+ /** Word boundary detection strategy */
1146
+ readonly boundaryStrategy?: 'space' | 'particle' | 'character';
1147
+ }
1148
+
1149
+ /**
1150
+ * Language Registry
1151
+ *
1152
+ * Central registration point for language support in the semantic parser.
1153
+ * Languages self-register when their modules are imported, enabling
1154
+ * tree-shaking for minimal bundles.
1155
+ *
1156
+ * @example
1157
+ * ```typescript
1158
+ * // Import only the languages you need
1159
+ * import '@lokascript/semantic/languages/en';
1160
+ * import '@lokascript/semantic/languages/es';
1161
+ *
1162
+ * // Now parse works for registered languages
1163
+ * import { parse } from '@lokascript/semantic';
1164
+ * parse('toggle .active', 'en'); // Works
1165
+ * parse('alternar .activo', 'es'); // Works
1166
+ * parse('切り替え .active', 'ja'); // Error: Language not registered
1167
+ * ```
1168
+ */
1169
+
1170
+ /**
1171
+ * Merge a variant profile with its base profile.
1172
+ * The variant's fields override the base, with deep merging for nested objects.
1173
+ *
1174
+ * @example
1175
+ * ```typescript
1176
+ * const esMX = mergeProfiles(spanishProfile, {
1177
+ * code: 'es-MX',
1178
+ * name: 'Spanish (Mexico)',
1179
+ * keywords: {
1180
+ * toggle: { primary: 'alternar', alternatives: ['dale', 'cambiar'] },
1181
+ * },
1182
+ * });
1183
+ * ```
1184
+ */
1185
+ declare function mergeProfiles(base: LanguageProfile, variant: Partial<LanguageProfile>): LanguageProfile;
1186
+ /**
1187
+ * Register a language with its tokenizer and profile.
1188
+ * Called automatically by language modules when imported.
1189
+ * If the profile has an `extends` field, it will inherit from the base profile.
1190
+ */
1191
+ declare function registerLanguage(code: string, tokenizer: LanguageTokenizer, profile: LanguageProfile): void;
1192
+ /**
1193
+ * Set the pattern generator function.
1194
+ * Called by patterns module to inject the generator without circular deps.
1195
+ */
1196
+ declare function setPatternGenerator(generator: (profile: LanguageProfile) => LanguagePattern[]): void;
1197
+ /**
1198
+ * Register patterns directly for a language.
1199
+ * This enables tree-shaking by allowing each language module to register
1200
+ * only its own patterns.
1201
+ */
1202
+ declare function registerPatterns(code: string, patterns: LanguagePattern[]): void;
1203
+ /**
1204
+ * Get a tokenizer for the specified language.
1205
+ * Supports fallback: if 'es-MX' is not registered, falls back to 'es'.
1206
+ * @throws Error if neither the variant nor base language is registered
1207
+ */
1208
+ declare function getTokenizer(code: string): LanguageTokenizer;
1209
+ /**
1210
+ * Get a profile for the specified language.
1211
+ * Supports fallback: if 'es-MX' is not registered, falls back to 'es'.
1212
+ * @throws Error if neither the variant nor base language is registered
1213
+ */
1214
+ declare function getProfile(code: string): LanguageProfile;
1215
+ /**
1216
+ * Try to get a profile, returning undefined if not registered.
1217
+ * Supports fallback: if 'es-MX' is not registered, falls back to 'es'.
1218
+ */
1219
+ declare function tryGetProfile(code: string): LanguageProfile | undefined;
1220
+ /**
1221
+ * Get all registered language codes.
1222
+ */
1223
+ declare function getRegisteredLanguages(): string[];
1224
+ /**
1225
+ * Check if a language is registered (exact match or base language fallback).
1226
+ */
1227
+ declare function isLanguageRegistered(code: string): boolean;
1228
+ /**
1229
+ * Check if a language is supported (exact match or base language fallback).
1230
+ * For backwards compatibility with tokenizers API.
1231
+ */
1232
+ declare function isLanguageSupported(code: string): boolean;
1233
+ /**
1234
+ * Get patterns for a specific language.
1235
+ * First checks for directly registered patterns (for tree-shaking),
1236
+ * then falls back to pattern generator.
1237
+ * Supports fallback: if 'es-MX' is not registered, falls back to 'es'.
1238
+ * @throws Error if language is not registered
1239
+ */
1240
+ declare function getPatternsForLanguage(code: string): LanguagePattern[];
1241
+ /**
1242
+ * Get patterns for a specific language and command.
1243
+ */
1244
+ declare function getPatternsForLanguageAndCommand(language: string, command: string): LanguagePattern[];
1245
+
1246
+ export { ASTBuilder, type ASTBuilderOptions, type ASTNode, type ActionType, type BlockNode, type BuildASTResult, type CacheStats, type CommandMapper, type CommandMapperResult, type CommandNode, type CommandSemanticNode, type CommandSequenceNode, type CompoundSemanticNode, type ConditionalNode, type ConditionalSemanticNode, DEFAULT_CONFIDENCE_THRESHOLD, type EventHandlerNode, type EventHandlerSemanticNode, HIGH_CONFIDENCE_THRESHOLD, type KeywordTranslation, type LanguagePattern, type LanguageProfile, type LanguageToken, type LanguageTokenizer, type LoopSemanticNode, type MarkingStrategy, type PatternMatchResult, type PossessiveConfig, type RoleMarker, type SemanticAnalysisResult, type SemanticAnalyzer, SemanticAnalyzerImpl, type SemanticAnalyzerOptions, SemanticCache, type SemanticCacheConfig, type SemanticMetadata, type SemanticNode, type SemanticRole, type SemanticValue, type TokenKind, type TokenStream, type TokenizationConfig, type VerbConfig, type WordOrder, buildAST, convertExpression, convertLiteral, convertPropertyPath, convertReference, convertSelector, convertValue, createCommandNode, createEventHandler, createLiteral, createPropertyPath, createReference, createSelector, createSemanticAnalyzer, createSemanticCache, getCommandMapper, getPatternsForLanguage, getPatternsForLanguageAndCommand, getProfile, getRegisteredLanguages, getRegisteredMappers, getTokenizer, isLanguageRegistered, isLanguageSupported, mergeProfiles, registerCommandMapper, registerLanguage, registerPatterns, rolesToCommandArgs, semanticCache, setPatternGenerator, shouldUseSemanticResult, tryGetProfile, withCache };