@lokascript/framework 4.5.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +220 -8
- package/dist/api/create-dsl.d.ts +59 -1
- package/dist/api/create-dsl.d.ts.map +1 -1
- package/dist/api/domain-registry.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1938 -724
- package/dist/api/index.js.map +1 -1
- package/dist/api/reading.d.ts +8 -0
- package/dist/api/reading.d.ts.map +1 -0
- package/dist/api/translation-loss.d.ts +84 -0
- package/dist/api/translation-loss.d.ts.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1047 -684
- package/dist/core/index.js.map +1 -1
- package/dist/core/matching/confidence-model.d.ts +54 -0
- package/dist/core/matching/confidence-model.d.ts.map +1 -0
- package/dist/core/matching/index.d.ts +12 -0
- package/dist/core/matching/index.d.ts.map +1 -0
- package/dist/core/matching/match-skeleton.d.ts +114 -0
- package/dist/core/matching/match-skeleton.d.ts.map +1 -0
- package/dist/core/matching/stock-confidence.d.ts +15 -0
- package/dist/core/matching/stock-confidence.d.ts.map +1 -0
- package/dist/core/matching/stock-reader.d.ts +56 -0
- package/dist/core/matching/stock-reader.d.ts.map +1 -0
- package/dist/core/matching/stock-reading.d.ts +44 -0
- package/dist/core/matching/stock-reading.d.ts.map +1 -0
- package/dist/core/matching/value-reader.d.ts +62 -0
- package/dist/core/matching/value-reader.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.js +561 -660
- package/dist/core/pattern-matching/index.js.map +1 -1
- package/dist/core/pattern-matching/pattern-matcher.d.ts +0 -117
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
- package/dist/core/types.d.ts +48 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/generation/index.d.ts +2 -0
- package/dist/generation/index.d.ts.map +1 -1
- package/dist/generation/index.js +583 -1
- package/dist/generation/index.js.map +1 -1
- package/dist/generation/pattern-render.d.ts +72 -0
- package/dist/generation/pattern-render.d.ts.map +1 -0
- package/dist/generation/schema-patterns.d.ts +152 -0
- package/dist/generation/schema-patterns.d.ts.map +1 -0
- package/dist/index.cjs +2132 -890
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2110 -887
- package/dist/index.js.map +1 -1
- package/dist/ir/index.js.map +1 -1
- package/dist/parsing/index.js +561 -660
- package/dist/parsing/index.js.map +1 -1
- package/dist/testing/gate/index.d.ts +8 -0
- package/dist/testing/gate/index.d.ts.map +1 -0
- package/dist/testing/gate/index.js +632 -0
- package/dist/testing/gate/index.js.map +1 -0
- package/dist/testing/gate/lint/format.d.ts +7 -0
- package/dist/testing/gate/lint/format.d.ts.map +1 -0
- package/dist/testing/gate/lint/index.d.ts +30 -0
- package/dist/testing/gate/lint/index.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/extractor-coverage.d.ts +18 -0
- package/dist/testing/gate/lint/rules/extractor-coverage.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/index.d.ts +14 -0
- package/dist/testing/gate/lint/rules/index.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/keyword-classification.d.ts +19 -0
- package/dist/testing/gate/lint/rules/keyword-classification.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/keyword-coverage.d.ts +13 -0
- package/dist/testing/gate/lint/rules/keyword-coverage.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/marker-tokenization.d.ts +20 -0
- package/dist/testing/gate/lint/rules/marker-tokenization.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/position-ordering.d.ts +25 -0
- package/dist/testing/gate/lint/rules/position-ordering.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/renderer-coherence.d.ts +24 -0
- package/dist/testing/gate/lint/rules/renderer-coherence.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/schema-rules.d.ts +10 -0
- package/dist/testing/gate/lint/rules/schema-rules.d.ts.map +1 -0
- package/dist/testing/gate/lint/types.d.ts +74 -0
- package/dist/testing/gate/lint/types.d.ts.map +1 -0
- package/dist/testing/gate/round-trip.d.ts +163 -0
- package/dist/testing/gate/round-trip.d.ts.map +1 -0
- package/package.json +7 -3
- package/src/__test__/fixtures/sql-dsl.ts +11 -2
- package/src/__test__/sql-integration.test.ts +2 -2
- package/src/api/create-dsl-engine.test.ts +86 -0
- package/src/api/create-dsl.test.ts +120 -0
- package/src/api/create-dsl.ts +314 -39
- package/src/api/domain-registry.test.ts +70 -5
- package/src/api/domain-registry.ts +82 -1
- package/src/api/index.ts +1 -0
- package/src/api/reading.ts +29 -0
- package/src/api/translation-loss.test.ts +89 -0
- package/src/api/translation-loss.ts +128 -0
- package/src/core/index.ts +1 -0
- package/src/core/matching/confidence-model.ts +58 -0
- package/src/core/matching/index.ts +12 -0
- package/src/core/matching/match-skeleton.test.ts +179 -0
- package/src/core/matching/match-skeleton.ts +621 -0
- package/src/core/matching/stock-confidence.ts +238 -0
- package/src/core/matching/stock-reader.test.ts +181 -0
- package/src/core/matching/stock-reader.ts +186 -0
- package/src/core/matching/stock-reading.ts +681 -0
- package/src/core/matching/value-reader.ts +85 -0
- package/src/core/pattern-matching/pattern-matcher.ts +11 -876
- package/src/core/types.ts +48 -0
- package/src/generation/index.ts +2 -0
- package/src/generation/pattern-render.ts +378 -0
- package/src/generation/schema-patterns.test.ts +99 -0
- package/src/generation/schema-patterns.ts +962 -0
- package/src/testing/gate/index.ts +8 -0
- package/src/testing/gate/lint/format.ts +23 -0
- package/src/testing/gate/lint/index.ts +73 -0
- package/src/testing/gate/lint/lint.test.ts +131 -0
- package/src/testing/gate/lint/rules/extractor-coverage.ts +63 -0
- package/src/testing/gate/lint/rules/index.ts +37 -0
- package/src/testing/gate/lint/rules/keyword-classification.ts +52 -0
- package/src/testing/gate/lint/rules/keyword-coverage.ts +38 -0
- package/src/testing/gate/lint/rules/marker-tokenization.ts +129 -0
- package/src/testing/gate/lint/rules/position-ordering.ts +87 -0
- package/src/testing/gate/lint/rules/renderer-coherence.ts +100 -0
- package/src/testing/gate/lint/rules/schema-rules.ts +35 -0
- package/src/testing/gate/lint/types.ts +83 -0
- package/src/testing/gate/round-trip.test.ts +118 -0
- package/src/testing/gate/round-trip.ts +438 -0
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,8 @@ __export(index_exports, {
|
|
|
35
35
|
InMemoryDictionary: () => InMemoryDictionary,
|
|
36
36
|
InMemoryProfileProvider: () => InMemoryProfileProvider,
|
|
37
37
|
LatinExtendedIdentifierExtractor: () => LatinExtendedIdentifierExtractor,
|
|
38
|
+
LossyTranslationError: () => LossyTranslationError,
|
|
39
|
+
MatchSkeleton: () => MatchSkeleton,
|
|
38
40
|
NullDictionary: () => NullDictionary,
|
|
39
41
|
NullProfileProvider: () => NullProfileProvider,
|
|
40
42
|
NumberExtractor: () => NumberExtractor,
|
|
@@ -42,9 +44,12 @@ __export(index_exports, {
|
|
|
42
44
|
PatternMatcher: () => PatternMatcher,
|
|
43
45
|
PatternTracker: () => PatternTracker,
|
|
44
46
|
PunctuationExtractor: () => PunctuationExtractor,
|
|
47
|
+
StockValueReader: () => StockValueReader,
|
|
45
48
|
StringLiteralExtractor: () => StringLiteralExtractor,
|
|
46
49
|
TokenStreamImpl: () => TokenStreamImpl,
|
|
50
|
+
TranslationReadBackError: () => TranslationReadBackError,
|
|
47
51
|
UnicodeIdentifierExtractor: () => UnicodeIdentifierExtractor,
|
|
52
|
+
UnreadInputError: () => UnreadInputError,
|
|
48
53
|
WhitespaceExtractor: () => WhitespaceExtractor,
|
|
49
54
|
accumulateBlocks: () => accumulateBlocks,
|
|
50
55
|
buildDisambiguation: () => buildDisambiguation,
|
|
@@ -74,9 +79,11 @@ __export(index_exports, {
|
|
|
74
79
|
createPosition: () => createPosition,
|
|
75
80
|
createPropertyPath: () => import_intent.createPropertyPath,
|
|
76
81
|
createReference: () => import_intent.createReference,
|
|
82
|
+
createSchemaPatternGenerator: () => createSchemaPatternGenerator,
|
|
77
83
|
createSchemaRenderer: () => createSchemaRenderer,
|
|
78
84
|
createSelector: () => import_intent.createSelector,
|
|
79
85
|
createSimpleTokenizer: () => createSimpleTokenizer,
|
|
86
|
+
createStockReader: () => createStockReader,
|
|
80
87
|
createToken: () => createToken,
|
|
81
88
|
createTokenizerContext: () => createTokenizerContext,
|
|
82
89
|
createTryNode: () => import_intent.createTryNode,
|
|
@@ -92,6 +99,7 @@ __export(index_exports, {
|
|
|
92
99
|
extractUrl: () => extractUrl,
|
|
93
100
|
extractValue: () => import_intent.extractValue,
|
|
94
101
|
filterBySeverity: () => import_intent7.filterBySeverity,
|
|
102
|
+
findTranslationLoss: () => findTranslationLoss,
|
|
95
103
|
fromEnvelopeJSON: () => import_intent5.fromEnvelopeJSON,
|
|
96
104
|
fromError: () => import_intent7.fromError,
|
|
97
105
|
fromInterchangeNode: () => fromInterchangeNode,
|
|
@@ -106,6 +114,7 @@ __export(index_exports, {
|
|
|
106
114
|
getPossessiveReference: () => getPossessiveReference,
|
|
107
115
|
getRoleSpec: () => import_intent6.getRoleSpec,
|
|
108
116
|
getRoleValue: () => import_intent.getRoleValue,
|
|
117
|
+
greedyStopMarkers: () => greedyStopMarkers,
|
|
109
118
|
insertMarkers: () => insertMarkers,
|
|
110
119
|
isAsciiIdentifierChar: () => isAsciiIdentifierChar,
|
|
111
120
|
isAsciiLetter: () => isAsciiLetter,
|
|
@@ -133,6 +142,7 @@ __export(index_exports, {
|
|
|
133
142
|
isWhitespace: () => isWhitespace,
|
|
134
143
|
joinTokens: () => joinTokens,
|
|
135
144
|
jsonToSemanticNode: () => jsonToSemanticNode,
|
|
145
|
+
legacyMarkerAlternatives: () => legacyMarkerAlternatives,
|
|
136
146
|
lookupKeyword: () => lookupKeyword,
|
|
137
147
|
lookupMarker: () => lookupMarker,
|
|
138
148
|
matchBest: () => matchBest,
|
|
@@ -145,25 +155,34 @@ __export(index_exports, {
|
|
|
145
155
|
parseExplicit: () => import_intent3.parseExplicit,
|
|
146
156
|
parseJSONL: () => parseJSONL,
|
|
147
157
|
patternMatcher: () => patternMatcher,
|
|
158
|
+
readGreedy: () => readGreedy,
|
|
159
|
+
readRoleValue: () => readRoleValue,
|
|
148
160
|
registryToAOTBackends: () => registryToAOTBackends,
|
|
149
161
|
renderDocument: () => import_intent4.renderDocument,
|
|
150
162
|
renderExplicit: () => import_intent4.renderExplicit,
|
|
151
163
|
renderExpr: () => renderExpr,
|
|
164
|
+
renderPattern: () => renderPattern,
|
|
152
165
|
reorderRoles: () => reorderRoles,
|
|
166
|
+
resolveMarkerForRole: () => resolveMarkerForRole,
|
|
167
|
+
schemaMarkerAlternatives: () => schemaMarkerAlternatives,
|
|
168
|
+
selectRenderPattern: () => selectRenderPattern,
|
|
153
169
|
semanticNodeToJSON: () => semanticNodeToJSON,
|
|
154
170
|
semanticNodeToRuntimeAST: () => semanticNodeToRuntimeAST,
|
|
155
171
|
semanticValueToAST: () => semanticValueToAST,
|
|
156
172
|
sortRolesByWordOrder: () => sortRolesByWordOrder,
|
|
173
|
+
stockConfidenceModel: () => stockConfidenceModel,
|
|
157
174
|
stripOptionalDiacritics: () => stripOptionalDiacritics,
|
|
158
175
|
synthesizeFromSchemas: () => synthesizeFromSchemas,
|
|
159
176
|
toEnvelopeJSON: () => import_intent5.toEnvelopeJSON,
|
|
160
177
|
toJSONL: () => toJSONL,
|
|
161
178
|
toJSONLRow: () => toJSONLRow,
|
|
162
179
|
toProtocolJSON: () => import_intent5.toProtocolJSON,
|
|
180
|
+
unconsumedSpans: () => unconsumedSpans,
|
|
163
181
|
validateProtocolJSON: () => import_intent5.validateProtocolJSON,
|
|
164
182
|
validateSemanticJSON: () => validateSemanticJSON,
|
|
165
183
|
validateValueType: () => validateValueType,
|
|
166
|
-
withDefaultExtractors: () => withDefaultExtractors
|
|
184
|
+
withDefaultExtractors: () => withDefaultExtractors,
|
|
185
|
+
withoutVariantOnlyRoles: () => withoutVariantOnlyRoles
|
|
167
186
|
});
|
|
168
187
|
module.exports = __toCommonJS(index_exports);
|
|
169
188
|
|
|
@@ -301,10 +320,535 @@ function getAllPossessiveKeywords(profile) {
|
|
|
301
320
|
return profile?.possessive?.keywords ?? {};
|
|
302
321
|
}
|
|
303
322
|
|
|
304
|
-
// src/core/
|
|
323
|
+
// src/core/matching/stock-reading.ts
|
|
305
324
|
function isValidReference(_value) {
|
|
306
325
|
return false;
|
|
307
326
|
}
|
|
327
|
+
function safeToLowerCase(value) {
|
|
328
|
+
if (typeof value === "string") {
|
|
329
|
+
return value.toLowerCase();
|
|
330
|
+
}
|
|
331
|
+
if (value === null || value === void 0) {
|
|
332
|
+
return "";
|
|
333
|
+
}
|
|
334
|
+
return String(value).toLowerCase();
|
|
335
|
+
}
|
|
336
|
+
function readRoleValue(tokens, patternToken, captured, profile) {
|
|
337
|
+
skipNoiseWords(tokens);
|
|
338
|
+
const token = tokens.peek();
|
|
339
|
+
if (!token) {
|
|
340
|
+
return patternToken.optional || false;
|
|
341
|
+
}
|
|
342
|
+
const possessiveValue = tryMatchPossessiveExpression(tokens, profile);
|
|
343
|
+
if (possessiveValue) {
|
|
344
|
+
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
345
|
+
if (!isTypeCompatible(possessiveValue.type, patternToken.expectedTypes)) {
|
|
346
|
+
return patternToken.optional || false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
captured.set(patternToken.role, possessiveValue);
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
const methodCallValue = tryMatchMethodCallExpression(tokens);
|
|
353
|
+
if (methodCallValue) {
|
|
354
|
+
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
355
|
+
if (!isTypeCompatible(methodCallValue.type, patternToken.expectedTypes)) {
|
|
356
|
+
return patternToken.optional || false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
captured.set(patternToken.role, methodCallValue);
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
const possessiveSelectorValue = tryMatchPossessiveSelectorExpression(tokens);
|
|
363
|
+
if (possessiveSelectorValue) {
|
|
364
|
+
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
365
|
+
if (!isTypeCompatible(possessiveSelectorValue.type, patternToken.expectedTypes)) {
|
|
366
|
+
return patternToken.optional || false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
captured.set(patternToken.role, possessiveSelectorValue);
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
const propertyAccessValue = tryMatchPropertyAccessExpression(tokens);
|
|
373
|
+
if (propertyAccessValue) {
|
|
374
|
+
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
375
|
+
if (!isTypeCompatible(propertyAccessValue.type, patternToken.expectedTypes)) {
|
|
376
|
+
return patternToken.optional || false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
captured.set(patternToken.role, propertyAccessValue);
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
const selectorPropertyValue = tryMatchSelectorPropertyExpression(tokens);
|
|
383
|
+
if (selectorPropertyValue) {
|
|
384
|
+
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
385
|
+
if (!isTypeCompatible(selectorPropertyValue.type, patternToken.expectedTypes)) {
|
|
386
|
+
return patternToken.optional || false;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
captured.set(patternToken.role, selectorPropertyValue);
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
const value = tokenToSemanticValue(token);
|
|
393
|
+
if (!value) {
|
|
394
|
+
return patternToken.optional || false;
|
|
395
|
+
}
|
|
396
|
+
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
397
|
+
if (!isTypeCompatible(value.type, patternToken.expectedTypes)) {
|
|
398
|
+
return patternToken.optional || false;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
captured.set(patternToken.role, value);
|
|
402
|
+
tokens.advance();
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
function tryMatchPossessiveExpression(tokens, profile) {
|
|
406
|
+
const token = tokens.peek();
|
|
407
|
+
if (!token) return null;
|
|
408
|
+
if (!profile) return null;
|
|
409
|
+
const tokenValue = token.normalized || token.value;
|
|
410
|
+
const tokenLower = safeToLowerCase(tokenValue);
|
|
411
|
+
const baseRef = getPossessiveReference(profile, tokenLower);
|
|
412
|
+
if (!baseRef) return null;
|
|
413
|
+
const mark = tokens.mark();
|
|
414
|
+
tokens.advance();
|
|
415
|
+
const propertyToken = tokens.peek();
|
|
416
|
+
if (!propertyToken) {
|
|
417
|
+
tokens.reset(mark);
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
if (propertyToken.kind === "identifier" || propertyToken.kind === "keyword" && !isStructuralKeyword(propertyToken.value) || propertyToken.kind === "selector" && propertyToken.value.startsWith("*") || propertyToken.kind === "selector" && propertyToken.value.startsWith("@") || propertyToken.kind === "selector" && propertyToken.value.startsWith(".") && /^\.[a-zA-Z_]\w*/.test(propertyToken.value)) {
|
|
421
|
+
tokens.advance();
|
|
422
|
+
let propertyName = propertyToken.value;
|
|
423
|
+
if (propertyToken.kind === "selector" && propertyName.startsWith(".") && /^\.[a-zA-Z_]\w*/.test(propertyName)) {
|
|
424
|
+
propertyName = propertyName.substring(1);
|
|
425
|
+
}
|
|
426
|
+
let chainedProps = propertyName;
|
|
427
|
+
while (tokens.peek()?.kind === "selector" && tokens.peek().value.startsWith(".") && /^\.[a-zA-Z_]\w*/.test(tokens.peek().value)) {
|
|
428
|
+
chainedProps += tokens.peek().value;
|
|
429
|
+
tokens.advance();
|
|
430
|
+
}
|
|
431
|
+
const nextPeek = tokens.peek();
|
|
432
|
+
if (nextPeek?.kind === "literal" && nextPeek.value.startsWith("(")) {
|
|
433
|
+
chainedProps += nextPeek.value;
|
|
434
|
+
tokens.advance();
|
|
435
|
+
}
|
|
436
|
+
return (0, import_intent.createPropertyPath)((0, import_intent.createReference)(baseRef), chainedProps);
|
|
437
|
+
}
|
|
438
|
+
tokens.reset(mark);
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
function isStructuralKeyword(value) {
|
|
442
|
+
const structural = /* @__PURE__ */ new Set([
|
|
443
|
+
// Prepositions
|
|
444
|
+
"into",
|
|
445
|
+
"in",
|
|
446
|
+
"to",
|
|
447
|
+
"from",
|
|
448
|
+
"at",
|
|
449
|
+
"by",
|
|
450
|
+
"with",
|
|
451
|
+
"without",
|
|
452
|
+
"before",
|
|
453
|
+
"after",
|
|
454
|
+
"of",
|
|
455
|
+
"as",
|
|
456
|
+
"on",
|
|
457
|
+
// Control flow
|
|
458
|
+
"then",
|
|
459
|
+
"end",
|
|
460
|
+
"else",
|
|
461
|
+
"if",
|
|
462
|
+
"repeat",
|
|
463
|
+
"while",
|
|
464
|
+
"for",
|
|
465
|
+
// Commands (shouldn't be property names)
|
|
466
|
+
"toggle",
|
|
467
|
+
"add",
|
|
468
|
+
"remove",
|
|
469
|
+
"put",
|
|
470
|
+
"set",
|
|
471
|
+
"show",
|
|
472
|
+
"hide",
|
|
473
|
+
"increment",
|
|
474
|
+
"decrement",
|
|
475
|
+
"send",
|
|
476
|
+
"trigger",
|
|
477
|
+
"call"
|
|
478
|
+
]);
|
|
479
|
+
return structural.has(value.toLowerCase());
|
|
480
|
+
}
|
|
481
|
+
function tryMatchMethodCallExpression(tokens) {
|
|
482
|
+
const token = tokens.peek();
|
|
483
|
+
if (!token || token.kind !== "selector") return null;
|
|
484
|
+
const mark = tokens.mark();
|
|
485
|
+
tokens.advance();
|
|
486
|
+
const dotToken = tokens.peek();
|
|
487
|
+
if (!dotToken || dotToken.kind !== "operator" || dotToken.value !== ".") {
|
|
488
|
+
tokens.reset(mark);
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
tokens.advance();
|
|
492
|
+
const methodToken = tokens.peek();
|
|
493
|
+
if (!methodToken || methodToken.kind !== "identifier") {
|
|
494
|
+
tokens.reset(mark);
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
tokens.advance();
|
|
498
|
+
const openParen = tokens.peek();
|
|
499
|
+
if (!openParen || openParen.kind !== "punctuation" || openParen.value !== "(") {
|
|
500
|
+
tokens.reset(mark);
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
tokens.advance();
|
|
504
|
+
const args = [];
|
|
505
|
+
while (!tokens.isAtEnd() && args.length < MAX_METHOD_ARGS) {
|
|
506
|
+
const argToken = tokens.peek();
|
|
507
|
+
if (!argToken) break;
|
|
508
|
+
if (argToken.kind === "punctuation" && argToken.value === ")") {
|
|
509
|
+
tokens.advance();
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
if (argToken.kind === "punctuation" && argToken.value === ",") {
|
|
513
|
+
tokens.advance();
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
args.push(argToken.value);
|
|
517
|
+
tokens.advance();
|
|
518
|
+
}
|
|
519
|
+
const methodCall = `${token.value}.${methodToken.value}(${args.join(", ")})`;
|
|
520
|
+
return {
|
|
521
|
+
type: "expression",
|
|
522
|
+
raw: methodCall
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
function tryMatchPropertyAccessExpression(tokens) {
|
|
526
|
+
const token = tokens.peek();
|
|
527
|
+
if (!token) return null;
|
|
528
|
+
if (token.kind !== "identifier" && token.kind !== "keyword") return null;
|
|
529
|
+
const mark = tokens.mark();
|
|
530
|
+
tokens.advance();
|
|
531
|
+
const dotToken = tokens.peek();
|
|
532
|
+
if (!dotToken || dotToken.kind !== "operator" || dotToken.value !== ".") {
|
|
533
|
+
tokens.reset(mark);
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
tokens.advance();
|
|
537
|
+
const propertyToken = tokens.peek();
|
|
538
|
+
if (!propertyToken || propertyToken.kind !== "identifier") {
|
|
539
|
+
tokens.reset(mark);
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
tokens.advance();
|
|
543
|
+
let chain = `${token.value}.${propertyToken.value}`;
|
|
544
|
+
let depth = 1;
|
|
545
|
+
while (!tokens.isAtEnd() && depth < MAX_PROPERTY_DEPTH) {
|
|
546
|
+
const nextDot = tokens.peek();
|
|
547
|
+
if (!nextDot || nextDot.kind !== "operator" || nextDot.value !== ".") {
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
tokens.advance();
|
|
551
|
+
const nextProp = tokens.peek();
|
|
552
|
+
if (!nextProp || nextProp.kind !== "identifier") {
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
tokens.advance();
|
|
556
|
+
chain += `.${nextProp.value}`;
|
|
557
|
+
depth++;
|
|
558
|
+
}
|
|
559
|
+
const openParen = tokens.peek();
|
|
560
|
+
if (openParen && openParen.kind === "punctuation" && openParen.value === "(") {
|
|
561
|
+
tokens.advance();
|
|
562
|
+
const args = [];
|
|
563
|
+
let argDepth = 0;
|
|
564
|
+
while (!tokens.isAtEnd() && args.length < MAX_METHOD_ARGS) {
|
|
565
|
+
const argToken = tokens.peek();
|
|
566
|
+
if (!argToken) break;
|
|
567
|
+
if (argToken.kind === "punctuation" && argToken.value === ")") {
|
|
568
|
+
if (argDepth === 0) {
|
|
569
|
+
tokens.advance();
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
argDepth--;
|
|
573
|
+
}
|
|
574
|
+
if (argToken.kind === "punctuation" && argToken.value === "(") {
|
|
575
|
+
argDepth++;
|
|
576
|
+
}
|
|
577
|
+
if (argToken.kind === "punctuation" && argToken.value === ",") {
|
|
578
|
+
tokens.advance();
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
args.push(argToken.value);
|
|
582
|
+
tokens.advance();
|
|
583
|
+
}
|
|
584
|
+
const methodCall = `${chain}(${args.join(", ")})`;
|
|
585
|
+
return {
|
|
586
|
+
type: "expression",
|
|
587
|
+
raw: methodCall
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
return {
|
|
591
|
+
type: "expression",
|
|
592
|
+
raw: chain
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function tryMatchPossessiveSelectorExpression(tokens) {
|
|
596
|
+
const token = tokens.peek();
|
|
597
|
+
if (!token || token.kind !== "selector") return null;
|
|
598
|
+
const mark = tokens.mark();
|
|
599
|
+
tokens.advance();
|
|
600
|
+
const possessiveToken = tokens.peek();
|
|
601
|
+
if (!possessiveToken || possessiveToken.kind !== "punctuation" || possessiveToken.value !== "'s") {
|
|
602
|
+
tokens.reset(mark);
|
|
603
|
+
return null;
|
|
604
|
+
}
|
|
605
|
+
tokens.advance();
|
|
606
|
+
const propertyToken = tokens.peek();
|
|
607
|
+
if (!propertyToken) {
|
|
608
|
+
tokens.reset(mark);
|
|
609
|
+
return null;
|
|
610
|
+
}
|
|
611
|
+
if (propertyToken.kind !== "selector" && propertyToken.kind !== "identifier") {
|
|
612
|
+
tokens.reset(mark);
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
tokens.advance();
|
|
616
|
+
return (0, import_intent.createPropertyPath)((0, import_intent.createSelector)(token.value), propertyToken.value);
|
|
617
|
+
}
|
|
618
|
+
function tryMatchSelectorPropertyExpression(tokens) {
|
|
619
|
+
const token = tokens.peek();
|
|
620
|
+
if (!token || token.kind !== "selector") return null;
|
|
621
|
+
if (typeof token.value !== "string" || !token.value.startsWith("#")) return null;
|
|
622
|
+
const mark = tokens.mark();
|
|
623
|
+
tokens.advance();
|
|
624
|
+
const propertyToken = tokens.peek();
|
|
625
|
+
if (!propertyToken || propertyToken.kind !== "selector") {
|
|
626
|
+
tokens.reset(mark);
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
if (!propertyToken.value.startsWith(".")) {
|
|
630
|
+
tokens.reset(mark);
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
const peek2 = tokens.peek(1);
|
|
634
|
+
if (peek2 && peek2.kind === "selector") {
|
|
635
|
+
}
|
|
636
|
+
tokens.advance();
|
|
637
|
+
const propertyName = propertyToken.value.slice(1);
|
|
638
|
+
return (0, import_intent.createPropertyPath)((0, import_intent.createSelector)(token.value), propertyName);
|
|
639
|
+
}
|
|
640
|
+
var MAX_PROPERTY_DEPTH = 10;
|
|
641
|
+
var MAX_METHOD_ARGS = 20;
|
|
642
|
+
function tokenToSemanticValue(token) {
|
|
643
|
+
switch (token.kind) {
|
|
644
|
+
case "selector":
|
|
645
|
+
return (0, import_intent.createSelector)(token.value);
|
|
646
|
+
case "literal":
|
|
647
|
+
return parseLiteralValue(token.value);
|
|
648
|
+
case "keyword": {
|
|
649
|
+
const tokenValue = token.normalized || token.value;
|
|
650
|
+
const lower = safeToLowerCase(tokenValue);
|
|
651
|
+
if (isValidReference(lower)) {
|
|
652
|
+
return (0, import_intent.createReference)(lower);
|
|
653
|
+
}
|
|
654
|
+
return (0, import_intent.createLiteral)(token.normalized || token.value);
|
|
655
|
+
}
|
|
656
|
+
case "identifier": {
|
|
657
|
+
if (typeof token.value === "string" && token.value.startsWith(":")) {
|
|
658
|
+
return (0, import_intent.createReference)(token.value);
|
|
659
|
+
}
|
|
660
|
+
const identLower = safeToLowerCase(token.value);
|
|
661
|
+
if (isValidReference(identLower)) {
|
|
662
|
+
return (0, import_intent.createReference)(identLower);
|
|
663
|
+
}
|
|
664
|
+
return { type: "expression", raw: token.value };
|
|
665
|
+
}
|
|
666
|
+
case "url":
|
|
667
|
+
return (0, import_intent.createLiteral)(token.value, "string");
|
|
668
|
+
default:
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
function parseLiteralValue(value) {
|
|
673
|
+
if (value.startsWith('"') || value.startsWith("'") || value.startsWith("`") || value.startsWith("\u300C")) {
|
|
674
|
+
const inner = value.slice(1, -1);
|
|
675
|
+
return (0, import_intent.createLiteral)(inner, "string");
|
|
676
|
+
}
|
|
677
|
+
if (value === "true") return (0, import_intent.createLiteral)(true, "boolean");
|
|
678
|
+
if (value === "false") return (0, import_intent.createLiteral)(false, "boolean");
|
|
679
|
+
const durationMatch = value.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);
|
|
680
|
+
if (durationMatch) {
|
|
681
|
+
const num2 = parseFloat(durationMatch[1]);
|
|
682
|
+
const unit = durationMatch[2];
|
|
683
|
+
if (unit) {
|
|
684
|
+
return (0, import_intent.createLiteral)(value, "duration");
|
|
685
|
+
}
|
|
686
|
+
return (0, import_intent.createLiteral)(num2, "number");
|
|
687
|
+
}
|
|
688
|
+
const num = parseFloat(value);
|
|
689
|
+
if (!isNaN(num)) {
|
|
690
|
+
return (0, import_intent.createLiteral)(num, "number");
|
|
691
|
+
}
|
|
692
|
+
return (0, import_intent.createLiteral)(value, "string");
|
|
693
|
+
}
|
|
694
|
+
var ENGLISH_NOISE_WORDS = /* @__PURE__ */ new Set(["the", "a", "an"]);
|
|
695
|
+
function skipNoiseWords(tokens) {
|
|
696
|
+
const token = tokens.peek();
|
|
697
|
+
if (!token) return;
|
|
698
|
+
const tokenLower = safeToLowerCase(token.value);
|
|
699
|
+
if (ENGLISH_NOISE_WORDS.has(tokenLower)) {
|
|
700
|
+
const mark = tokens.mark();
|
|
701
|
+
tokens.advance();
|
|
702
|
+
const nextToken = tokens.peek();
|
|
703
|
+
if (nextToken && nextToken.kind === "selector") {
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
tokens.reset(mark);
|
|
707
|
+
}
|
|
708
|
+
if (tokenLower === "class") {
|
|
709
|
+
tokens.advance();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// src/core/matching/stock-confidence.ts
|
|
714
|
+
function scoreParts(ctx) {
|
|
715
|
+
const { pattern, captured } = ctx;
|
|
716
|
+
let score = 0;
|
|
717
|
+
let maxScore = 0;
|
|
718
|
+
const hasDefault = (role) => {
|
|
719
|
+
return pattern.extraction?.[role]?.default !== void 0;
|
|
720
|
+
};
|
|
721
|
+
for (const token of pattern.template.tokens) {
|
|
722
|
+
if (token.type === "role") {
|
|
723
|
+
maxScore += 1;
|
|
724
|
+
if (captured.has(token.role)) {
|
|
725
|
+
score += 1;
|
|
726
|
+
}
|
|
727
|
+
} else if (token.type === "group") {
|
|
728
|
+
for (const subToken of token.tokens) {
|
|
729
|
+
if (subToken.type === "role") {
|
|
730
|
+
const roleHasDefault = hasDefault(subToken.role);
|
|
731
|
+
const weight = 0.8;
|
|
732
|
+
maxScore += weight;
|
|
733
|
+
if (captured.has(subToken.role)) {
|
|
734
|
+
score += weight;
|
|
735
|
+
} else if (roleHasDefault) {
|
|
736
|
+
score += weight * 0.6;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
const roleCoverage = maxScore > 0 ? score / maxScore : 1;
|
|
743
|
+
let baseConfidence = roleCoverage;
|
|
744
|
+
let stemPenalty = 0;
|
|
745
|
+
if (ctx.stemMatchCount > 0 && ctx.totalKeywordMatches > 0) {
|
|
746
|
+
stemPenalty = ctx.stemMatchCount / ctx.totalKeywordMatches * 0.15;
|
|
747
|
+
baseConfidence = Math.max(0.5, baseConfidence - stemPenalty);
|
|
748
|
+
}
|
|
749
|
+
const vsoBoost = calculateVSOConfidenceBoost(pattern);
|
|
750
|
+
baseConfidence = Math.min(1, baseConfidence + vsoBoost);
|
|
751
|
+
const prepositionAdjustment = arabicPrepositionDisambiguation(pattern, captured);
|
|
752
|
+
baseConfidence = Math.max(0, Math.min(1, baseConfidence + prepositionAdjustment));
|
|
753
|
+
return {
|
|
754
|
+
roleCoverage,
|
|
755
|
+
stemPenalty,
|
|
756
|
+
languageBoost: vsoBoost,
|
|
757
|
+
languageAdjustment: prepositionAdjustment,
|
|
758
|
+
final: baseConfidence
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
function calculateVSOConfidenceBoost(pattern) {
|
|
762
|
+
if (pattern.language !== "ar") {
|
|
763
|
+
return 0;
|
|
764
|
+
}
|
|
765
|
+
const firstToken = pattern.template.tokens[0];
|
|
766
|
+
if (!firstToken || firstToken.type !== "literal") {
|
|
767
|
+
return 0;
|
|
768
|
+
}
|
|
769
|
+
const ARABIC_VERBS = /* @__PURE__ */ new Set([
|
|
770
|
+
"\u0628\u062F\u0644",
|
|
771
|
+
"\u063A\u064A\u0631",
|
|
772
|
+
"\u0623\u0636\u0641",
|
|
773
|
+
"\u0623\u0632\u0644",
|
|
774
|
+
"\u0636\u0639",
|
|
775
|
+
"\u0627\u062C\u0639\u0644",
|
|
776
|
+
"\u0639\u064A\u0646",
|
|
777
|
+
"\u0632\u062F",
|
|
778
|
+
"\u0627\u0646\u0642\u0635",
|
|
779
|
+
"\u0633\u062C\u0644",
|
|
780
|
+
"\u0623\u0638\u0647\u0631",
|
|
781
|
+
"\u0623\u062E\u0641",
|
|
782
|
+
"\u0634\u063A\u0644",
|
|
783
|
+
"\u0623\u0631\u0633\u0644",
|
|
784
|
+
"\u0631\u0643\u0632",
|
|
785
|
+
"\u0634\u0648\u0634",
|
|
786
|
+
"\u062A\u0648\u0642\u0641",
|
|
787
|
+
"\u0627\u0646\u0633\u062E",
|
|
788
|
+
"\u0627\u062D\u0630\u0641",
|
|
789
|
+
"\u0627\u0635\u0646\u0639",
|
|
790
|
+
"\u0627\u0646\u062A\u0638\u0631",
|
|
791
|
+
"\u0627\u0646\u062A\u0642\u0627\u0644",
|
|
792
|
+
"\u0623\u0648"
|
|
793
|
+
]);
|
|
794
|
+
if (ARABIC_VERBS.has(firstToken.value)) {
|
|
795
|
+
return 0.15;
|
|
796
|
+
}
|
|
797
|
+
if (firstToken.alternatives) {
|
|
798
|
+
for (const alt of firstToken.alternatives) {
|
|
799
|
+
if (ARABIC_VERBS.has(alt)) {
|
|
800
|
+
return 0.15;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return 0;
|
|
805
|
+
}
|
|
806
|
+
function arabicPrepositionDisambiguation(pattern, captured) {
|
|
807
|
+
if (pattern.language !== "ar") {
|
|
808
|
+
return 0;
|
|
809
|
+
}
|
|
810
|
+
let adjustment = 0;
|
|
811
|
+
const PREFERRED_PREPOSITIONS = {
|
|
812
|
+
patient: ["\u0639\u0644\u0649"],
|
|
813
|
+
// element selectors prefer على (on/upon)
|
|
814
|
+
destination: ["\u0625\u0644\u0649", "\u0627\u0644\u0649"],
|
|
815
|
+
// destination prefers إلى (to)
|
|
816
|
+
source: ["\u0645\u0646"],
|
|
817
|
+
// source prefers من (from)
|
|
818
|
+
agent: ["\u0645\u0646"],
|
|
819
|
+
// agent/by prefers من (from/by)
|
|
820
|
+
manner: ["\u0628"],
|
|
821
|
+
// manner prefers ب (with/by)
|
|
822
|
+
style: ["\u0628"],
|
|
823
|
+
// style prefers ب (with)
|
|
824
|
+
goal: ["\u0625\u0644\u0649", "\u0627\u0644\u0649"],
|
|
825
|
+
// target state prefers إلى (to)
|
|
826
|
+
method: ["\u0628"]
|
|
827
|
+
// method prefers ب (with/by)
|
|
828
|
+
};
|
|
829
|
+
for (const [role, value] of captured.entries()) {
|
|
830
|
+
const preferred = PREFERRED_PREPOSITIONS[role];
|
|
831
|
+
if (!preferred || preferred.length === 0) {
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
const metadata = "metadata" in value ? value.metadata : void 0;
|
|
835
|
+
if (metadata && typeof metadata.prepositionValue === "string") {
|
|
836
|
+
const usedPreposition = metadata.prepositionValue;
|
|
837
|
+
if (preferred.includes(usedPreposition)) {
|
|
838
|
+
adjustment += 0.1;
|
|
839
|
+
} else {
|
|
840
|
+
adjustment -= 0.1;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return Math.max(-0.1, Math.min(0.1, adjustment));
|
|
845
|
+
}
|
|
846
|
+
var stockConfidenceModel = {
|
|
847
|
+
calculate: (ctx) => scoreParts(ctx).final,
|
|
848
|
+
calculateWithBreakdown: (ctx) => scoreParts(ctx)
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// src/core/pattern-matching/pattern-matcher.ts
|
|
308
852
|
var _PatternMatcher = class _PatternMatcher {
|
|
309
853
|
constructor() {
|
|
310
854
|
/** Debug logger */
|
|
@@ -316,19 +860,6 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
316
860
|
this.stemMatchCount = 0;
|
|
317
861
|
this.totalKeywordMatches = 0;
|
|
318
862
|
}
|
|
319
|
-
/**
|
|
320
|
-
* Safely convert a value to lowercase string.
|
|
321
|
-
* Provides protection against non-string values at runtime.
|
|
322
|
-
*/
|
|
323
|
-
safeToLowerCase(value) {
|
|
324
|
-
if (typeof value === "string") {
|
|
325
|
-
return value.toLowerCase();
|
|
326
|
-
}
|
|
327
|
-
if (value === null || value === void 0) {
|
|
328
|
-
return "";
|
|
329
|
-
}
|
|
330
|
-
return String(value).toLowerCase();
|
|
331
|
-
}
|
|
332
863
|
/**
|
|
333
864
|
* Try to match a single pattern against the token stream.
|
|
334
865
|
* Returns the match result or null if no match.
|
|
@@ -377,7 +908,12 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
377
908
|
tokens.reset(mark);
|
|
378
909
|
return null;
|
|
379
910
|
}
|
|
380
|
-
const confidence =
|
|
911
|
+
const confidence = stockConfidenceModel.calculate({
|
|
912
|
+
pattern,
|
|
913
|
+
captured,
|
|
914
|
+
stemMatchCount: this.stemMatchCount,
|
|
915
|
+
totalKeywordMatches: this.totalKeywordMatches
|
|
916
|
+
});
|
|
381
917
|
this.applyExtractionRules(pattern, captured);
|
|
382
918
|
return {
|
|
383
919
|
pattern,
|
|
@@ -562,7 +1098,7 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
562
1098
|
case "literal":
|
|
563
1099
|
return this.matchLiteralToken(tokens, patternToken);
|
|
564
1100
|
case "role":
|
|
565
|
-
return
|
|
1101
|
+
return readRoleValue(tokens, patternToken, captured, this.currentProfile);
|
|
566
1102
|
case "group":
|
|
567
1103
|
return this.matchGroupToken(tokens, patternToken, captured);
|
|
568
1104
|
default:
|
|
@@ -620,420 +1156,54 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
620
1156
|
return false;
|
|
621
1157
|
}
|
|
622
1158
|
/**
|
|
623
|
-
* Match a
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
1159
|
+
* Match a group pattern token (optional sequence).
|
|
1160
|
+
* When the group's leading marker isn't at the current position, scans ahead
|
|
1161
|
+
* up to MAX_MARKER_SCAN tokens to find it. This allows unmarked tokens
|
|
1162
|
+
* (e.g., a value like 'hello') to sit between groups without blocking later
|
|
1163
|
+
* marker matches.
|
|
628
1164
|
*/
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
token ? JSON.stringify({ value: token.value, kind: token.kind }) : "null"
|
|
1165
|
+
matchGroupToken(tokens, patternToken, captured, parentStopMarkers) {
|
|
1166
|
+
const mark = tokens.mark();
|
|
1167
|
+
const capturedBefore = new Set(captured.keys());
|
|
1168
|
+
const success = this.matchTokenSequence(
|
|
1169
|
+
tokens,
|
|
1170
|
+
patternToken.tokens,
|
|
1171
|
+
captured,
|
|
1172
|
+
parentStopMarkers
|
|
638
1173
|
);
|
|
639
|
-
if (
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
if (possessiveValue) {
|
|
644
|
-
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
645
|
-
if (!isTypeCompatible(possessiveValue.type, patternToken.expectedTypes)) {
|
|
646
|
-
return patternToken.optional || false;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
captured.set(patternToken.role, possessiveValue);
|
|
650
|
-
return true;
|
|
651
|
-
}
|
|
652
|
-
const methodCallValue = this.tryMatchMethodCallExpression(tokens);
|
|
653
|
-
if (methodCallValue) {
|
|
654
|
-
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
655
|
-
if (!isTypeCompatible(methodCallValue.type, patternToken.expectedTypes)) {
|
|
656
|
-
return patternToken.optional || false;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
captured.set(patternToken.role, methodCallValue);
|
|
660
|
-
return true;
|
|
661
|
-
}
|
|
662
|
-
const possessiveSelectorValue = this.tryMatchPossessiveSelectorExpression(tokens);
|
|
663
|
-
if (possessiveSelectorValue) {
|
|
664
|
-
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
665
|
-
if (!isTypeCompatible(possessiveSelectorValue.type, patternToken.expectedTypes)) {
|
|
666
|
-
return patternToken.optional || false;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
captured.set(patternToken.role, possessiveSelectorValue);
|
|
670
|
-
return true;
|
|
671
|
-
}
|
|
672
|
-
const propertyAccessValue = this.tryMatchPropertyAccessExpression(tokens);
|
|
673
|
-
if (propertyAccessValue) {
|
|
674
|
-
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
675
|
-
if (!isTypeCompatible(propertyAccessValue.type, patternToken.expectedTypes)) {
|
|
676
|
-
return patternToken.optional || false;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
captured.set(patternToken.role, propertyAccessValue);
|
|
680
|
-
return true;
|
|
1174
|
+
if (success) return true;
|
|
1175
|
+
tokens.reset(mark);
|
|
1176
|
+
for (const role of captured.keys()) {
|
|
1177
|
+
if (!capturedBefore.has(role)) captured.delete(role);
|
|
681
1178
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
|
|
711
|
-
if (!isTypeCompatible(value.type, patternToken.expectedTypes)) {
|
|
712
|
-
this.logger.debug(" >>> TYPE MISMATCH - returning", patternToken.optional || false);
|
|
713
|
-
return patternToken.optional || false;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
this.logger.debug(" >>> Type validation PASSED");
|
|
717
|
-
captured.set(patternToken.role, value);
|
|
718
|
-
tokens.advance();
|
|
719
|
-
return true;
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Try to match a possessive expression like 'my value' or 'its innerHTML'.
|
|
723
|
-
* Returns the PropertyPathValue if matched, or null if not.
|
|
724
|
-
*/
|
|
725
|
-
tryMatchPossessiveExpression(tokens) {
|
|
726
|
-
const token = tokens.peek();
|
|
727
|
-
if (!token) return null;
|
|
728
|
-
if (!this.currentProfile) return null;
|
|
729
|
-
const tokenValue = token.normalized || token.value;
|
|
730
|
-
const tokenLower = this.safeToLowerCase(tokenValue);
|
|
731
|
-
const baseRef = getPossessiveReference(this.currentProfile, tokenLower);
|
|
732
|
-
if (!baseRef) return null;
|
|
733
|
-
const mark = tokens.mark();
|
|
734
|
-
tokens.advance();
|
|
735
|
-
const propertyToken = tokens.peek();
|
|
736
|
-
if (!propertyToken) {
|
|
737
|
-
tokens.reset(mark);
|
|
738
|
-
return null;
|
|
739
|
-
}
|
|
740
|
-
if (propertyToken.kind === "identifier" || propertyToken.kind === "keyword" && !this.isStructuralKeyword(propertyToken.value) || propertyToken.kind === "selector" && propertyToken.value.startsWith("*") || propertyToken.kind === "selector" && propertyToken.value.startsWith("@") || propertyToken.kind === "selector" && propertyToken.value.startsWith(".") && /^\.[a-zA-Z_]\w*/.test(propertyToken.value)) {
|
|
741
|
-
tokens.advance();
|
|
742
|
-
let propertyName = propertyToken.value;
|
|
743
|
-
if (propertyToken.kind === "selector" && propertyName.startsWith(".") && /^\.[a-zA-Z_]\w*/.test(propertyName)) {
|
|
744
|
-
propertyName = propertyName.substring(1);
|
|
745
|
-
}
|
|
746
|
-
let chainedProps = propertyName;
|
|
747
|
-
while (tokens.peek()?.kind === "selector" && tokens.peek().value.startsWith(".") && /^\.[a-zA-Z_]\w*/.test(tokens.peek().value)) {
|
|
748
|
-
chainedProps += tokens.peek().value;
|
|
749
|
-
tokens.advance();
|
|
750
|
-
}
|
|
751
|
-
const nextPeek = tokens.peek();
|
|
752
|
-
if (nextPeek?.kind === "literal" && nextPeek.value.startsWith("(")) {
|
|
753
|
-
chainedProps += nextPeek.value;
|
|
754
|
-
tokens.advance();
|
|
755
|
-
}
|
|
756
|
-
return (0, import_intent.createPropertyPath)((0, import_intent.createReference)(baseRef), chainedProps);
|
|
757
|
-
}
|
|
758
|
-
tokens.reset(mark);
|
|
759
|
-
return null;
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
* Check if a keyword is a structural keyword (preposition, control flow, etc.)
|
|
763
|
-
* that shouldn't be consumed as a property name.
|
|
764
|
-
*/
|
|
765
|
-
isStructuralKeyword(value) {
|
|
766
|
-
const structural = /* @__PURE__ */ new Set([
|
|
767
|
-
// Prepositions
|
|
768
|
-
"into",
|
|
769
|
-
"in",
|
|
770
|
-
"to",
|
|
771
|
-
"from",
|
|
772
|
-
"at",
|
|
773
|
-
"by",
|
|
774
|
-
"with",
|
|
775
|
-
"without",
|
|
776
|
-
"before",
|
|
777
|
-
"after",
|
|
778
|
-
"of",
|
|
779
|
-
"as",
|
|
780
|
-
"on",
|
|
781
|
-
// Control flow
|
|
782
|
-
"then",
|
|
783
|
-
"end",
|
|
784
|
-
"else",
|
|
785
|
-
"if",
|
|
786
|
-
"repeat",
|
|
787
|
-
"while",
|
|
788
|
-
"for",
|
|
789
|
-
// Commands (shouldn't be property names)
|
|
790
|
-
"toggle",
|
|
791
|
-
"add",
|
|
792
|
-
"remove",
|
|
793
|
-
"put",
|
|
794
|
-
"set",
|
|
795
|
-
"show",
|
|
796
|
-
"hide",
|
|
797
|
-
"increment",
|
|
798
|
-
"decrement",
|
|
799
|
-
"send",
|
|
800
|
-
"trigger",
|
|
801
|
-
"call"
|
|
802
|
-
]);
|
|
803
|
-
return structural.has(value.toLowerCase());
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Try to match a method call expression like '#dialog.showModal()'.
|
|
807
|
-
* Pattern: selector + '.' + identifier + '(' + [args] + ')'
|
|
808
|
-
* Returns an expression value if matched, or null if not.
|
|
809
|
-
*/
|
|
810
|
-
tryMatchMethodCallExpression(tokens) {
|
|
811
|
-
const token = tokens.peek();
|
|
812
|
-
if (!token || token.kind !== "selector") return null;
|
|
813
|
-
const mark = tokens.mark();
|
|
814
|
-
tokens.advance();
|
|
815
|
-
const dotToken = tokens.peek();
|
|
816
|
-
if (!dotToken || dotToken.kind !== "operator" || dotToken.value !== ".") {
|
|
817
|
-
tokens.reset(mark);
|
|
818
|
-
return null;
|
|
819
|
-
}
|
|
820
|
-
tokens.advance();
|
|
821
|
-
const methodToken = tokens.peek();
|
|
822
|
-
if (!methodToken || methodToken.kind !== "identifier") {
|
|
823
|
-
tokens.reset(mark);
|
|
824
|
-
return null;
|
|
825
|
-
}
|
|
826
|
-
tokens.advance();
|
|
827
|
-
const openParen = tokens.peek();
|
|
828
|
-
if (!openParen || openParen.kind !== "punctuation" || openParen.value !== "(") {
|
|
829
|
-
tokens.reset(mark);
|
|
830
|
-
return null;
|
|
831
|
-
}
|
|
832
|
-
tokens.advance();
|
|
833
|
-
const args = [];
|
|
834
|
-
while (!tokens.isAtEnd() && args.length < _PatternMatcher.MAX_METHOD_ARGS) {
|
|
835
|
-
const argToken = tokens.peek();
|
|
836
|
-
if (!argToken) break;
|
|
837
|
-
if (argToken.kind === "punctuation" && argToken.value === ")") {
|
|
838
|
-
tokens.advance();
|
|
839
|
-
break;
|
|
840
|
-
}
|
|
841
|
-
if (argToken.kind === "punctuation" && argToken.value === ",") {
|
|
842
|
-
tokens.advance();
|
|
843
|
-
continue;
|
|
844
|
-
}
|
|
845
|
-
args.push(argToken.value);
|
|
846
|
-
tokens.advance();
|
|
847
|
-
}
|
|
848
|
-
const methodCall = `${token.value}.${methodToken.value}(${args.join(", ")})`;
|
|
849
|
-
return {
|
|
850
|
-
type: "expression",
|
|
851
|
-
raw: methodCall
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Try to match a property access expression like 'userData.name' or 'it.data'.
|
|
856
|
-
* Pattern: (identifier | keyword) + '.' + identifier [+ '.' + identifier ...]
|
|
857
|
-
* Returns an expression value if matched, or null if not.
|
|
858
|
-
*/
|
|
859
|
-
tryMatchPropertyAccessExpression(tokens) {
|
|
860
|
-
const token = tokens.peek();
|
|
861
|
-
if (!token) return null;
|
|
862
|
-
if (token.kind !== "identifier" && token.kind !== "keyword") return null;
|
|
863
|
-
const mark = tokens.mark();
|
|
864
|
-
tokens.advance();
|
|
865
|
-
const dotToken = tokens.peek();
|
|
866
|
-
if (!dotToken || dotToken.kind !== "operator" || dotToken.value !== ".") {
|
|
867
|
-
tokens.reset(mark);
|
|
868
|
-
return null;
|
|
869
|
-
}
|
|
870
|
-
tokens.advance();
|
|
871
|
-
const propertyToken = tokens.peek();
|
|
872
|
-
if (!propertyToken || propertyToken.kind !== "identifier") {
|
|
873
|
-
tokens.reset(mark);
|
|
874
|
-
return null;
|
|
875
|
-
}
|
|
876
|
-
tokens.advance();
|
|
877
|
-
let chain = `${token.value}.${propertyToken.value}`;
|
|
878
|
-
let depth = 1;
|
|
879
|
-
while (!tokens.isAtEnd() && depth < _PatternMatcher.MAX_PROPERTY_DEPTH) {
|
|
880
|
-
const nextDot = tokens.peek();
|
|
881
|
-
if (!nextDot || nextDot.kind !== "operator" || nextDot.value !== ".") {
|
|
882
|
-
break;
|
|
883
|
-
}
|
|
884
|
-
tokens.advance();
|
|
885
|
-
const nextProp = tokens.peek();
|
|
886
|
-
if (!nextProp || nextProp.kind !== "identifier") {
|
|
887
|
-
break;
|
|
888
|
-
}
|
|
889
|
-
tokens.advance();
|
|
890
|
-
chain += `.${nextProp.value}`;
|
|
891
|
-
depth++;
|
|
892
|
-
}
|
|
893
|
-
const openParen = tokens.peek();
|
|
894
|
-
if (openParen && openParen.kind === "punctuation" && openParen.value === "(") {
|
|
895
|
-
tokens.advance();
|
|
896
|
-
const args = [];
|
|
897
|
-
let argDepth = 0;
|
|
898
|
-
while (!tokens.isAtEnd() && args.length < _PatternMatcher.MAX_METHOD_ARGS) {
|
|
899
|
-
const argToken = tokens.peek();
|
|
900
|
-
if (!argToken) break;
|
|
901
|
-
if (argToken.kind === "punctuation" && argToken.value === ")") {
|
|
902
|
-
if (argDepth === 0) {
|
|
903
|
-
tokens.advance();
|
|
904
|
-
break;
|
|
905
|
-
}
|
|
906
|
-
argDepth--;
|
|
907
|
-
}
|
|
908
|
-
if (argToken.kind === "punctuation" && argToken.value === "(") {
|
|
909
|
-
argDepth++;
|
|
910
|
-
}
|
|
911
|
-
if (argToken.kind === "punctuation" && argToken.value === ",") {
|
|
912
|
-
tokens.advance();
|
|
913
|
-
continue;
|
|
914
|
-
}
|
|
915
|
-
args.push(argToken.value);
|
|
916
|
-
tokens.advance();
|
|
917
|
-
}
|
|
918
|
-
const methodCall = `${chain}(${args.join(", ")})`;
|
|
919
|
-
return {
|
|
920
|
-
type: "expression",
|
|
921
|
-
raw: methodCall
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
return {
|
|
925
|
-
type: "expression",
|
|
926
|
-
raw: chain
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
/**
|
|
930
|
-
* Try to match a possessive selector expression like "#element's *opacity".
|
|
931
|
-
* Pattern: selector + "'s" + (selector | identifier)
|
|
932
|
-
* Returns a property-path value if matched, or null if not.
|
|
933
|
-
*/
|
|
934
|
-
tryMatchPossessiveSelectorExpression(tokens) {
|
|
935
|
-
const token = tokens.peek();
|
|
936
|
-
if (!token || token.kind !== "selector") return null;
|
|
937
|
-
const mark = tokens.mark();
|
|
938
|
-
tokens.advance();
|
|
939
|
-
const possessiveToken = tokens.peek();
|
|
940
|
-
if (!possessiveToken || possessiveToken.kind !== "punctuation" || possessiveToken.value !== "'s") {
|
|
941
|
-
tokens.reset(mark);
|
|
942
|
-
return null;
|
|
943
|
-
}
|
|
944
|
-
tokens.advance();
|
|
945
|
-
const propertyToken = tokens.peek();
|
|
946
|
-
if (!propertyToken) {
|
|
947
|
-
tokens.reset(mark);
|
|
948
|
-
return null;
|
|
949
|
-
}
|
|
950
|
-
if (propertyToken.kind !== "selector" && propertyToken.kind !== "identifier") {
|
|
951
|
-
tokens.reset(mark);
|
|
952
|
-
return null;
|
|
953
|
-
}
|
|
954
|
-
tokens.advance();
|
|
955
|
-
return (0, import_intent.createPropertyPath)((0, import_intent.createSelector)(token.value), propertyToken.value);
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Try to match a selector + property expression like "#output.innerText".
|
|
959
|
-
* This handles cases where the tokenizer produces two selector tokens:
|
|
960
|
-
* - #output (id selector)
|
|
961
|
-
* - .innerText (looks like class selector, but is actually property)
|
|
962
|
-
*
|
|
963
|
-
* Pattern: id-selector + class-selector-that-is-actually-property
|
|
964
|
-
* Returns a property-path value if matched, or null if not.
|
|
965
|
-
*/
|
|
966
|
-
tryMatchSelectorPropertyExpression(tokens) {
|
|
967
|
-
const token = tokens.peek();
|
|
968
|
-
if (!token || token.kind !== "selector") return null;
|
|
969
|
-
if (typeof token.value !== "string" || !token.value.startsWith("#")) return null;
|
|
970
|
-
const mark = tokens.mark();
|
|
971
|
-
tokens.advance();
|
|
972
|
-
const propertyToken = tokens.peek();
|
|
973
|
-
if (!propertyToken || propertyToken.kind !== "selector") {
|
|
974
|
-
tokens.reset(mark);
|
|
975
|
-
return null;
|
|
976
|
-
}
|
|
977
|
-
if (!propertyToken.value.startsWith(".")) {
|
|
978
|
-
tokens.reset(mark);
|
|
979
|
-
return null;
|
|
980
|
-
}
|
|
981
|
-
const peek2 = tokens.peek(1);
|
|
982
|
-
if (peek2 && peek2.kind === "selector") {
|
|
983
|
-
}
|
|
984
|
-
tokens.advance();
|
|
985
|
-
const propertyName = propertyToken.value.slice(1);
|
|
986
|
-
return (0, import_intent.createPropertyPath)((0, import_intent.createSelector)(token.value), propertyName);
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* Match a group pattern token (optional sequence).
|
|
990
|
-
* When the group's leading marker isn't at the current position, scans ahead
|
|
991
|
-
* up to MAX_MARKER_SCAN tokens to find it. This allows unmarked tokens
|
|
992
|
-
* (e.g., a value like 'hello') to sit between groups without blocking later
|
|
993
|
-
* marker matches.
|
|
994
|
-
*/
|
|
995
|
-
matchGroupToken(tokens, patternToken, captured, parentStopMarkers) {
|
|
996
|
-
const mark = tokens.mark();
|
|
997
|
-
const capturedBefore = new Set(captured.keys());
|
|
998
|
-
const success = this.matchTokenSequence(
|
|
999
|
-
tokens,
|
|
1000
|
-
patternToken.tokens,
|
|
1001
|
-
captured,
|
|
1002
|
-
parentStopMarkers
|
|
1003
|
-
);
|
|
1004
|
-
if (success) return true;
|
|
1005
|
-
tokens.reset(mark);
|
|
1006
|
-
for (const role of captured.keys()) {
|
|
1007
|
-
if (!capturedBefore.has(role)) captured.delete(role);
|
|
1008
|
-
}
|
|
1009
|
-
if (!patternToken.optional) return false;
|
|
1010
|
-
const leadingMarker = this.getGroupLeadingMarker(patternToken);
|
|
1011
|
-
if (leadingMarker) {
|
|
1012
|
-
for (let offset = 1; offset <= _PatternMatcher.MAX_MARKER_SCAN; offset++) {
|
|
1013
|
-
const ahead = tokens.peek(offset);
|
|
1014
|
-
if (!ahead) break;
|
|
1015
|
-
const aheadValue = (ahead.normalized || ahead.value).toLowerCase();
|
|
1016
|
-
if (aheadValue === leadingMarker) {
|
|
1017
|
-
this.logger.debug(
|
|
1018
|
-
" >> MARKER SCAN: found",
|
|
1019
|
-
leadingMarker,
|
|
1020
|
-
"at offset",
|
|
1021
|
-
offset,
|
|
1022
|
-
"- skipping intervening tokens"
|
|
1023
|
-
);
|
|
1024
|
-
for (let s = 0; s < offset; s++) tokens.advance();
|
|
1025
|
-
const retrySuccess = this.matchTokenSequence(
|
|
1026
|
-
tokens,
|
|
1027
|
-
patternToken.tokens,
|
|
1028
|
-
captured,
|
|
1029
|
-
parentStopMarkers
|
|
1030
|
-
);
|
|
1031
|
-
if (retrySuccess) return true;
|
|
1032
|
-
tokens.reset(mark);
|
|
1033
|
-
for (const role of captured.keys()) {
|
|
1034
|
-
if (!capturedBefore.has(role)) captured.delete(role);
|
|
1035
|
-
}
|
|
1036
|
-
break;
|
|
1179
|
+
if (!patternToken.optional) return false;
|
|
1180
|
+
const leadingMarker = this.getGroupLeadingMarker(patternToken);
|
|
1181
|
+
if (leadingMarker) {
|
|
1182
|
+
for (let offset = 1; offset <= _PatternMatcher.MAX_MARKER_SCAN; offset++) {
|
|
1183
|
+
const ahead = tokens.peek(offset);
|
|
1184
|
+
if (!ahead) break;
|
|
1185
|
+
const aheadValue = (ahead.normalized || ahead.value).toLowerCase();
|
|
1186
|
+
if (aheadValue === leadingMarker) {
|
|
1187
|
+
this.logger.debug(
|
|
1188
|
+
" >> MARKER SCAN: found",
|
|
1189
|
+
leadingMarker,
|
|
1190
|
+
"at offset",
|
|
1191
|
+
offset,
|
|
1192
|
+
"- skipping intervening tokens"
|
|
1193
|
+
);
|
|
1194
|
+
for (let s = 0; s < offset; s++) tokens.advance();
|
|
1195
|
+
const retrySuccess = this.matchTokenSequence(
|
|
1196
|
+
tokens,
|
|
1197
|
+
patternToken.tokens,
|
|
1198
|
+
captured,
|
|
1199
|
+
parentStopMarkers
|
|
1200
|
+
);
|
|
1201
|
+
if (retrySuccess) return true;
|
|
1202
|
+
tokens.reset(mark);
|
|
1203
|
+
for (const role of captured.keys()) {
|
|
1204
|
+
if (!capturedBefore.has(role)) captured.delete(role);
|
|
1205
|
+
}
|
|
1206
|
+
break;
|
|
1037
1207
|
}
|
|
1038
1208
|
}
|
|
1039
1209
|
}
|
|
@@ -1060,7 +1230,7 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
1060
1230
|
if (token.stem === value && token.stemConfidence !== void 0 && token.stemConfidence >= 0.7) {
|
|
1061
1231
|
return "stem";
|
|
1062
1232
|
}
|
|
1063
|
-
if (token.kind === "keyword" &&
|
|
1233
|
+
if (token.kind === "keyword" && safeToLowerCase(token.value) === value.toLowerCase()) {
|
|
1064
1234
|
return "case-insensitive";
|
|
1065
1235
|
}
|
|
1066
1236
|
return "none";
|
|
@@ -1108,62 +1278,9 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
1108
1278
|
if (token.normalized && stopMarkers.has(token.normalized.toLowerCase())) return true;
|
|
1109
1279
|
return false;
|
|
1110
1280
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
tokenToSemanticValue(token) {
|
|
1115
|
-
switch (token.kind) {
|
|
1116
|
-
case "selector":
|
|
1117
|
-
return (0, import_intent.createSelector)(token.value);
|
|
1118
|
-
case "literal":
|
|
1119
|
-
return this.parseLiteralValue(token.value);
|
|
1120
|
-
case "keyword":
|
|
1121
|
-
const tokenValue = token.normalized || token.value;
|
|
1122
|
-
const lower = this.safeToLowerCase(tokenValue);
|
|
1123
|
-
if (isValidReference(lower)) {
|
|
1124
|
-
return (0, import_intent.createReference)(lower);
|
|
1125
|
-
}
|
|
1126
|
-
return (0, import_intent.createLiteral)(token.normalized || token.value);
|
|
1127
|
-
case "identifier":
|
|
1128
|
-
if (typeof token.value === "string" && token.value.startsWith(":")) {
|
|
1129
|
-
return (0, import_intent.createReference)(token.value);
|
|
1130
|
-
}
|
|
1131
|
-
const identLower = this.safeToLowerCase(token.value);
|
|
1132
|
-
if (isValidReference(identLower)) {
|
|
1133
|
-
return (0, import_intent.createReference)(identLower);
|
|
1134
|
-
}
|
|
1135
|
-
return { type: "expression", raw: token.value };
|
|
1136
|
-
case "url":
|
|
1137
|
-
return (0, import_intent.createLiteral)(token.value, "string");
|
|
1138
|
-
default:
|
|
1139
|
-
return null;
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* Parse a literal value (string, number, boolean).
|
|
1144
|
-
*/
|
|
1145
|
-
parseLiteralValue(value) {
|
|
1146
|
-
if (value.startsWith('"') || value.startsWith("'") || value.startsWith("`") || value.startsWith("\u300C")) {
|
|
1147
|
-
const inner = value.slice(1, -1);
|
|
1148
|
-
return (0, import_intent.createLiteral)(inner, "string");
|
|
1149
|
-
}
|
|
1150
|
-
if (value === "true") return (0, import_intent.createLiteral)(true, "boolean");
|
|
1151
|
-
if (value === "false") return (0, import_intent.createLiteral)(false, "boolean");
|
|
1152
|
-
const durationMatch = value.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);
|
|
1153
|
-
if (durationMatch) {
|
|
1154
|
-
const num2 = parseFloat(durationMatch[1]);
|
|
1155
|
-
const unit = durationMatch[2];
|
|
1156
|
-
if (unit) {
|
|
1157
|
-
return (0, import_intent.createLiteral)(value, "duration");
|
|
1158
|
-
}
|
|
1159
|
-
return (0, import_intent.createLiteral)(num2, "number");
|
|
1160
|
-
}
|
|
1161
|
-
const num = parseFloat(value);
|
|
1162
|
-
if (!isNaN(num)) {
|
|
1163
|
-
return (0, import_intent.createLiteral)(num, "number");
|
|
1164
|
-
}
|
|
1165
|
-
return (0, import_intent.createLiteral)(value, "string");
|
|
1166
|
-
}
|
|
1281
|
+
// ==========================================================================
|
|
1282
|
+
// Depth Limits for Expression Parsing (security hardening)
|
|
1283
|
+
// ==========================================================================
|
|
1167
1284
|
/**
|
|
1168
1285
|
* Apply extraction rules to fill in static values and defaults for missing roles.
|
|
1169
1286
|
*/
|
|
@@ -1184,260 +1301,634 @@ var _PatternMatcher = class _PatternMatcher {
|
|
|
1184
1301
|
isOptional(patternToken) {
|
|
1185
1302
|
return patternToken.type !== "literal" && patternToken.optional === true;
|
|
1186
1303
|
}
|
|
1304
|
+
// ===========================================================================
|
|
1305
|
+
// English Idiom Support - Noise Word Handling
|
|
1306
|
+
// ===========================================================================
|
|
1187
1307
|
/**
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
* - Stem matches (morphological normalization has inherent uncertainty)
|
|
1192
|
-
* - Missing optional roles (but less penalty if role has a default value)
|
|
1308
|
+
* Extract event modifiers from the token stream.
|
|
1309
|
+
* Event modifiers are .once, .debounce(N), .throttle(N), .queue(strategy)
|
|
1310
|
+
* that can appear after event names.
|
|
1193
1311
|
*
|
|
1194
|
-
*
|
|
1195
|
-
* - VSO languages (Arabic) when pattern starts with a verb
|
|
1312
|
+
* Returns EventModifiers object or undefined if no modifiers found.
|
|
1196
1313
|
*/
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
let
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
} else if (roleHasDefault) {
|
|
1218
|
-
score += weight * 0.6;
|
|
1219
|
-
}
|
|
1314
|
+
extractEventModifiers(tokens) {
|
|
1315
|
+
const modifiers = {};
|
|
1316
|
+
let foundModifier = false;
|
|
1317
|
+
while (!tokens.isAtEnd()) {
|
|
1318
|
+
const token = tokens.peek();
|
|
1319
|
+
if (!token || token.kind !== "event-modifier") {
|
|
1320
|
+
break;
|
|
1321
|
+
}
|
|
1322
|
+
const metadata = token.metadata;
|
|
1323
|
+
if (!metadata) {
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
foundModifier = true;
|
|
1327
|
+
switch (metadata.modifierName) {
|
|
1328
|
+
case "once":
|
|
1329
|
+
modifiers.once = true;
|
|
1330
|
+
break;
|
|
1331
|
+
case "debounce":
|
|
1332
|
+
if (typeof metadata.value === "number") {
|
|
1333
|
+
modifiers.debounce = metadata.value;
|
|
1220
1334
|
}
|
|
1221
|
-
|
|
1335
|
+
break;
|
|
1336
|
+
case "throttle":
|
|
1337
|
+
if (typeof metadata.value === "number") {
|
|
1338
|
+
modifiers.throttle = metadata.value;
|
|
1339
|
+
}
|
|
1340
|
+
break;
|
|
1341
|
+
case "queue":
|
|
1342
|
+
if (metadata.value === "first" || metadata.value === "last" || metadata.value === "all" || metadata.value === "none") {
|
|
1343
|
+
modifiers.queue = metadata.value;
|
|
1344
|
+
}
|
|
1345
|
+
break;
|
|
1222
1346
|
}
|
|
1347
|
+
tokens.advance();
|
|
1223
1348
|
}
|
|
1224
|
-
|
|
1225
|
-
if (this.stemMatchCount > 0 && this.totalKeywordMatches > 0) {
|
|
1226
|
-
const stemPenalty = this.stemMatchCount / this.totalKeywordMatches * 0.15;
|
|
1227
|
-
baseConfidence = Math.max(0.5, baseConfidence - stemPenalty);
|
|
1228
|
-
}
|
|
1229
|
-
const vsoBoost = this.calculateVSOConfidenceBoost(pattern);
|
|
1230
|
-
baseConfidence = Math.min(1, baseConfidence + vsoBoost);
|
|
1231
|
-
const prepositionAdjustment = this.arabicPrepositionDisambiguation(pattern, captured);
|
|
1232
|
-
baseConfidence = Math.max(0, Math.min(1, baseConfidence + prepositionAdjustment));
|
|
1233
|
-
return baseConfidence;
|
|
1349
|
+
return foundModifier ? modifiers : void 0;
|
|
1234
1350
|
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
"\u0623\u0636\u0641",
|
|
1259
|
-
"\u0623\u0632\u0644",
|
|
1260
|
-
"\u0636\u0639",
|
|
1261
|
-
"\u0627\u062C\u0639\u0644",
|
|
1262
|
-
"\u0639\u064A\u0646",
|
|
1263
|
-
"\u0632\u062F",
|
|
1264
|
-
"\u0627\u0646\u0642\u0635",
|
|
1265
|
-
"\u0633\u062C\u0644",
|
|
1266
|
-
"\u0623\u0638\u0647\u0631",
|
|
1267
|
-
"\u0623\u062E\u0641",
|
|
1268
|
-
"\u0634\u063A\u0644",
|
|
1269
|
-
"\u0623\u0631\u0633\u0644",
|
|
1270
|
-
"\u0631\u0643\u0632",
|
|
1271
|
-
"\u0634\u0648\u0634",
|
|
1272
|
-
"\u062A\u0648\u0642\u0641",
|
|
1273
|
-
"\u0627\u0646\u0633\u062E",
|
|
1274
|
-
"\u0627\u062D\u0630\u0641",
|
|
1275
|
-
"\u0627\u0635\u0646\u0639",
|
|
1276
|
-
"\u0627\u0646\u062A\u0638\u0631",
|
|
1277
|
-
"\u0627\u0646\u062A\u0642\u0627\u0644",
|
|
1278
|
-
"\u0623\u0648"
|
|
1279
|
-
]);
|
|
1280
|
-
if (ARABIC_VERBS.has(firstToken.value)) {
|
|
1281
|
-
return 0.15;
|
|
1282
|
-
}
|
|
1283
|
-
if (firstToken.alternatives) {
|
|
1284
|
-
for (const alt of firstToken.alternatives) {
|
|
1285
|
-
if (ARABIC_VERBS.has(alt)) {
|
|
1286
|
-
return 0.15;
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1351
|
+
};
|
|
1352
|
+
/** Maximum tokens to scan ahead when looking for a group's leading marker */
|
|
1353
|
+
_PatternMatcher.MAX_MARKER_SCAN = 3;
|
|
1354
|
+
var PatternMatcher = _PatternMatcher;
|
|
1355
|
+
var patternMatcher = new PatternMatcher();
|
|
1356
|
+
function matchPattern(tokens, pattern) {
|
|
1357
|
+
return patternMatcher.matchPattern(tokens, pattern);
|
|
1358
|
+
}
|
|
1359
|
+
function matchBest(tokens, patterns) {
|
|
1360
|
+
return patternMatcher.matchBest(tokens, patterns);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// src/core/tokenization/token-utils.ts
|
|
1364
|
+
var TokenStreamImpl = class {
|
|
1365
|
+
constructor(tokens, language) {
|
|
1366
|
+
this.pos = 0;
|
|
1367
|
+
this.tokens = tokens;
|
|
1368
|
+
this.language = language;
|
|
1369
|
+
}
|
|
1370
|
+
peek(offset = 0) {
|
|
1371
|
+
const index = this.pos + offset;
|
|
1372
|
+
if (index < 0 || index >= this.tokens.length) {
|
|
1373
|
+
return null;
|
|
1289
1374
|
}
|
|
1290
|
-
return
|
|
1375
|
+
return this.tokens[index];
|
|
1376
|
+
}
|
|
1377
|
+
advance() {
|
|
1378
|
+
if (this.isAtEnd()) {
|
|
1379
|
+
throw new Error("Unexpected end of token stream");
|
|
1380
|
+
}
|
|
1381
|
+
return this.tokens[this.pos++];
|
|
1382
|
+
}
|
|
1383
|
+
isAtEnd() {
|
|
1384
|
+
return this.pos >= this.tokens.length;
|
|
1385
|
+
}
|
|
1386
|
+
mark() {
|
|
1387
|
+
return { position: this.pos };
|
|
1388
|
+
}
|
|
1389
|
+
reset(mark) {
|
|
1390
|
+
this.pos = mark.position;
|
|
1391
|
+
}
|
|
1392
|
+
position() {
|
|
1393
|
+
return this.pos;
|
|
1291
1394
|
}
|
|
1292
1395
|
/**
|
|
1293
|
-
*
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
1301
|
-
* This method analyzes the prepositions used with captured semantic roles and
|
|
1302
|
-
* adjusts confidence based on idiomaticity:
|
|
1303
|
-
* - +0.10 for highly idiomatic preposition choices
|
|
1304
|
-
* - -0.10 for less natural preposition choices
|
|
1305
|
-
*
|
|
1306
|
-
* @param pattern The language pattern being matched
|
|
1307
|
-
* @param captured The captured semantic values
|
|
1308
|
-
* @returns Confidence adjustment (-0.10 to +0.10)
|
|
1396
|
+
* Get remaining tokens as an array.
|
|
1397
|
+
*/
|
|
1398
|
+
remaining() {
|
|
1399
|
+
return this.tokens.slice(this.pos);
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Consume tokens while predicate is true.
|
|
1309
1403
|
*/
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1404
|
+
takeWhile(predicate) {
|
|
1405
|
+
const result = [];
|
|
1406
|
+
while (!this.isAtEnd() && predicate(this.peek())) {
|
|
1407
|
+
result.push(this.advance());
|
|
1408
|
+
}
|
|
1409
|
+
return result;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Skip tokens while predicate is true.
|
|
1413
|
+
*/
|
|
1414
|
+
skipWhile(predicate) {
|
|
1415
|
+
while (!this.isAtEnd() && predicate(this.peek())) {
|
|
1416
|
+
this.advance();
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
function createPosition(start, end) {
|
|
1421
|
+
return { start, end };
|
|
1422
|
+
}
|
|
1423
|
+
function createToken(valueOrParams, kind, position, normalizedOrOptions) {
|
|
1424
|
+
if (typeof valueOrParams === "object") {
|
|
1425
|
+
const { value: value2, kind: kind2, position: position2, normalized: normalized2, stem, stemConfidence, metadata } = valueOrParams;
|
|
1426
|
+
return {
|
|
1427
|
+
value: value2,
|
|
1428
|
+
kind: kind2,
|
|
1429
|
+
position: position2,
|
|
1430
|
+
...normalized2 !== void 0 && { normalized: normalized2 },
|
|
1431
|
+
...stem !== void 0 && { stem },
|
|
1432
|
+
...stemConfidence !== void 0 && { stemConfidence },
|
|
1433
|
+
...metadata !== void 0 && { metadata }
|
|
1332
1434
|
};
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1435
|
+
}
|
|
1436
|
+
const value = valueOrParams;
|
|
1437
|
+
if (!kind || !position) {
|
|
1438
|
+
throw new Error("createToken requires kind and position parameters");
|
|
1439
|
+
}
|
|
1440
|
+
if (typeof normalizedOrOptions === "string") {
|
|
1441
|
+
return { value, kind, position, normalized: normalizedOrOptions };
|
|
1442
|
+
}
|
|
1443
|
+
if (normalizedOrOptions) {
|
|
1444
|
+
const { normalized: normalized2, stem, stemConfidence, metadata } = normalizedOrOptions;
|
|
1445
|
+
return {
|
|
1446
|
+
value,
|
|
1447
|
+
kind,
|
|
1448
|
+
position,
|
|
1449
|
+
...normalized2 !== void 0 && { normalized: normalized2 },
|
|
1450
|
+
...stem !== void 0 && { stem },
|
|
1451
|
+
...stemConfidence !== void 0 && { stemConfidence },
|
|
1452
|
+
...metadata !== void 0 && { metadata }
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
return { value, kind, position };
|
|
1456
|
+
}
|
|
1457
|
+
function isWhitespace(char) {
|
|
1458
|
+
return /\s/.test(char);
|
|
1459
|
+
}
|
|
1460
|
+
function isSelectorStart(char) {
|
|
1461
|
+
return char === "#" || char === "." || char === "[" || char === "@" || char === "*" || char === "<";
|
|
1462
|
+
}
|
|
1463
|
+
function isQuote(char) {
|
|
1464
|
+
return char === '"' || char === "'" || char === "`" || char === "\u300C" || char === "\u300D";
|
|
1465
|
+
}
|
|
1466
|
+
function isDigit(char) {
|
|
1467
|
+
return /\d/.test(char);
|
|
1468
|
+
}
|
|
1469
|
+
function stripOptionalDiacritics(word) {
|
|
1470
|
+
return word.replace(/[\u064b-\u0652\u0670]/g, "");
|
|
1471
|
+
}
|
|
1472
|
+
function isAsciiLetter(char) {
|
|
1473
|
+
return /[a-zA-Z]/.test(char);
|
|
1474
|
+
}
|
|
1475
|
+
function isAsciiIdentifierChar(char) {
|
|
1476
|
+
return /[a-zA-Z0-9_-]/.test(char);
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
// src/core/matching/match-skeleton.ts
|
|
1480
|
+
function groupHasRole(group) {
|
|
1481
|
+
return group.tokens.some((t) => t.type === "role" || t.type === "group" && groupHasRole(t));
|
|
1482
|
+
}
|
|
1483
|
+
var MatchSkeleton = class {
|
|
1484
|
+
/**
|
|
1485
|
+
* @param makeReader - builds the grammar's reader, handed this matcher's view
|
|
1486
|
+
* of the match in progress (one reader per matcher).
|
|
1487
|
+
*/
|
|
1488
|
+
constructor(makeReader, confidenceModel) {
|
|
1489
|
+
/**
|
|
1490
|
+
* The pattern tokens still to match after the one being matched, through
|
|
1491
|
+
* every enclosing group: a value stops at any marker the pattern still owes.
|
|
1492
|
+
*/
|
|
1493
|
+
this.patternRest = [];
|
|
1494
|
+
/**
|
|
1495
|
+
* Whether the role slot being matched directly follows a literal the pattern
|
|
1496
|
+
* matched: its marker (`[por {quantity}]`), or the command's verb.
|
|
1497
|
+
*/
|
|
1498
|
+
this.slotAfterLiteral = false;
|
|
1499
|
+
/**
|
|
1500
|
+
* Selective memoization cache (Phase 6.1).
|
|
1501
|
+
* Caches pattern match results keyed by `tokenPosition:patternId`.
|
|
1502
|
+
* Cleared before each top-level matchBest() call.
|
|
1503
|
+
*/
|
|
1504
|
+
this.matchCache = /* @__PURE__ */ new Map();
|
|
1505
|
+
/**
|
|
1506
|
+
* Stream index where each role's capture began, for the current
|
|
1507
|
+
* `matchPattern` call. Rebuilt per call, written on the same success path as
|
|
1508
|
+
* `captured` — see `PatternMatchResult.roleStarts`.
|
|
1509
|
+
*/
|
|
1510
|
+
this.roleStarts = /* @__PURE__ */ new Map();
|
|
1511
|
+
/**
|
|
1512
|
+
* Track stem matches for confidence calculation.
|
|
1513
|
+
* This is set during matching and read during confidence calculation.
|
|
1514
|
+
*/
|
|
1515
|
+
this.stemMatchCount = 0;
|
|
1516
|
+
this.totalKeywordMatches = 0;
|
|
1517
|
+
this.confidenceModel = confidenceModel;
|
|
1518
|
+
this.reader = makeReader({
|
|
1519
|
+
patternRest: () => this.patternRest,
|
|
1520
|
+
slotAfterLiteral: () => this.slotAfterLiteral,
|
|
1521
|
+
wouldMatch: (pt, token) => this.patternTokenWouldMatch(pt, token)
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Try to match a single pattern against the token stream.
|
|
1526
|
+
* Returns the match result or null if no match.
|
|
1527
|
+
*/
|
|
1528
|
+
matchPattern(tokens, pattern) {
|
|
1529
|
+
const mark = tokens.mark();
|
|
1530
|
+
const captured = /* @__PURE__ */ new Map();
|
|
1531
|
+
this.reader.beginPattern(pattern);
|
|
1532
|
+
this.stemMatchCount = 0;
|
|
1533
|
+
this.totalKeywordMatches = 0;
|
|
1534
|
+
this.roleStarts = /* @__PURE__ */ new Map();
|
|
1535
|
+
this.patternRest = [];
|
|
1536
|
+
const success = this.matchTokenSequence(tokens, pattern.template.tokens, captured);
|
|
1537
|
+
if (!success) {
|
|
1538
|
+
tokens.reset(mark);
|
|
1539
|
+
return null;
|
|
1540
|
+
}
|
|
1541
|
+
const confidence = this.confidenceModel.calculate({
|
|
1542
|
+
pattern,
|
|
1543
|
+
captured,
|
|
1544
|
+
stemMatchCount: this.stemMatchCount,
|
|
1545
|
+
totalKeywordMatches: this.totalKeywordMatches
|
|
1546
|
+
});
|
|
1547
|
+
this.applyExtractionRules(pattern, captured);
|
|
1548
|
+
return {
|
|
1549
|
+
pattern,
|
|
1550
|
+
captured,
|
|
1551
|
+
consumedTokens: tokens.position() - mark.position,
|
|
1552
|
+
confidence,
|
|
1553
|
+
roleStarts: this.roleStarts,
|
|
1554
|
+
...this.reader.resultFields?.()
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Try to match multiple patterns, return the best match.
|
|
1559
|
+
*/
|
|
1560
|
+
matchBest(tokens, patterns) {
|
|
1561
|
+
this.matchCache.clear();
|
|
1562
|
+
const matches = [];
|
|
1563
|
+
const startPos = tokens.position();
|
|
1564
|
+
for (const pattern of patterns) {
|
|
1565
|
+
const mark = tokens.mark();
|
|
1566
|
+
const cacheKey = `${startPos}:${pattern.id}`;
|
|
1567
|
+
let result;
|
|
1568
|
+
if (this.matchCache.has(cacheKey)) {
|
|
1569
|
+
result = this.matchCache.get(cacheKey);
|
|
1570
|
+
} else {
|
|
1571
|
+
result = this.matchPattern(tokens, pattern);
|
|
1572
|
+
this.matchCache.set(cacheKey, result);
|
|
1337
1573
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1574
|
+
if (result) {
|
|
1575
|
+
matches.push(result);
|
|
1576
|
+
}
|
|
1577
|
+
tokens.reset(mark);
|
|
1578
|
+
}
|
|
1579
|
+
if (matches.length === 0) {
|
|
1580
|
+
return null;
|
|
1581
|
+
}
|
|
1582
|
+
matches.sort((a, b) => {
|
|
1583
|
+
const priorityDiff = b.pattern.priority - a.pattern.priority;
|
|
1584
|
+
if (priorityDiff !== 0) return priorityDiff;
|
|
1585
|
+
return b.confidence - a.confidence;
|
|
1586
|
+
});
|
|
1587
|
+
const best = matches[0];
|
|
1588
|
+
this.matchPattern(tokens, best.pattern);
|
|
1589
|
+
return best;
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Match a sequence of pattern tokens against the token stream.
|
|
1593
|
+
*/
|
|
1594
|
+
matchTokenSequence(tokens, patternTokens, captured, nextAfterSequence) {
|
|
1595
|
+
this.reader.skipLeading?.(tokens, patternTokens);
|
|
1596
|
+
for (let i = 0; i < patternTokens.length; i++) {
|
|
1597
|
+
const patternToken = patternTokens[i];
|
|
1598
|
+
this.reader.beforePatternToken?.(tokens, patternTokens, i, captured);
|
|
1599
|
+
if (this.reader.maySkipSlot(
|
|
1600
|
+
patternToken,
|
|
1601
|
+
tokens.peek(),
|
|
1602
|
+
patternTokens[i + 1] ?? nextAfterSequence
|
|
1603
|
+
)) {
|
|
1604
|
+
const skipMark = tokens.mark();
|
|
1605
|
+
const speculative = new Map(captured);
|
|
1606
|
+
if (this.matchTokenSequence(
|
|
1607
|
+
tokens,
|
|
1608
|
+
patternTokens.slice(i + 1),
|
|
1609
|
+
speculative,
|
|
1610
|
+
nextAfterSequence
|
|
1611
|
+
) && this.reader.atClauseEnd(tokens)) {
|
|
1612
|
+
captured.clear();
|
|
1613
|
+
for (const [role, value] of speculative) captured.set(role, value);
|
|
1614
|
+
return true;
|
|
1615
|
+
}
|
|
1616
|
+
tokens.reset(skipMark);
|
|
1617
|
+
}
|
|
1618
|
+
const outerRest = this.patternRest;
|
|
1619
|
+
this.patternRest = [...patternTokens.slice(i + 1), ...outerRest];
|
|
1620
|
+
this.slotAfterLiteral = patternToken.type === "role" && patternTokens[i - 1]?.type === "literal";
|
|
1621
|
+
const matched = this.matchPatternToken(
|
|
1622
|
+
tokens,
|
|
1623
|
+
patternToken,
|
|
1624
|
+
captured,
|
|
1625
|
+
patternTokens[i + 1] ?? nextAfterSequence
|
|
1626
|
+
);
|
|
1627
|
+
this.patternRest = outerRest;
|
|
1628
|
+
if (!matched) {
|
|
1629
|
+
if (this.isOptional(patternToken)) {
|
|
1630
|
+
continue;
|
|
1631
|
+
}
|
|
1632
|
+
return false;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return true;
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Match a single pattern token against the current position in the stream.
|
|
1639
|
+
*/
|
|
1640
|
+
matchPatternToken(tokens, patternToken, captured, nextPatternToken) {
|
|
1641
|
+
switch (patternToken.type) {
|
|
1642
|
+
case "literal":
|
|
1643
|
+
return this.matchLiteralToken(tokens, patternToken);
|
|
1644
|
+
case "role": {
|
|
1645
|
+
const roleStart = tokens.position();
|
|
1646
|
+
const matchedRole = this.reader.readRole(tokens, patternToken, captured, nextPatternToken);
|
|
1647
|
+
if (matchedRole && captured.has(patternToken.role)) {
|
|
1648
|
+
this.roleStarts.set(patternToken.role, roleStart);
|
|
1649
|
+
}
|
|
1650
|
+
return matchedRole;
|
|
1651
|
+
}
|
|
1652
|
+
case "group":
|
|
1653
|
+
return this.matchGroupToken(tokens, patternToken, captured, nextPatternToken);
|
|
1654
|
+
default:
|
|
1655
|
+
return false;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Match a literal pattern token (keyword or particle).
|
|
1660
|
+
*/
|
|
1661
|
+
matchLiteralToken(tokens, patternToken) {
|
|
1662
|
+
const token = tokens.peek();
|
|
1663
|
+
if (!token) return false;
|
|
1664
|
+
const matchType = this.getMatchType(token, patternToken.value);
|
|
1665
|
+
if (matchType !== "none") {
|
|
1666
|
+
this.totalKeywordMatches++;
|
|
1667
|
+
if (matchType === "stem") {
|
|
1668
|
+
this.stemMatchCount++;
|
|
1669
|
+
}
|
|
1670
|
+
tokens.advance();
|
|
1671
|
+
return true;
|
|
1672
|
+
}
|
|
1673
|
+
if (patternToken.alternatives) {
|
|
1674
|
+
for (const alt of patternToken.alternatives) {
|
|
1675
|
+
const altMatchType = this.getMatchType(token, alt);
|
|
1676
|
+
if (altMatchType !== "none") {
|
|
1677
|
+
this.totalKeywordMatches++;
|
|
1678
|
+
if (altMatchType === "stem") {
|
|
1679
|
+
this.stemMatchCount++;
|
|
1680
|
+
}
|
|
1681
|
+
tokens.advance();
|
|
1682
|
+
return true;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
for (const value of [patternToken.value, ...patternToken.alternatives ?? []]) {
|
|
1687
|
+
for (const sep of ["-", "_"]) {
|
|
1688
|
+
if (value.includes(sep) && this.tryMatchShatteredCompound(tokens, value, sep)) {
|
|
1689
|
+
this.totalKeywordMatches++;
|
|
1690
|
+
return true;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* Match a compound keyword (`titik-henti`, `по_умолчанию`) against a
|
|
1698
|
+
* shattered token run (`titik` `-` `henti` / `по` `_` `умолчанию`): word
|
|
1699
|
+
* segments must be identifier/keyword/particle tokens equal to the expected
|
|
1700
|
+
* segments (case-insensitive; particle because prepositions like ru `по` /
|
|
1701
|
+
* uk `за` lead some underscore compounds), separators lone `sep` tokens.
|
|
1702
|
+
* Consumes the run on success, resets the stream on failure.
|
|
1703
|
+
*/
|
|
1704
|
+
tryMatchShatteredCompound(tokens, expected, sep) {
|
|
1705
|
+
const segments = expected.split(sep);
|
|
1706
|
+
if (segments.length < 2 || segments.some((s) => s.length === 0)) return false;
|
|
1707
|
+
const mark = tokens.mark();
|
|
1708
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1709
|
+
if (i > 0) {
|
|
1710
|
+
const sepToken = tokens.peek();
|
|
1711
|
+
if (!sepToken || sepToken.value !== sep) {
|
|
1712
|
+
tokens.reset(mark);
|
|
1713
|
+
return false;
|
|
1714
|
+
}
|
|
1715
|
+
tokens.advance();
|
|
1716
|
+
}
|
|
1717
|
+
const word = tokens.peek();
|
|
1718
|
+
if (!word || word.kind !== "identifier" && word.kind !== "keyword" && word.kind !== "particle" || word.value.toLowerCase() !== segments[i].toLowerCase()) {
|
|
1719
|
+
tokens.reset(mark);
|
|
1720
|
+
return false;
|
|
1721
|
+
}
|
|
1722
|
+
tokens.advance();
|
|
1723
|
+
}
|
|
1724
|
+
return true;
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Match a group pattern token (optional sequence).
|
|
1728
|
+
*/
|
|
1729
|
+
matchGroupToken(tokens, patternToken, captured, nextPatternToken) {
|
|
1730
|
+
const mark = tokens.mark();
|
|
1731
|
+
const capturedBefore = new Map(captured);
|
|
1732
|
+
let success = this.matchTokenSequence(tokens, patternToken.tokens, captured, nextPatternToken);
|
|
1733
|
+
if (success && tokens.position() > mark.position && groupHasRole(patternToken) && [...captured].every(([role, value]) => capturedBefore.get(role) === value) && captured.size === capturedBefore.size) {
|
|
1734
|
+
success = false;
|
|
1735
|
+
}
|
|
1736
|
+
if (success) {
|
|
1737
|
+
const markerLiterals = [];
|
|
1738
|
+
for (const inner of patternToken.tokens) {
|
|
1739
|
+
if (inner.type === "group" && inner.renderRequired) {
|
|
1740
|
+
for (const t of inner.tokens) {
|
|
1741
|
+
if (t.type === "literal") markerLiterals.push(t.value, ...t.alternatives ?? []);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
if (markerLiterals.length > 0) {
|
|
1746
|
+
const addedRole = [...captured.keys()].some((role) => !capturedBefore.has(role));
|
|
1747
|
+
if (addedRole) {
|
|
1748
|
+
const last = tokens.tokens[tokens.position() - 1];
|
|
1749
|
+
const markerSeen = last !== void 0 && tokens.position() > mark.position && markerLiterals.some((lit) => this.getMatchType(last, lit) !== "none");
|
|
1750
|
+
if (!markerSeen) success = false;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
if (!success) {
|
|
1755
|
+
tokens.reset(mark);
|
|
1756
|
+
for (const role of captured.keys()) {
|
|
1757
|
+
if (!capturedBefore.has(role)) {
|
|
1758
|
+
captured.delete(role);
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
for (const [role, value] of capturedBefore) {
|
|
1762
|
+
if (captured.get(role) !== value) {
|
|
1763
|
+
captured.set(role, value);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
return patternToken.optional || false;
|
|
1767
|
+
}
|
|
1768
|
+
return true;
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Whether a pattern token (literal, or a group starting with a literal) would
|
|
1772
|
+
* match the given stream token. Used to keep the event-head source-clause
|
|
1773
|
+
* consumption from stealing a marker the pattern explicitly expects.
|
|
1774
|
+
*/
|
|
1775
|
+
patternTokenWouldMatch(pt, token) {
|
|
1776
|
+
if (!pt) return false;
|
|
1777
|
+
if (pt.type === "literal") {
|
|
1778
|
+
if (this.getMatchType(token, pt.value) !== "none") return true;
|
|
1779
|
+
return !!pt.alternatives?.some((a) => this.getMatchType(token, a) !== "none");
|
|
1780
|
+
}
|
|
1781
|
+
if (pt.type === "group") {
|
|
1782
|
+
return this.patternTokenWouldMatch(pt.tokens?.[0], token);
|
|
1783
|
+
}
|
|
1784
|
+
return false;
|
|
1785
|
+
}
|
|
1786
|
+
/**
|
|
1787
|
+
* Get the type of match for a token against a value.
|
|
1788
|
+
* Used for confidence calculation.
|
|
1789
|
+
*/
|
|
1790
|
+
getMatchType(token, value) {
|
|
1791
|
+
if (token.value === value) return "exact";
|
|
1792
|
+
if (token.normalized === value) return "normalized";
|
|
1793
|
+
if (token.stem === value && token.stemConfidence !== void 0 && token.stemConfidence >= 0.7) {
|
|
1794
|
+
return "stem";
|
|
1795
|
+
}
|
|
1796
|
+
if (token.kind === "keyword" && token.value.toLowerCase() === value.toLowerCase()) {
|
|
1797
|
+
return "case-insensitive";
|
|
1798
|
+
}
|
|
1799
|
+
if (token.kind === "keyword") {
|
|
1800
|
+
const strippedToken = stripOptionalDiacritics(token.value).toLowerCase();
|
|
1801
|
+
if (strippedToken && strippedToken === stripOptionalDiacritics(value).toLowerCase()) {
|
|
1802
|
+
return "case-insensitive";
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
return "none";
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Apply extraction rules to fill in static values and defaults for missing
|
|
1809
|
+
* roles, and re-shape captured roles that declare a `transform` (the
|
|
1810
|
+
* ExtractionRule field was documented but unwired — go-qu-url-dest is the
|
|
1811
|
+
* first consumer: it re-types the marker-bound capture to the expression
|
|
1812
|
+
* shape the en reference produces).
|
|
1813
|
+
*/
|
|
1814
|
+
applyExtractionRules(pattern, captured) {
|
|
1815
|
+
for (const [role, rule] of Object.entries(pattern.extraction)) {
|
|
1816
|
+
const existing = captured.get(role);
|
|
1817
|
+
if (existing) {
|
|
1818
|
+
if (rule.transform) {
|
|
1819
|
+
const raw = existing.type === "literal" ? String(existing.value) : String(existing.raw ?? "");
|
|
1820
|
+
captured.set(role, rule.transform(raw));
|
|
1345
1821
|
}
|
|
1822
|
+
} else if (rule.value !== void 0) {
|
|
1823
|
+
captured.set(
|
|
1824
|
+
role,
|
|
1825
|
+
rule.valueIsExpression ? { type: "expression", raw: rule.value } : { type: "literal", value: rule.value }
|
|
1826
|
+
);
|
|
1827
|
+
} else if (rule.default) {
|
|
1828
|
+
const implicitDefault = {
|
|
1829
|
+
...rule.default,
|
|
1830
|
+
implicit: true
|
|
1831
|
+
};
|
|
1832
|
+
captured.set(role, implicitDefault);
|
|
1346
1833
|
}
|
|
1347
1834
|
}
|
|
1348
|
-
return Math.max(-0.1, Math.min(0.1, adjustment));
|
|
1349
1835
|
}
|
|
1350
1836
|
/**
|
|
1351
|
-
*
|
|
1352
|
-
* This enables more natural English syntax like "toggle the .active".
|
|
1837
|
+
* Check if a pattern token is optional.
|
|
1353
1838
|
*/
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1839
|
+
isOptional(patternToken) {
|
|
1840
|
+
return patternToken.type !== "literal" && patternToken.optional === true;
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1843
|
+
|
|
1844
|
+
// src/core/matching/stock-reader.ts
|
|
1845
|
+
function greedyStopMarkers(rest) {
|
|
1846
|
+
const markers = /* @__PURE__ */ new Set();
|
|
1847
|
+
const add = (pt) => {
|
|
1848
|
+
markers.add(pt.value.toLowerCase());
|
|
1849
|
+
for (const alt of pt.alternatives ?? []) markers.add(alt.toLowerCase());
|
|
1850
|
+
};
|
|
1851
|
+
for (const pt of rest) {
|
|
1852
|
+
if (pt.type === "literal") {
|
|
1853
|
+
add(pt);
|
|
1854
|
+
break;
|
|
1366
1855
|
}
|
|
1367
|
-
if (
|
|
1368
|
-
tokens.
|
|
1856
|
+
if (pt.type === "group") {
|
|
1857
|
+
const lead = pt.tokens.find((t) => t.type === "literal");
|
|
1858
|
+
if (lead?.type === "literal") add(lead);
|
|
1859
|
+
if (!pt.optional) break;
|
|
1369
1860
|
}
|
|
1370
1861
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1862
|
+
return markers;
|
|
1863
|
+
}
|
|
1864
|
+
function isStopMarker(token, stopMarkers) {
|
|
1865
|
+
if (stopMarkers.size === 0) return false;
|
|
1866
|
+
if (stopMarkers.has(token.value.toLowerCase())) return true;
|
|
1867
|
+
return !!token.normalized && stopMarkers.has(token.normalized.toLowerCase());
|
|
1868
|
+
}
|
|
1869
|
+
function readGreedy(tokens, stopMarkers) {
|
|
1870
|
+
const values = [];
|
|
1871
|
+
while (!tokens.isAtEnd()) {
|
|
1872
|
+
const next = tokens.peek();
|
|
1873
|
+
if (!next || isStopMarker(next, stopMarkers)) break;
|
|
1874
|
+
values.push(next.value);
|
|
1875
|
+
tokens.advance();
|
|
1876
|
+
}
|
|
1877
|
+
return values.length > 0 ? { type: "expression", raw: values.join(" ") } : null;
|
|
1878
|
+
}
|
|
1879
|
+
var StockValueReader = class {
|
|
1880
|
+
constructor(view, profiles = {}) {
|
|
1881
|
+
this.view = view;
|
|
1882
|
+
this.profiles = profiles;
|
|
1883
|
+
}
|
|
1884
|
+
beginPattern(pattern) {
|
|
1885
|
+
this.profile = this.profiles[pattern.language] ?? { code: pattern.language };
|
|
1886
|
+
this.lastOptional = void 0;
|
|
1887
|
+
}
|
|
1888
|
+
readRole(tokens, slot, captured, next) {
|
|
1889
|
+
const start = tokens.mark();
|
|
1890
|
+
if (this.readOnce(tokens, slot, captured, next, true)) {
|
|
1891
|
+
if (!slot.optional) {
|
|
1892
|
+
this.lastOptional = void 0;
|
|
1893
|
+
} else if (captured.has(slot.role) && tokens.position() > start.position && !this.view.slotAfterLiteral() && next?.type !== "literal") {
|
|
1894
|
+
this.lastOptional = { role: slot.role, start, end: tokens.position() };
|
|
1389
1895
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1896
|
+
return true;
|
|
1897
|
+
}
|
|
1898
|
+
const before = this.lastOptional;
|
|
1899
|
+
if (slot.optional || !before || before.end !== tokens.position()) return false;
|
|
1900
|
+
this.lastOptional = void 0;
|
|
1901
|
+
tokens.reset(before.start);
|
|
1902
|
+
captured.delete(before.role);
|
|
1903
|
+
return this.readOnce(tokens, slot, captured, next, false);
|
|
1904
|
+
}
|
|
1905
|
+
/** One read of `slot`; `guard` refuses a required slot the marker the pattern wants next. */
|
|
1906
|
+
readOnce(tokens, slot, captured, next, guard) {
|
|
1907
|
+
if (guard && !slot.optional && next?.type === "literal") {
|
|
1908
|
+
const token = tokens.peek();
|
|
1909
|
+
if (token && this.view.wouldMatch(next, token)) return false;
|
|
1910
|
+
}
|
|
1911
|
+
if (slot.greedy) {
|
|
1912
|
+
const value = readGreedy(tokens, greedyStopMarkers(this.view.patternRest()));
|
|
1913
|
+
if (value) {
|
|
1914
|
+
captured.set(slot.role, value);
|
|
1915
|
+
return true;
|
|
1410
1916
|
}
|
|
1411
|
-
|
|
1917
|
+
return slot.optional ?? false;
|
|
1412
1918
|
}
|
|
1413
|
-
return
|
|
1919
|
+
return readRoleValue(tokens, slot, captured, this.profile);
|
|
1920
|
+
}
|
|
1921
|
+
maySkipSlot(patternToken, token, next) {
|
|
1922
|
+
const slot = patternToken.type === "group" && patternToken.optional ? patternToken.tokens.every((t) => t.type === "role") ? patternToken.tokens[0] : void 0 : patternToken;
|
|
1923
|
+
if (!slot || slot.type !== "role" || !slot.optional) return false;
|
|
1924
|
+
return !!token && this.view.wouldMatch(next, token);
|
|
1925
|
+
}
|
|
1926
|
+
atClauseEnd(tokens) {
|
|
1927
|
+
return tokens.isAtEnd();
|
|
1414
1928
|
}
|
|
1415
1929
|
};
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
// ==========================================================================
|
|
1419
|
-
// Depth Limits for Expression Parsing (security hardening)
|
|
1420
|
-
// ==========================================================================
|
|
1421
|
-
/** Maximum depth for nested property access (e.g., a.b.c.d...) */
|
|
1422
|
-
_PatternMatcher.MAX_PROPERTY_DEPTH = 10;
|
|
1423
|
-
/** Maximum number of arguments in method calls */
|
|
1424
|
-
_PatternMatcher.MAX_METHOD_ARGS = 20;
|
|
1425
|
-
// ===========================================================================
|
|
1426
|
-
// English Idiom Support - Noise Word Handling
|
|
1427
|
-
// ===========================================================================
|
|
1428
|
-
/**
|
|
1429
|
-
* Noise words that can be skipped in English for more natural syntax.
|
|
1430
|
-
* - "the" before selectors: "toggle the .active" → "toggle .active"
|
|
1431
|
-
* - "class" after class selectors: "add the .visible class" → "add .visible"
|
|
1432
|
-
*/
|
|
1433
|
-
_PatternMatcher.ENGLISH_NOISE_WORDS = /* @__PURE__ */ new Set(["the", "a", "an"]);
|
|
1434
|
-
var PatternMatcher = _PatternMatcher;
|
|
1435
|
-
var patternMatcher = new PatternMatcher();
|
|
1436
|
-
function matchPattern(tokens, pattern) {
|
|
1437
|
-
return patternMatcher.matchPattern(tokens, pattern);
|
|
1438
|
-
}
|
|
1439
|
-
function matchBest(tokens, patterns) {
|
|
1440
|
-
return patternMatcher.matchBest(tokens, patterns);
|
|
1930
|
+
function createStockReader(profiles = {}) {
|
|
1931
|
+
return (view) => new StockValueReader(view, profiles);
|
|
1441
1932
|
}
|
|
1442
1933
|
|
|
1443
1934
|
// src/generation/pattern-generator.ts
|
|
@@ -1676,39 +2167,614 @@ function buildRenderTables(schemas, profiles) {
|
|
|
1676
2167
|
markerPositions[role][profile.code] = markerDef.position;
|
|
1677
2168
|
}
|
|
1678
2169
|
}
|
|
1679
|
-
const schemaMap = /* @__PURE__ */ new Map();
|
|
1680
|
-
for (const s of schemas) schemaMap.set(s.action, s);
|
|
1681
|
-
return { keywords, markers, markerPositions, sovLanguages, schemaMap };
|
|
2170
|
+
const schemaMap = /* @__PURE__ */ new Map();
|
|
2171
|
+
for (const s of schemas) schemaMap.set(s.action, s);
|
|
2172
|
+
return { keywords, markers, markerPositions, sovLanguages, schemaMap };
|
|
2173
|
+
}
|
|
2174
|
+
function renderFromSchema(node, language, tables) {
|
|
2175
|
+
const schema = tables.schemaMap.get(node.action);
|
|
2176
|
+
if (!schema) return null;
|
|
2177
|
+
const keyword = lookupKeyword(tables.keywords, node.action, language);
|
|
2178
|
+
const isSOV = tables.sovLanguages.has(language);
|
|
2179
|
+
const ordered = sortRolesByWordOrder([...schema.roles], isSOV ? "SOV" : "SVO");
|
|
2180
|
+
const preVerb = [];
|
|
2181
|
+
const postVerb = [];
|
|
2182
|
+
for (const role of ordered) {
|
|
2183
|
+
let value = (0, import_intent.extractRoleValue)(node, role.role);
|
|
2184
|
+
if (!value && role.default !== void 0) {
|
|
2185
|
+
value = String((0, import_intent.extractValue)(role.default));
|
|
2186
|
+
}
|
|
2187
|
+
if (!value) continue;
|
|
2188
|
+
if (role.quoteMultiword && /\s/.test(value) && !/^(["']).*\1$/.test(value)) {
|
|
2189
|
+
value = `"${value}"`;
|
|
2190
|
+
}
|
|
2191
|
+
const markerText = role.renderOverride?.[language] ?? role.markerOverride?.[language] ?? role.renderOverride?.["*"] ?? tables.markers[role.role]?.[language];
|
|
2192
|
+
const markerPosition = role.markerPositionOverride?.[language] ?? role.markerPosition ?? tables.markerPositions[role.role]?.[language] ?? (isSOV ? "after" : "before");
|
|
2193
|
+
const bucket = isSOV && role.sovSlot === "postVerb" ? postVerb : preVerb;
|
|
2194
|
+
if (markerText && markerPosition === "before") {
|
|
2195
|
+
bucket.push(markerText, value);
|
|
2196
|
+
} else if (markerText) {
|
|
2197
|
+
bucket.push(value, markerText);
|
|
2198
|
+
} else {
|
|
2199
|
+
bucket.push(value);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
return isSOV ? buildPhrase(...preVerb, keyword, ...postVerb) : buildPhrase(keyword, ...preVerb, ...postVerb);
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
// src/generation/schema-patterns.ts
|
|
2206
|
+
function createSchemaPatternGenerator(grammar) {
|
|
2207
|
+
return {
|
|
2208
|
+
generatePattern: (schema, profile, config) => generatePattern2(grammar, schema, profile, config),
|
|
2209
|
+
generateSimplePattern: (schema, profile, config) => generateSimplePattern(grammar, schema, profile, config),
|
|
2210
|
+
generateVerbFirstPattern: (schema, profile, config) => generateVerbFirstPattern(schema, profile, config),
|
|
2211
|
+
generatePatternVariants: (schema, profile, config) => generatePatternVariants2(grammar, schema, profile, config),
|
|
2212
|
+
buildRoleToken
|
|
2213
|
+
};
|
|
2214
|
+
}
|
|
2215
|
+
function withoutVariantOnlyRoles(schema) {
|
|
2216
|
+
return schema.roles.some((r) => r.variantOnly) ? { ...schema, roles: schema.roles.filter((r) => !r.variantOnly) } : schema;
|
|
2217
|
+
}
|
|
2218
|
+
function sortRolesByPosition(roles, wordOrder, order) {
|
|
2219
|
+
const sortKey = wordOrder === "SOV" ? "sovPosition" : "svoPosition";
|
|
2220
|
+
return [...roles].sort(
|
|
2221
|
+
(a, b) => order === "ascending" ? (a[sortKey] ?? 99) - (b[sortKey] ?? 99) : (b[sortKey] ?? 0) - (a[sortKey] ?? 0)
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
function resolveMarkerForRole(roleSpec, profile) {
|
|
2225
|
+
const overrideMarker = roleSpec.markerOverride?.[profile.code];
|
|
2226
|
+
const defaultMarker = profile.roleMarkers[roleSpec.role];
|
|
2227
|
+
if (overrideMarker !== void 0) {
|
|
2228
|
+
const alternatives = legacyMarkerAlternatives(roleSpec, profile.code, overrideMarker);
|
|
2229
|
+
return {
|
|
2230
|
+
primary: overrideMarker,
|
|
2231
|
+
...alternatives && { alternatives },
|
|
2232
|
+
position: defaultMarker?.position ?? "before",
|
|
2233
|
+
isOverride: true
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
if (defaultMarker && defaultMarker.primary) {
|
|
2237
|
+
const result = {
|
|
2238
|
+
primary: defaultMarker.primary,
|
|
2239
|
+
position: defaultMarker.position,
|
|
2240
|
+
isOverride: false
|
|
2241
|
+
};
|
|
2242
|
+
if (defaultMarker.alternatives) {
|
|
2243
|
+
result.alternatives = defaultMarker.alternatives;
|
|
2244
|
+
}
|
|
2245
|
+
return result;
|
|
2246
|
+
}
|
|
2247
|
+
return null;
|
|
2248
|
+
}
|
|
2249
|
+
function legacyMarkerAlternatives(roleSpec, languageCode, overrideMarker) {
|
|
2250
|
+
const legacy = roleSpec.markerLegacy?.[languageCode];
|
|
2251
|
+
if (!legacy?.length) return void 0;
|
|
2252
|
+
const alternatives = [...new Set(legacy)].filter((a) => a && a !== overrideMarker);
|
|
2253
|
+
return alternatives.length ? alternatives : void 0;
|
|
2254
|
+
}
|
|
2255
|
+
function schemaMarkerAlternatives(roleSpec, languageCode, marker) {
|
|
2256
|
+
const legacy = roleSpec.markerLegacy?.[languageCode] ?? [];
|
|
2257
|
+
const variants = roleSpec.methodCarrier ? [] : roleSpec.markerVariants?.[languageCode] ?? [];
|
|
2258
|
+
const alternatives = [.../* @__PURE__ */ new Set([...legacy, ...variants])].filter((a) => a && a !== marker);
|
|
2259
|
+
return alternatives.length ? alternatives : void 0;
|
|
2260
|
+
}
|
|
2261
|
+
var defaultConfig2 = {
|
|
2262
|
+
basePriority: 100,
|
|
2263
|
+
generateSimpleVariants: true,
|
|
2264
|
+
generateAlternatives: true
|
|
2265
|
+
};
|
|
2266
|
+
function generatePattern2(grammar, schema, profile, config = defaultConfig2) {
|
|
2267
|
+
const id = `${schema.action}-${profile.code}-generated`;
|
|
2268
|
+
const priority = config.basePriority ?? 100;
|
|
2269
|
+
const keyword = profile.keywords[schema.action];
|
|
2270
|
+
if (!keyword) {
|
|
2271
|
+
throw new Error(`No keyword translation for '${schema.action}' in ${profile.code}`);
|
|
2272
|
+
}
|
|
2273
|
+
const tokens = buildTokens2(grammar, schema, profile, keyword);
|
|
2274
|
+
const extraction = buildExtractionRulesWithDefaults(schema, profile);
|
|
2275
|
+
const format = buildFormatString2(grammar, schema, profile, keyword);
|
|
2276
|
+
return {
|
|
2277
|
+
id,
|
|
2278
|
+
language: profile.code,
|
|
2279
|
+
command: schema.action,
|
|
2280
|
+
priority,
|
|
2281
|
+
template: {
|
|
2282
|
+
format,
|
|
2283
|
+
tokens
|
|
2284
|
+
},
|
|
2285
|
+
extraction
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
function generateSimplePattern(grammar, schema, profile, config = defaultConfig2) {
|
|
2289
|
+
const optionalRoles = schema.roles.filter((r) => !r.required);
|
|
2290
|
+
if (optionalRoles.length === 0) {
|
|
2291
|
+
return null;
|
|
2292
|
+
}
|
|
2293
|
+
const requiredRoles = schema.roles.filter((r) => r.required);
|
|
2294
|
+
const simpleSchema = {
|
|
2295
|
+
...schema,
|
|
2296
|
+
roles: requiredRoles
|
|
2297
|
+
};
|
|
2298
|
+
const pattern = generatePattern2(grammar, simpleSchema, profile, config);
|
|
2299
|
+
return {
|
|
2300
|
+
...pattern,
|
|
2301
|
+
id: `${schema.action}-${profile.code}-generated-simple`,
|
|
2302
|
+
priority: (config.basePriority ?? 100) - 5,
|
|
2303
|
+
// Lower priority than full pattern (was -10)
|
|
2304
|
+
extraction: buildExtractionRulesWithDefaults(schema, profile)
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
function generateVerbFirstPattern(schema, profile, config = defaultConfig2) {
|
|
2308
|
+
if (profile.wordOrder !== "SOV") return null;
|
|
2309
|
+
const requiredRoles = schema.roles.filter((r) => r.required);
|
|
2310
|
+
if (requiredRoles.length !== 1) return null;
|
|
2311
|
+
const keyword = profile.keywords[schema.action];
|
|
2312
|
+
if (!keyword) return null;
|
|
2313
|
+
const verbToken = keyword.alternatives ? { type: "literal", value: keyword.primary, alternatives: keyword.alternatives } : { type: "literal", value: keyword.primary };
|
|
2314
|
+
const roleTokens = requiredRoles.flatMap((r) => {
|
|
2315
|
+
const prefix = r.valuePrefixLiteral?.[profile.code];
|
|
2316
|
+
const roleToken = {
|
|
2317
|
+
type: "role",
|
|
2318
|
+
role: r.role,
|
|
2319
|
+
optional: false,
|
|
2320
|
+
expectedTypes: r.expectedTypes
|
|
2321
|
+
};
|
|
2322
|
+
return prefix ? [{ type: "literal", value: prefix }, roleToken] : [roleToken];
|
|
2323
|
+
});
|
|
2324
|
+
return {
|
|
2325
|
+
id: `${schema.action}-${profile.code}-generated-verb-first`,
|
|
2326
|
+
language: profile.code,
|
|
2327
|
+
command: schema.action,
|
|
2328
|
+
// Strictly below the canonical (basePriority) and simple (basePriority - 5)
|
|
2329
|
+
// patterns so native order is always preferred.
|
|
2330
|
+
priority: (config.basePriority ?? 100) - 20,
|
|
2331
|
+
template: {
|
|
2332
|
+
format: `${keyword.primary} <${requiredRoles[0].role}>`,
|
|
2333
|
+
tokens: [verbToken, ...roleTokens]
|
|
2334
|
+
},
|
|
2335
|
+
extraction: buildExtractionRulesWithDefaults(schema, profile)
|
|
2336
|
+
};
|
|
2337
|
+
}
|
|
2338
|
+
function generatePatternVariants2(grammar, schema, profile, config = defaultConfig2) {
|
|
2339
|
+
const patterns = [];
|
|
2340
|
+
const full = schema;
|
|
2341
|
+
schema = withoutVariantOnlyRoles(schema);
|
|
2342
|
+
patterns.push(generatePattern2(grammar, schema, profile, config));
|
|
2343
|
+
if (config.generateSimpleVariants) {
|
|
2344
|
+
const simple = generateSimplePattern(grammar, schema, profile, config);
|
|
2345
|
+
if (simple) {
|
|
2346
|
+
patterns.push(simple);
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
for (const omitted of schema.omitRoleVariants ?? []) {
|
|
2350
|
+
const variantSchema = {
|
|
2351
|
+
...schema,
|
|
2352
|
+
roles: schema.roles.filter((r) => r.role !== omitted)
|
|
2353
|
+
};
|
|
2354
|
+
const variant = generatePattern2(grammar, variantSchema, profile, config);
|
|
2355
|
+
patterns.push({
|
|
2356
|
+
...variant,
|
|
2357
|
+
id: `${schema.action}-${profile.code}-generated-no-${omitted}`,
|
|
2358
|
+
priority: (config.basePriority ?? 100) - 8
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
for (const widen of schema.widenTypeVariants ?? []) {
|
|
2362
|
+
if (widen.excludeLanguages?.includes(profile.code)) continue;
|
|
2363
|
+
const cloneSchema = {
|
|
2364
|
+
...schema,
|
|
2365
|
+
roles: schema.roles.map(
|
|
2366
|
+
(r) => r.role === widen.role ? { ...r, expectedTypes: [...widen.types] } : r
|
|
2367
|
+
)
|
|
2368
|
+
};
|
|
2369
|
+
const main = generatePattern2(grammar, cloneSchema, profile, config);
|
|
2370
|
+
patterns.push({
|
|
2371
|
+
...main,
|
|
2372
|
+
id: `${schema.action}-${profile.code}-generated-${widen.idSuffix}`,
|
|
2373
|
+
priority: (config.basePriority ?? 100) - (widen.priorityDelta ?? 15)
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
for (const v of full.requiredRoleVariants ?? []) {
|
|
2377
|
+
const variantSchema = {
|
|
2378
|
+
...full,
|
|
2379
|
+
roles: full.roles.filter((r) => !v.omit?.includes(r.role)).map((r) => {
|
|
2380
|
+
const required = r.role === v.role ? { ...r, required: true } : r;
|
|
2381
|
+
return r.role === v.widen?.role ? { ...required, expectedTypes: [...v.widen.types] } : required;
|
|
2382
|
+
})
|
|
2383
|
+
};
|
|
2384
|
+
const variant = generatePattern2(grammar, variantSchema, profile, config);
|
|
2385
|
+
patterns.push({
|
|
2386
|
+
...variant,
|
|
2387
|
+
id: `${schema.action}-${profile.code}-generated-${v.idSuffix}`,
|
|
2388
|
+
priority: (config.basePriority ?? 100) + (v.priorityDelta ?? 5)
|
|
2389
|
+
});
|
|
2390
|
+
}
|
|
2391
|
+
if (config.generateVerbFirstVariants !== false) {
|
|
2392
|
+
const verbFirst = generateVerbFirstPattern(schema, profile, config);
|
|
2393
|
+
if (verbFirst) {
|
|
2394
|
+
patterns.push(verbFirst);
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
for (const v of schema.rolePrefixLiteralVariants ?? []) {
|
|
2398
|
+
const literal = v.literal[profile.code];
|
|
2399
|
+
if (!literal) continue;
|
|
2400
|
+
const { rolePrefixLiteralVariants: _omitted, ...baseSchema } = schema;
|
|
2401
|
+
const cloneSchema = {
|
|
2402
|
+
...baseSchema,
|
|
2403
|
+
roles: schema.roles.map(
|
|
2404
|
+
(r) => r.role === v.role ? { ...r, valuePrefixLiteral: { [profile.code]: literal } } : r
|
|
2405
|
+
)
|
|
2406
|
+
};
|
|
2407
|
+
const delta = v.priorityDelta ?? 5;
|
|
2408
|
+
const carrier = v.methodCarrier ? { [v.methodCarrier]: { value: literal } } : {};
|
|
2409
|
+
const main = generatePattern2(grammar, cloneSchema, profile, config);
|
|
2410
|
+
patterns.push({
|
|
2411
|
+
...main,
|
|
2412
|
+
id: `${schema.action}-${profile.code}-generated-${v.idSuffix}`,
|
|
2413
|
+
priority: (config.basePriority ?? 100) + delta,
|
|
2414
|
+
extraction: { ...main.extraction, ...carrier }
|
|
2415
|
+
});
|
|
2416
|
+
if (config.generateVerbFirstVariants !== false) {
|
|
2417
|
+
const verbFirstUrl = generateVerbFirstPattern(cloneSchema, profile, config);
|
|
2418
|
+
if (verbFirstUrl) {
|
|
2419
|
+
patterns.push({
|
|
2420
|
+
...verbFirstUrl,
|
|
2421
|
+
id: `${schema.action}-${profile.code}-generated-verb-first-${v.idSuffix}`,
|
|
2422
|
+
priority: (config.basePriority ?? 100) - 20 + delta,
|
|
2423
|
+
extraction: { ...verbFirstUrl.extraction, ...carrier }
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
return patterns;
|
|
2429
|
+
}
|
|
2430
|
+
function buildTokens2(grammar, schema, profile, keyword) {
|
|
2431
|
+
const tokens = [];
|
|
2432
|
+
const verbToken = keyword.alternatives ? { type: "literal", value: keyword.primary, alternatives: keyword.alternatives } : { type: "literal", value: keyword.primary };
|
|
2433
|
+
const postVerbRoles = profile.wordOrder === "SOV" ? schema.roles.filter((r) => r.sovSlot === "postVerb") : [];
|
|
2434
|
+
const roleTokens = buildRoleTokens(
|
|
2435
|
+
grammar,
|
|
2436
|
+
postVerbRoles.length ? { ...schema, roles: schema.roles.filter((r) => r.sovSlot !== "postVerb") } : schema,
|
|
2437
|
+
profile
|
|
2438
|
+
);
|
|
2439
|
+
const postVerbTokens = postVerbRoles.length ? buildRoleTokens(grammar, { ...schema, roles: postVerbRoles }, profile) : [];
|
|
2440
|
+
switch (profile.wordOrder) {
|
|
2441
|
+
case "SVO":
|
|
2442
|
+
tokens.push(verbToken);
|
|
2443
|
+
tokens.push(...roleTokens);
|
|
2444
|
+
break;
|
|
2445
|
+
case "SOV":
|
|
2446
|
+
tokens.push(...roleTokens);
|
|
2447
|
+
tokens.push(verbToken);
|
|
2448
|
+
tokens.push(...postVerbTokens);
|
|
2449
|
+
break;
|
|
2450
|
+
case "VSO":
|
|
2451
|
+
tokens.push(verbToken);
|
|
2452
|
+
tokens.push(...roleTokens);
|
|
2453
|
+
break;
|
|
2454
|
+
default:
|
|
2455
|
+
tokens.push(verbToken);
|
|
2456
|
+
tokens.push(...roleTokens);
|
|
2457
|
+
}
|
|
2458
|
+
return collapseAdjacentLiterals(tokens);
|
|
2459
|
+
}
|
|
2460
|
+
function collapseAdjacentLiterals(tokens) {
|
|
2461
|
+
const out = [];
|
|
2462
|
+
for (const tok of tokens) {
|
|
2463
|
+
const prev = out[out.length - 1];
|
|
2464
|
+
if (prev && prev.type === "literal" && tok.type === "literal" && prev.value === tok.value) {
|
|
2465
|
+
const alts = [...prev.alternatives ?? [], ...tok.alternatives ?? []];
|
|
2466
|
+
if (alts.length) out[out.length - 1] = { ...prev, alternatives: [...new Set(alts)] };
|
|
2467
|
+
continue;
|
|
2468
|
+
}
|
|
2469
|
+
out.push(tok);
|
|
2470
|
+
}
|
|
2471
|
+
return out;
|
|
2472
|
+
}
|
|
2473
|
+
function buildRoleTokens(grammar, schema, profile) {
|
|
2474
|
+
const tokens = [];
|
|
2475
|
+
const sortedRoles = sortRolesByPosition(schema.roles, profile.wordOrder, grammar.positionOrder);
|
|
2476
|
+
for (const roleSpec of sortedRoles) {
|
|
2477
|
+
const roleToken = buildRoleToken(roleSpec, profile);
|
|
2478
|
+
if (!roleSpec.required) {
|
|
2479
|
+
tokens.push({
|
|
2480
|
+
type: "group",
|
|
2481
|
+
optional: true,
|
|
2482
|
+
tokens: roleToken
|
|
2483
|
+
});
|
|
2484
|
+
} else {
|
|
2485
|
+
tokens.push(...roleToken);
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
return tokens;
|
|
2489
|
+
}
|
|
2490
|
+
function buildRoleToken(roleSpec, profile) {
|
|
2491
|
+
const tokens = [];
|
|
2492
|
+
const overrideMarker = roleSpec.markerOverride?.[profile.code];
|
|
2493
|
+
const defaultMarker = profile.roleMarkers[roleSpec.role];
|
|
2494
|
+
const suppressMarker = roleSpec.renderOverride?.[profile.code] === "";
|
|
2495
|
+
const roleValueToken = {
|
|
2496
|
+
type: "role",
|
|
2497
|
+
role: roleSpec.role,
|
|
2498
|
+
optional: !roleSpec.required,
|
|
2499
|
+
expectedTypes: roleSpec.expectedTypes,
|
|
2500
|
+
// The matcher reads this too — a `'keyword'`-shaped slot holds a fixed
|
|
2501
|
+
// keyword phrase (`using view transition`) and must not be skipped by the
|
|
2502
|
+
// trailing-slot verb guard.
|
|
2503
|
+
...roleSpec.valueShape !== void 0 ? { valueShape: roleSpec.valueShape } : {},
|
|
2504
|
+
// A greedy role reads up to the next marker the pattern owes (a domain's
|
|
2505
|
+
// SQL condition); its value reader does the reading.
|
|
2506
|
+
...roleSpec.greedy ? { greedy: true } : {}
|
|
2507
|
+
};
|
|
2508
|
+
const prefixLiteral = roleSpec.valuePrefixLiteral?.[profile.code];
|
|
2509
|
+
const pushPrefixed = () => {
|
|
2510
|
+
if (prefixLiteral) tokens.push({ type: "literal", value: prefixLiteral });
|
|
2511
|
+
tokens.push(roleValueToken);
|
|
2512
|
+
};
|
|
2513
|
+
if (overrideMarker !== void 0) {
|
|
2514
|
+
const markerWords = overrideMarker ? overrideMarker.split(/\s+/).filter(Boolean) : [];
|
|
2515
|
+
const isPassthroughOverride = overrideMarker !== void 0 && overrideMarker === roleSpec.markerOverride?.en;
|
|
2516
|
+
const position = roleSpec.markerPositionOverride?.[profile.code] ?? roleSpec.markerPosition ?? defaultMarker?.position ?? (profile.wordOrder === "SOV" && !isPassthroughOverride ? "after" : "before");
|
|
2517
|
+
const optionalMarker = roleSpec.markerOptional?.[profile.code] === true;
|
|
2518
|
+
const pushWord = (word) => {
|
|
2519
|
+
const alternatives = markerWords.length === 1 ? schemaMarkerAlternatives(roleSpec, profile.code, word) ?? [] : [];
|
|
2520
|
+
const literal = {
|
|
2521
|
+
type: "literal",
|
|
2522
|
+
value: word,
|
|
2523
|
+
...alternatives.length ? { alternatives } : {},
|
|
2524
|
+
...suppressMarker ? { renderSuppress: true } : {}
|
|
2525
|
+
};
|
|
2526
|
+
tokens.push(optionalMarker ? { type: "group", optional: true, tokens: [literal] } : literal);
|
|
2527
|
+
};
|
|
2528
|
+
if (position === "before") {
|
|
2529
|
+
for (const word of markerWords) pushWord(word);
|
|
2530
|
+
pushPrefixed();
|
|
2531
|
+
} else {
|
|
2532
|
+
pushPrefixed();
|
|
2533
|
+
for (const word of markerWords) pushWord(word);
|
|
2534
|
+
}
|
|
2535
|
+
} else if (defaultMarker) {
|
|
2536
|
+
const asMarker = () => {
|
|
2537
|
+
const alternatives = [
|
|
2538
|
+
.../* @__PURE__ */ new Set([
|
|
2539
|
+
...defaultMarker.alternatives ?? [],
|
|
2540
|
+
...schemaMarkerAlternatives(roleSpec, profile.code, defaultMarker.primary) ?? []
|
|
2541
|
+
])
|
|
2542
|
+
].filter((a) => a !== defaultMarker.primary);
|
|
2543
|
+
return {
|
|
2544
|
+
type: "literal",
|
|
2545
|
+
value: defaultMarker.primary,
|
|
2546
|
+
...alternatives.length ? { alternatives } : {},
|
|
2547
|
+
...suppressMarker ? { renderSuppress: true } : {}
|
|
2548
|
+
};
|
|
2549
|
+
};
|
|
2550
|
+
const pushMarker = (marker) => {
|
|
2551
|
+
if (!profile.markersOptional && !roleSpec.markerOptional?.[profile.code]) {
|
|
2552
|
+
tokens.push(marker);
|
|
2553
|
+
return;
|
|
2554
|
+
}
|
|
2555
|
+
tokens.push({
|
|
2556
|
+
type: "group",
|
|
2557
|
+
optional: true,
|
|
2558
|
+
...profile.markersOptional && !roleSpec.markerOptional?.[profile.code] ? { renderRequired: true } : {},
|
|
2559
|
+
tokens: [marker]
|
|
2560
|
+
});
|
|
2561
|
+
};
|
|
2562
|
+
if ((roleSpec.markerPosition ?? defaultMarker.position) === "before") {
|
|
2563
|
+
if (defaultMarker.primary) {
|
|
2564
|
+
pushMarker(asMarker());
|
|
2565
|
+
}
|
|
2566
|
+
pushPrefixed();
|
|
2567
|
+
} else {
|
|
2568
|
+
pushPrefixed();
|
|
2569
|
+
pushMarker(asMarker());
|
|
2570
|
+
}
|
|
2571
|
+
} else {
|
|
2572
|
+
pushPrefixed();
|
|
2573
|
+
}
|
|
2574
|
+
return tokens;
|
|
2575
|
+
}
|
|
2576
|
+
function buildExtractionRules2(schema, profile) {
|
|
2577
|
+
const rules = {};
|
|
2578
|
+
for (const roleSpec of schema.roles) {
|
|
2579
|
+
const overrideMarker = roleSpec.markerOverride?.[profile.code];
|
|
2580
|
+
const defaultMarker = profile.roleMarkers[roleSpec.role];
|
|
2581
|
+
if (roleSpec.valuePrefixLiteral?.[profile.code]) {
|
|
2582
|
+
rules[roleSpec.role] = { marker: roleSpec.valuePrefixLiteral[profile.code] };
|
|
2583
|
+
} else if (overrideMarker !== void 0) {
|
|
2584
|
+
if (!overrideMarker) {
|
|
2585
|
+
rules[roleSpec.role] = {};
|
|
2586
|
+
} else {
|
|
2587
|
+
const isSingleWord = !/\s/.test(overrideMarker.trim());
|
|
2588
|
+
const markerAlternatives = isSingleWord ? schemaMarkerAlternatives(roleSpec, profile.code, overrideMarker) ?? [] : [];
|
|
2589
|
+
rules[roleSpec.role] = markerAlternatives.length ? { marker: overrideMarker, markerAlternatives } : { marker: overrideMarker };
|
|
2590
|
+
}
|
|
2591
|
+
} else if (defaultMarker && defaultMarker.primary) {
|
|
2592
|
+
const markerAlternatives = [
|
|
2593
|
+
.../* @__PURE__ */ new Set([
|
|
2594
|
+
...defaultMarker.alternatives ?? [],
|
|
2595
|
+
...schemaMarkerAlternatives(roleSpec, profile.code, defaultMarker.primary) ?? []
|
|
2596
|
+
])
|
|
2597
|
+
].filter((a) => a !== defaultMarker.primary);
|
|
2598
|
+
rules[roleSpec.role] = markerAlternatives.length ? { marker: defaultMarker.primary, markerAlternatives } : { marker: defaultMarker.primary };
|
|
2599
|
+
} else {
|
|
2600
|
+
rules[roleSpec.role] = {};
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
return rules;
|
|
2604
|
+
}
|
|
2605
|
+
function buildExtractionRulesWithDefaults(schema, profile) {
|
|
2606
|
+
const baseRules = buildExtractionRules2(schema, profile);
|
|
2607
|
+
const rules = {};
|
|
2608
|
+
for (const roleSpec of schema.roles) {
|
|
2609
|
+
const baseRule = baseRules[roleSpec.role] || {};
|
|
2610
|
+
if (!roleSpec.required && roleSpec.default) {
|
|
2611
|
+
rules[roleSpec.role] = { ...baseRule, default: roleSpec.default };
|
|
2612
|
+
} else {
|
|
2613
|
+
rules[roleSpec.role] = baseRule;
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
return rules;
|
|
2617
|
+
}
|
|
2618
|
+
function buildFormatString2(grammar, schema, profile, keyword) {
|
|
2619
|
+
const parts = [];
|
|
2620
|
+
const sortedRoles = sortRolesByPosition(schema.roles, profile.wordOrder, grammar.positionOrder);
|
|
2621
|
+
const roleParts = sortedRoles.map((roleSpec) => {
|
|
2622
|
+
const resolved = resolveMarkerForRole(roleSpec, profile);
|
|
2623
|
+
let part = "";
|
|
2624
|
+
if (resolved && resolved.primary) {
|
|
2625
|
+
if (resolved.position === "before") {
|
|
2626
|
+
part = `${resolved.primary} {${roleSpec.role}}`;
|
|
2627
|
+
} else {
|
|
2628
|
+
part = `{${roleSpec.role}} ${resolved.primary}`;
|
|
2629
|
+
}
|
|
2630
|
+
} else {
|
|
2631
|
+
part = `{${roleSpec.role}}`;
|
|
2632
|
+
}
|
|
2633
|
+
return roleSpec.required ? part : `[${part}]`;
|
|
2634
|
+
});
|
|
2635
|
+
switch (profile.wordOrder) {
|
|
2636
|
+
case "SVO":
|
|
2637
|
+
case "VSO":
|
|
2638
|
+
parts.push(keyword.primary, ...roleParts);
|
|
2639
|
+
break;
|
|
2640
|
+
case "SOV":
|
|
2641
|
+
parts.push(...roleParts, keyword.primary);
|
|
2642
|
+
break;
|
|
2643
|
+
default:
|
|
2644
|
+
parts.push(keyword.primary, ...roleParts);
|
|
2645
|
+
}
|
|
2646
|
+
return parts.join(" ");
|
|
1682
2647
|
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
2648
|
+
|
|
2649
|
+
// src/generation/pattern-render.ts
|
|
2650
|
+
var NESTED_ROLE_BONUS = 5;
|
|
2651
|
+
var UNCOVERED_ROLE_PENALTY = 30;
|
|
2652
|
+
function pinnedLiteral(rule) {
|
|
2653
|
+
if (rule?.default?.type === "literal") return String(rule.default.value).trim().toLowerCase();
|
|
2654
|
+
if (rule?.value !== void 0) return String(rule.value).trim().toLowerCase();
|
|
2655
|
+
return void 0;
|
|
2656
|
+
}
|
|
2657
|
+
function selectRenderPattern(node, patterns, hooks) {
|
|
2658
|
+
let candidates = patterns.filter((pattern) => !pattern.parseOnly);
|
|
2659
|
+
if (candidates.length === 0) candidates = patterns;
|
|
2660
|
+
if (hooks.candidates) candidates = hooks.candidates(node, candidates);
|
|
2661
|
+
const pinnedValues = /* @__PURE__ */ new Map();
|
|
2662
|
+
for (const pattern of candidates) {
|
|
2663
|
+
for (const [role, rule] of Object.entries(pattern.extraction ?? {})) {
|
|
2664
|
+
const key = pinnedLiteral(rule);
|
|
2665
|
+
if (key === void 0) continue;
|
|
2666
|
+
const set = pinnedValues.get(role) ?? /* @__PURE__ */ new Set();
|
|
2667
|
+
set.add(key);
|
|
2668
|
+
pinnedValues.set(role, set);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
const scored = candidates.map((pattern) => {
|
|
2672
|
+
let score = pattern.priority;
|
|
2673
|
+
const hasRealRole = (role) => hooks.hasRealRole(node, role);
|
|
2674
|
+
const scoreTokens = (tokens, inGroup) => {
|
|
2675
|
+
for (const token of tokens) {
|
|
2676
|
+
if (token.type === "group") {
|
|
2677
|
+
scoreTokens(token.tokens, true);
|
|
2678
|
+
} else if (token.type === "role") {
|
|
2679
|
+
if (hasRealRole(token.role)) {
|
|
2680
|
+
score += inGroup ? NESTED_ROLE_BONUS : 10;
|
|
2681
|
+
} else if (!inGroup && !token.optional) {
|
|
2682
|
+
score -= 50;
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
scoreTokens(pattern.template.tokens, false);
|
|
2688
|
+
const slots = /* @__PURE__ */ new Set();
|
|
2689
|
+
const collectSlots = (tokens) => {
|
|
2690
|
+
for (const token of tokens) {
|
|
2691
|
+
if (token.type === "group") collectSlots(token.tokens);
|
|
2692
|
+
else if (token.type === "role") slots.add(token.role);
|
|
2693
|
+
}
|
|
2694
|
+
};
|
|
2695
|
+
collectSlots(pattern.template.tokens);
|
|
2696
|
+
for (const role of node.roles.keys()) {
|
|
2697
|
+
if (hasRealRole(role) && !slots.has(role)) score -= UNCOVERED_ROLE_PENALTY;
|
|
2698
|
+
}
|
|
2699
|
+
for (const [role, rule] of Object.entries(pattern.extraction ?? {})) {
|
|
2700
|
+
const pinnedKey = pinnedLiteral(rule);
|
|
2701
|
+
if (pinnedKey === void 0) continue;
|
|
2702
|
+
const actual = node.roles.get(role);
|
|
2703
|
+
const actualKey = actual?.type === (rule.valueIsExpression ? "expression" : "literal") ? String(
|
|
2704
|
+
actual.type === "expression" ? actual.raw : actual.value
|
|
2705
|
+
).trim().toLowerCase() : void 0;
|
|
2706
|
+
if (actualKey === pinnedKey) {
|
|
2707
|
+
score += 60;
|
|
2708
|
+
} else if (actualKey === void 0 || pinnedValues.get(role)?.has(actualKey)) {
|
|
2709
|
+
score -= 200;
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
score += hooks.adjustScore?.(pattern, node) ?? 0;
|
|
2713
|
+
return { pattern, score };
|
|
2714
|
+
});
|
|
2715
|
+
scored.sort((a, b) => b.score - a.score);
|
|
2716
|
+
return scored.length > 0 ? scored[0].pattern : null;
|
|
2717
|
+
}
|
|
2718
|
+
function renderPattern(node, pattern, hooks) {
|
|
2719
|
+
const parts = [];
|
|
2720
|
+
const language = pattern.language;
|
|
2721
|
+
const tokens = pattern.template.tokens;
|
|
2722
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
2723
|
+
hooks.beforeToken?.(tokens, i, parts, node, language);
|
|
2724
|
+
const span = hooks.span?.(tokens, i, node, language, true);
|
|
2725
|
+
if (span !== void 0) {
|
|
2726
|
+
parts.push(span.text);
|
|
2727
|
+
i += span.tokens - 1;
|
|
2728
|
+
continue;
|
|
1695
2729
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
2730
|
+
const token = tokens[i];
|
|
2731
|
+
const rendered = renderPatternToken(token, node, language, hooks);
|
|
2732
|
+
if (rendered !== null) {
|
|
2733
|
+
pushPart(hooks, parts, rendered, token, tokens[i - 1], node, language);
|
|
2734
|
+
hooks.afterToken?.(token, parts.length - 1, node);
|
|
1699
2735
|
}
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
2736
|
+
}
|
|
2737
|
+
return parts;
|
|
2738
|
+
}
|
|
2739
|
+
function pushPart(hooks, parts, text, token, previous, node, language) {
|
|
2740
|
+
if (hooks.pushPart) hooks.pushPart(parts, text, token, previous, node, language);
|
|
2741
|
+
else parts.push(text);
|
|
2742
|
+
}
|
|
2743
|
+
function renderPatternToken(token, node, language, hooks) {
|
|
2744
|
+
switch (token.type) {
|
|
2745
|
+
case "literal":
|
|
2746
|
+
return token.renderSuppress ? null : token.value;
|
|
2747
|
+
case "role":
|
|
2748
|
+
return hooks.writeRole(token, node, language);
|
|
2749
|
+
case "group": {
|
|
2750
|
+
const hasRequired = token.tokens.filter((t) => t.type === "role" && !t.optional).every((t) => node.roles.has(t.role));
|
|
2751
|
+
if (!hasRequired && token.optional) {
|
|
2752
|
+
return null;
|
|
2753
|
+
}
|
|
2754
|
+
if (hooks.writeGroup && !hooks.writeGroup(token, node, language)) return null;
|
|
2755
|
+
const groupParts = [];
|
|
2756
|
+
let hasRoleValue = false;
|
|
2757
|
+
for (let i = 0; i < token.tokens.length; i++) {
|
|
2758
|
+
const span = hooks.span?.(token.tokens, i, node, language, false);
|
|
2759
|
+
if (span !== void 0) {
|
|
2760
|
+
groupParts.push(span.text);
|
|
2761
|
+
hasRoleValue = true;
|
|
2762
|
+
i += span.tokens - 1;
|
|
2763
|
+
continue;
|
|
2764
|
+
}
|
|
2765
|
+
const subToken = token.tokens[i];
|
|
2766
|
+
const rendered = renderPatternToken(subToken, node, language, hooks);
|
|
2767
|
+
if (rendered !== null) {
|
|
2768
|
+
pushPart(hooks, groupParts, rendered, subToken, token.tokens[i - 1], node, language);
|
|
2769
|
+
if (subToken.type === "role") hasRoleValue = true;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
if (token.optional && !hasRoleValue && !token.renderRequired) return null;
|
|
2773
|
+
return groupParts.length > 0 ? groupParts.join(" ") : null;
|
|
1709
2774
|
}
|
|
2775
|
+
default:
|
|
2776
|
+
return null;
|
|
1710
2777
|
}
|
|
1711
|
-
return isSOV ? buildPhrase(...preVerb, keyword, ...postVerb) : buildPhrase(keyword, ...preVerb, ...postVerb);
|
|
1712
2778
|
}
|
|
1713
2779
|
|
|
1714
2780
|
// src/grammar/types.ts
|
|
@@ -2954,7 +4020,53 @@ function semanticValueToAST(value) {
|
|
|
2954
4020
|
}
|
|
2955
4021
|
}
|
|
2956
4022
|
|
|
4023
|
+
// src/api/reading.ts
|
|
4024
|
+
function roleValues(node) {
|
|
4025
|
+
const out = /* @__PURE__ */ new Map();
|
|
4026
|
+
for (const [role, value] of node.roles) {
|
|
4027
|
+
const v = value;
|
|
4028
|
+
out.set(role, String(v?.value ?? v?.raw ?? value));
|
|
4029
|
+
}
|
|
4030
|
+
return out;
|
|
4031
|
+
}
|
|
4032
|
+
function readingDifference(source, back) {
|
|
4033
|
+
if (back.action !== source.action) return `reads as ${back.action}`;
|
|
4034
|
+
const want = roleValues(source);
|
|
4035
|
+
const got = roleValues(back);
|
|
4036
|
+
const parts = [];
|
|
4037
|
+
for (const [role, value] of want) {
|
|
4038
|
+
if (!got.has(role)) parts.push(`${role} lost`);
|
|
4039
|
+
else if (got.get(role) !== value) parts.push(`${role}: ${value} \u2192 ${got.get(role)}`);
|
|
4040
|
+
}
|
|
4041
|
+
for (const role of got.keys()) if (!want.has(role)) parts.push(`${role} added`);
|
|
4042
|
+
return parts.join(", ");
|
|
4043
|
+
}
|
|
4044
|
+
|
|
2957
4045
|
// src/api/create-dsl.ts
|
|
4046
|
+
var UnreadInputError = class extends Error {
|
|
4047
|
+
constructor(input, language, reading, unread) {
|
|
4048
|
+
super(`"${input}" (${language}) reads as ${reading.action} only by leaving "${unread}" unread`);
|
|
4049
|
+
this.input = input;
|
|
4050
|
+
this.language = language;
|
|
4051
|
+
this.reading = reading;
|
|
4052
|
+
this.unread = unread;
|
|
4053
|
+
this.code = "unread-input";
|
|
4054
|
+
this.name = "UnreadInputError";
|
|
4055
|
+
}
|
|
4056
|
+
};
|
|
4057
|
+
var TranslationReadBackError = class extends Error {
|
|
4058
|
+
constructor(partial, from, to, source, reading, why) {
|
|
4059
|
+
super(`translation ${from} \u2192 ${to} does not read back as the source (${why}): "${partial}"`);
|
|
4060
|
+
this.partial = partial;
|
|
4061
|
+
this.from = from;
|
|
4062
|
+
this.to = to;
|
|
4063
|
+
this.source = source;
|
|
4064
|
+
this.reading = reading;
|
|
4065
|
+
this.why = why;
|
|
4066
|
+
this.code = "translation-does-not-read-back";
|
|
4067
|
+
this.name = "TranslationReadBackError";
|
|
4068
|
+
}
|
|
4069
|
+
};
|
|
2958
4070
|
var DSLRegistry = class {
|
|
2959
4071
|
/**
|
|
2960
4072
|
* @param partiallyTranslatedActions Actions permitted to lack a keyword in
|
|
@@ -2962,7 +4074,8 @@ var DSLRegistry = class {
|
|
|
2962
4074
|
* subset of the DSL's languages. A built-in command missing a keyword stays
|
|
2963
4075
|
* an error, since that is a domain-authoring mistake.
|
|
2964
4076
|
*/
|
|
2965
|
-
constructor(config, partiallyTranslatedActions
|
|
4077
|
+
constructor(config, partiallyTranslatedActions, generate) {
|
|
4078
|
+
this.generate = generate;
|
|
2966
4079
|
this.patterns = /* @__PURE__ */ new Map();
|
|
2967
4080
|
this.tokenizers = /* @__PURE__ */ new Map();
|
|
2968
4081
|
this.schemas = config.schemas;
|
|
@@ -2978,7 +4091,7 @@ var DSLRegistry = class {
|
|
|
2978
4091
|
if (this.partiallyTranslatedActions.has(schema.action) && !lang.patternProfile.keywords[schema.action]) {
|
|
2979
4092
|
continue;
|
|
2980
4093
|
}
|
|
2981
|
-
const pattern =
|
|
4094
|
+
const pattern = this.generate(schema, lang.patternProfile);
|
|
2982
4095
|
patterns.push(pattern);
|
|
2983
4096
|
}
|
|
2984
4097
|
this.patterns.set(lang.code, patterns);
|
|
@@ -2994,9 +4107,9 @@ var DSLRegistry = class {
|
|
|
2994
4107
|
}
|
|
2995
4108
|
};
|
|
2996
4109
|
var MultilingualDSLImpl = class {
|
|
2997
|
-
constructor(config, registry, transformer, profileProvider) {
|
|
4110
|
+
constructor(config, registry, transformer, profileProvider, engine) {
|
|
2998
4111
|
this.registry = registry;
|
|
2999
|
-
this.
|
|
4112
|
+
this.match = engine.match;
|
|
3000
4113
|
this.transformer = transformer;
|
|
3001
4114
|
this.profileProvider = profileProvider;
|
|
3002
4115
|
if (config.codeGenerator) {
|
|
@@ -3009,10 +4122,7 @@ var MultilingualDSLImpl = class {
|
|
|
3009
4122
|
for (const extension of config.extensions ?? []) {
|
|
3010
4123
|
if (extension.render) this.extensionRenderers.set(extension.schema.action, extension.render);
|
|
3011
4124
|
}
|
|
3012
|
-
this.schemaFallbackRenderer =
|
|
3013
|
-
schemas: config.schemas,
|
|
3014
|
-
profiles: config.languages.map((l) => l.patternProfile)
|
|
3015
|
-
});
|
|
4125
|
+
this.schemaFallbackRenderer = engine.fallbackRenderer(config, registry);
|
|
3016
4126
|
const schemaMap = new Map(config.schemas.map((s) => [s.action, s]));
|
|
3017
4127
|
this.schemaLookup = {
|
|
3018
4128
|
getSchema: (action) => schemaMap.get(action)
|
|
@@ -3036,28 +4146,50 @@ var MultilingualDSLImpl = class {
|
|
|
3036
4146
|
}
|
|
3037
4147
|
const tokens = tokenizer.tokenize(input);
|
|
3038
4148
|
const patterns = this.registry.getPatterns(language);
|
|
3039
|
-
const
|
|
3040
|
-
|
|
3041
|
-
|
|
4149
|
+
const total = tokens.tokens.length;
|
|
4150
|
+
let best = null;
|
|
4151
|
+
let longestPartial = null;
|
|
3042
4152
|
for (const pattern of patterns) {
|
|
3043
|
-
const
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
sourceText: input,
|
|
3052
|
-
patternId: pattern.id,
|
|
3053
|
-
confidence: match.confidence
|
|
3054
|
-
}
|
|
3055
|
-
};
|
|
3056
|
-
return { node, confidence: match.confidence };
|
|
4153
|
+
const mark = tokens.mark();
|
|
4154
|
+
const match = this.match(tokens, pattern, language);
|
|
4155
|
+
tokens.reset(mark);
|
|
4156
|
+
if (!match) continue;
|
|
4157
|
+
if (match.consumedTokens < total) {
|
|
4158
|
+
if (!longestPartial || match.consumedTokens > longestPartial.consumedTokens)
|
|
4159
|
+
longestPartial = match;
|
|
4160
|
+
continue;
|
|
3057
4161
|
}
|
|
4162
|
+
if (!best || match.pattern.priority > best.pattern.priority || match.pattern.priority === best.pattern.priority && match.confidence > best.confidence + 1e-3)
|
|
4163
|
+
best = match;
|
|
4164
|
+
}
|
|
4165
|
+
if (best) {
|
|
4166
|
+
const node = this.nodeOf(best, input, language);
|
|
4167
|
+
return { node, confidence: best.confidence };
|
|
4168
|
+
}
|
|
4169
|
+
if (longestPartial) {
|
|
4170
|
+
const unread = tokens.tokens.slice(longestPartial.consumedTokens).map((t) => t.value).join(" ");
|
|
4171
|
+
throw new UnreadInputError(
|
|
4172
|
+
input,
|
|
4173
|
+
language,
|
|
4174
|
+
this.nodeOf(longestPartial, input, language),
|
|
4175
|
+
unread
|
|
4176
|
+
);
|
|
3058
4177
|
}
|
|
3059
4178
|
throw new Error(`No pattern matched for input: ${input}`);
|
|
3060
4179
|
}
|
|
4180
|
+
nodeOf(match, input, language) {
|
|
4181
|
+
return {
|
|
4182
|
+
kind: "command",
|
|
4183
|
+
action: match.pattern.command,
|
|
4184
|
+
roles: match.captured,
|
|
4185
|
+
metadata: {
|
|
4186
|
+
sourceLanguage: language,
|
|
4187
|
+
sourceText: input,
|
|
4188
|
+
patternId: match.pattern.id,
|
|
4189
|
+
confidence: match.confidence
|
|
4190
|
+
}
|
|
4191
|
+
};
|
|
4192
|
+
}
|
|
3061
4193
|
validate(input, language) {
|
|
3062
4194
|
try {
|
|
3063
4195
|
const result = this.parseWithConfidence(input, language);
|
|
@@ -3068,11 +4200,12 @@ var MultilingualDSLImpl = class {
|
|
|
3068
4200
|
} catch (error) {
|
|
3069
4201
|
return {
|
|
3070
4202
|
valid: false,
|
|
3071
|
-
errors: [error instanceof Error ? error.message : String(error)]
|
|
4203
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
4204
|
+
...error instanceof UnreadInputError ? { errorCode: error.code } : {}
|
|
3072
4205
|
};
|
|
3073
4206
|
}
|
|
3074
4207
|
}
|
|
3075
|
-
translate(input, fromLanguage, toLanguage) {
|
|
4208
|
+
translate(input, fromLanguage, toLanguage, options) {
|
|
3076
4209
|
if ((0, import_intent3.isExplicitSyntax)(input)) return input;
|
|
3077
4210
|
let node;
|
|
3078
4211
|
try {
|
|
@@ -3084,14 +4217,46 @@ var MultilingualDSLImpl = class {
|
|
|
3084
4217
|
throw parseError;
|
|
3085
4218
|
}
|
|
3086
4219
|
const rendered = this.registry.getSupportedLanguages().includes(toLanguage) ? this.render(node, toLanguage) : null;
|
|
3087
|
-
if (rendered != null) return rendered;
|
|
4220
|
+
if (rendered != null) return this.readsBack(rendered, node, fromLanguage, toLanguage, options);
|
|
3088
4221
|
if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
|
|
3089
|
-
return this.
|
|
4222
|
+
return this.readsBack(
|
|
4223
|
+
this.transformer.transform(input, fromLanguage, toLanguage),
|
|
4224
|
+
node,
|
|
4225
|
+
fromLanguage,
|
|
4226
|
+
toLanguage,
|
|
4227
|
+
options
|
|
4228
|
+
);
|
|
3090
4229
|
}
|
|
3091
4230
|
throw new Error(
|
|
3092
4231
|
`translate() could not render action "${node.action}" in language "${toLanguage}": no custom renderer, domain renderer, or schema pattern covers it, and no grammar profile is configured for the transformer fallback. Either add "${toLanguage}" to the DSL's languages/renderer, or set 'grammarProfile' on its LanguageConfig in createMultilingualDSL() (parse/validate/compile do not need it).`
|
|
3093
4232
|
);
|
|
3094
4233
|
}
|
|
4234
|
+
/**
|
|
4235
|
+
* `rendered`, read in `to`, must be `source`: the same action and role values, or, when the DSL
|
|
4236
|
+
* compiles, the same code (a parser may keep a translated word its generator normalizes: bdd ja
|
|
4237
|
+
* `表示` is `visible`). The rule is the domain gate's (lokascript-domains). A translation used to be
|
|
4238
|
+
* returned whatever it read as: ja/ko bdd `select` dropped its value, and nothing said so.
|
|
4239
|
+
*/
|
|
4240
|
+
readsBack(rendered, source, from, to, options) {
|
|
4241
|
+
if (options?.lossy === "allow") return rendered;
|
|
4242
|
+
let back;
|
|
4243
|
+
try {
|
|
4244
|
+
back = this.parseWithConfidence(rendered, to).node;
|
|
4245
|
+
} catch (error) {
|
|
4246
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
4247
|
+
throw new TranslationReadBackError(rendered, from, to, source, null, why);
|
|
4248
|
+
}
|
|
4249
|
+
const difference = readingDifference(source, back);
|
|
4250
|
+
if (!difference) return rendered;
|
|
4251
|
+
if (this.codeGenerator) {
|
|
4252
|
+
try {
|
|
4253
|
+
if (this.codeGenerator.generate(back) === this.codeGenerator.generate(source))
|
|
4254
|
+
return rendered;
|
|
4255
|
+
} catch {
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
throw new TranslationReadBackError(rendered, from, to, source, back, difference);
|
|
4259
|
+
}
|
|
3095
4260
|
hasGrammarProfile(language) {
|
|
3096
4261
|
return this.profileProvider.getProfile(language) != null;
|
|
3097
4262
|
}
|
|
@@ -3117,7 +4282,8 @@ var MultilingualDSLImpl = class {
|
|
|
3117
4282
|
} catch (error) {
|
|
3118
4283
|
return {
|
|
3119
4284
|
ok: false,
|
|
3120
|
-
errors: [error instanceof Error ? error.message : String(error)]
|
|
4285
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
4286
|
+
...error instanceof UnreadInputError ? { errorCode: error.code } : {}
|
|
3121
4287
|
};
|
|
3122
4288
|
}
|
|
3123
4289
|
}
|
|
@@ -3229,8 +4395,76 @@ function createMultilingualDSL(config) {
|
|
|
3229
4395
|
dictionary,
|
|
3230
4396
|
profileProvider
|
|
3231
4397
|
});
|
|
3232
|
-
const
|
|
3233
|
-
|
|
4398
|
+
const engine = engineFor(config);
|
|
4399
|
+
const registry = new DSLRegistry(effectiveConfig, extensionActions, engine.generate);
|
|
4400
|
+
return new MultilingualDSLImpl(effectiveConfig, registry, transformer, profileProvider, engine);
|
|
4401
|
+
}
|
|
4402
|
+
function engineFor(config) {
|
|
4403
|
+
const name = config.engine ?? "classic";
|
|
4404
|
+
if (name === "classic") return classicEngine();
|
|
4405
|
+
if (name === "core") return coreEngine();
|
|
4406
|
+
throw new Error(`Unknown DSL engine "${String(name)}" (expected "classic" or "core")`);
|
|
4407
|
+
}
|
|
4408
|
+
function classicEngine() {
|
|
4409
|
+
const matcher = new PatternMatcher();
|
|
4410
|
+
return {
|
|
4411
|
+
generate: (schema, profile) => generatePattern(schema, profile),
|
|
4412
|
+
match: (tokens, pattern, language) => matcher.matchPattern(tokens, pattern, { code: language }),
|
|
4413
|
+
fallbackRenderer: (config) => createDomainRenderer({
|
|
4414
|
+
schemas: config.schemas,
|
|
4415
|
+
profiles: config.languages.map((l) => l.patternProfile)
|
|
4416
|
+
})
|
|
4417
|
+
};
|
|
4418
|
+
}
|
|
4419
|
+
function schemaProfileOf(profile) {
|
|
4420
|
+
const side = profile.wordOrder === "SOV" ? "after" : "before";
|
|
4421
|
+
const roleMarkers = {};
|
|
4422
|
+
for (const [role, marker] of Object.entries(profile.roleMarkers ?? {})) {
|
|
4423
|
+
roleMarkers[role] = {
|
|
4424
|
+
primary: marker.primary,
|
|
4425
|
+
...marker.alternatives ? { alternatives: marker.alternatives } : {},
|
|
4426
|
+
position: marker.position ?? side
|
|
4427
|
+
};
|
|
4428
|
+
}
|
|
4429
|
+
return {
|
|
4430
|
+
code: profile.code,
|
|
4431
|
+
wordOrder: profile.wordOrder,
|
|
4432
|
+
keywords: profile.keywords,
|
|
4433
|
+
roleMarkers
|
|
4434
|
+
};
|
|
4435
|
+
}
|
|
4436
|
+
function coreEngine() {
|
|
4437
|
+
const generator = createSchemaPatternGenerator({ positionOrder: "descending" });
|
|
4438
|
+
const matcher = new MatchSkeleton(createStockReader(), stockConfidenceModel);
|
|
4439
|
+
return {
|
|
4440
|
+
generate: (schema, profile) => generator.generatePattern(schema, schemaProfileOf(profile)),
|
|
4441
|
+
match: (tokens, pattern) => matcher.matchPattern(tokens, pattern),
|
|
4442
|
+
fallbackRenderer: (config, registry) => {
|
|
4443
|
+
const schemas = new Map(config.schemas.map((s) => [s.action, s]));
|
|
4444
|
+
const hooks = {
|
|
4445
|
+
hasRealRole: (node, role) => {
|
|
4446
|
+
const value = node.roles.get(role);
|
|
4447
|
+
return value !== void 0 && value.implicit !== true;
|
|
4448
|
+
},
|
|
4449
|
+
writeRole: (token, node) => {
|
|
4450
|
+
if (!node.roles.has(token.role)) return null;
|
|
4451
|
+
let value = (0, import_intent.extractRoleValue)(node, token.role);
|
|
4452
|
+
const spec = schemas.get(node.action)?.roles.find((r) => r.role === token.role);
|
|
4453
|
+
if (spec?.quoteMultiword && /\s/.test(value) && !/^(["']).*\1$/.test(value)) {
|
|
4454
|
+
value = `"${value}"`;
|
|
4455
|
+
}
|
|
4456
|
+
return value || null;
|
|
4457
|
+
}
|
|
4458
|
+
};
|
|
4459
|
+
return (node, language) => {
|
|
4460
|
+
const patterns = registry.getPatterns(language).filter((p) => p.command === node.action);
|
|
4461
|
+
const pattern = selectRenderPattern(node, patterns, hooks);
|
|
4462
|
+
if (!pattern) return null;
|
|
4463
|
+
const text = renderPattern(node, pattern, hooks).join(" ");
|
|
4464
|
+
return text || null;
|
|
4465
|
+
};
|
|
4466
|
+
}
|
|
4467
|
+
};
|
|
3234
4468
|
}
|
|
3235
4469
|
|
|
3236
4470
|
// src/prompts/prompt-generator.ts
|
|
@@ -4044,6 +5278,8 @@ var DomainRegistry = class {
|
|
|
4044
5278
|
return jsonResponse({ error: `Unknown operation: ${parsed.operation}` }, true);
|
|
4045
5279
|
}
|
|
4046
5280
|
} catch (error) {
|
|
5281
|
+
if (error instanceof UnreadInputError) return unreadInputResponse(error);
|
|
5282
|
+
if (error instanceof TranslationReadBackError) return readBackResponse(error);
|
|
4047
5283
|
const message = error instanceof Error ? error.message : String(error);
|
|
4048
5284
|
return jsonResponse({ error: `${descriptor.name} tool error: ${message}` }, true);
|
|
4049
5285
|
}
|
|
@@ -4169,6 +5405,7 @@ var DomainRegistry = class {
|
|
|
4169
5405
|
ok: result.ok,
|
|
4170
5406
|
code: result.code,
|
|
4171
5407
|
errors: result.errors,
|
|
5408
|
+
...result.errorCode === "unread-input" ? { diagnostics: [UNREAD_INPUT(result.errors)] } : {},
|
|
4172
5409
|
language,
|
|
4173
5410
|
input
|
|
4174
5411
|
});
|
|
@@ -4181,6 +5418,7 @@ var DomainRegistry = class {
|
|
|
4181
5418
|
return jsonResponse({
|
|
4182
5419
|
valid: result.valid,
|
|
4183
5420
|
errors: result.errors,
|
|
5421
|
+
...result.errorCode === "unread-input" ? { diagnostics: [UNREAD_INPUT(result.errors)] } : {},
|
|
4184
5422
|
language,
|
|
4185
5423
|
[descriptor.inputLabel]: input
|
|
4186
5424
|
});
|
|
@@ -4211,7 +5449,24 @@ var DomainRegistry = class {
|
|
|
4211
5449
|
for (const [key, value] of node.roles) {
|
|
4212
5450
|
roles[key] = value;
|
|
4213
5451
|
}
|
|
5452
|
+
if (rendered != null) {
|
|
5453
|
+
let back = null;
|
|
5454
|
+
let why = "";
|
|
5455
|
+
try {
|
|
5456
|
+
back = dsl.parse(rendered, to);
|
|
5457
|
+
why = readingDifference(node, back);
|
|
5458
|
+
if (why && compiled.ok) {
|
|
5459
|
+
const again = dsl.compile(rendered, to);
|
|
5460
|
+
if (again.ok && again.code === compiled.code) why = "";
|
|
5461
|
+
}
|
|
5462
|
+
} catch (error) {
|
|
5463
|
+
why = error instanceof Error ? error.message : String(error);
|
|
5464
|
+
}
|
|
5465
|
+
if (why)
|
|
5466
|
+
return readBackResponse(new TranslationReadBackError(rendered, from, to, node, back, why));
|
|
5467
|
+
}
|
|
4214
5468
|
return jsonResponse({
|
|
5469
|
+
ok: true,
|
|
4215
5470
|
input: { [descriptor.inputLabel]: input, language: from },
|
|
4216
5471
|
...rendered != null && { rendered: { text: rendered, language: to } },
|
|
4217
5472
|
semantic: { action: node.action, roles },
|
|
@@ -4291,7 +5546,7 @@ function generateToolDefinitions(desc) {
|
|
|
4291
5546
|
case "translate":
|
|
4292
5547
|
tools.push({
|
|
4293
5548
|
name: `translate_${desc.name}`,
|
|
4294
|
-
description: `Translate ${desc.description} input between natural languages (requires 'from' and 'to' codes). Supports: ${langList}.`,
|
|
5549
|
+
description: `Translate ${desc.description} input between natural languages (requires 'from' and 'to' codes). Supports: ${langList}. A rendering that does not read back as the source is REFUSED: ok is false, the diagnostic is TRANSLATION_DOES_NOT_READ_BACK, and its text is under \`partial\`, never \`rendered\`: do not present it as the translation. Input left unread is refused as UNREAD_INPUT.`,
|
|
4295
5550
|
inputSchema: {
|
|
4296
5551
|
type: "object",
|
|
4297
5552
|
properties: {
|
|
@@ -4325,6 +5580,46 @@ function getString(args, name, defaultValue = "") {
|
|
|
4325
5580
|
const value = args[name];
|
|
4326
5581
|
return typeof value === "string" ? value : defaultValue;
|
|
4327
5582
|
}
|
|
5583
|
+
function readingOf(node) {
|
|
5584
|
+
const roles = {};
|
|
5585
|
+
for (const [key, value] of node.roles) roles[key] = value;
|
|
5586
|
+
return { action: node.action, roles };
|
|
5587
|
+
}
|
|
5588
|
+
var UNREAD_INPUT = (errors) => ({
|
|
5589
|
+
severity: "error",
|
|
5590
|
+
code: "UNREAD_INPUT",
|
|
5591
|
+
message: errors?.[0] ?? "part of the input was not read",
|
|
5592
|
+
suggestion: "Part of the input belongs to no role of the command it reads as: remove it, or quote a value of several words."
|
|
5593
|
+
});
|
|
5594
|
+
function unreadInputResponse(error) {
|
|
5595
|
+
return jsonResponse(
|
|
5596
|
+
{
|
|
5597
|
+
ok: false,
|
|
5598
|
+
unread: error.unread,
|
|
5599
|
+
reading: readingOf(error.reading),
|
|
5600
|
+
diagnostics: [UNREAD_INPUT([error.message])]
|
|
5601
|
+
},
|
|
5602
|
+
true
|
|
5603
|
+
);
|
|
5604
|
+
}
|
|
5605
|
+
function readBackResponse(error) {
|
|
5606
|
+
return jsonResponse(
|
|
5607
|
+
{
|
|
5608
|
+
ok: false,
|
|
5609
|
+
partial: error.partial,
|
|
5610
|
+
...error.reading ? { reading: readingOf(error.reading) } : {},
|
|
5611
|
+
diagnostics: [
|
|
5612
|
+
{
|
|
5613
|
+
severity: "error",
|
|
5614
|
+
code: "TRANSLATION_DOES_NOT_READ_BACK",
|
|
5615
|
+
message: error.message,
|
|
5616
|
+
suggestion: "The rendering would not mean the source in the target language: do not present `partial` as the translation."
|
|
5617
|
+
}
|
|
5618
|
+
]
|
|
5619
|
+
},
|
|
5620
|
+
true
|
|
5621
|
+
);
|
|
5622
|
+
}
|
|
4328
5623
|
function jsonResponse(data, isError) {
|
|
4329
5624
|
return {
|
|
4330
5625
|
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
@@ -4475,6 +5770,50 @@ var CrossDomainDispatcher = class {
|
|
|
4475
5770
|
}
|
|
4476
5771
|
};
|
|
4477
5772
|
|
|
5773
|
+
// src/api/translation-loss.ts
|
|
5774
|
+
var LossyTranslationError = class extends Error {
|
|
5775
|
+
constructor(partial, loss, from, to) {
|
|
5776
|
+
super(
|
|
5777
|
+
`translation ${from} \u2192 ${to} would lose part of the script (${loss.kind}): ` + loss.lost.join(", ")
|
|
5778
|
+
);
|
|
5779
|
+
this.partial = partial;
|
|
5780
|
+
this.loss = loss;
|
|
5781
|
+
this.from = from;
|
|
5782
|
+
this.to = to;
|
|
5783
|
+
this.name = "LossyTranslationError";
|
|
5784
|
+
}
|
|
5785
|
+
};
|
|
5786
|
+
function unconsumedSpans(node) {
|
|
5787
|
+
const out = [];
|
|
5788
|
+
for (const d of node.diagnostics ?? []) {
|
|
5789
|
+
if (d.code !== "unconsumed-input") continue;
|
|
5790
|
+
out.push(/"(.*)"\s*$/s.exec(d.message)?.[1] ?? d.message);
|
|
5791
|
+
}
|
|
5792
|
+
return out;
|
|
5793
|
+
}
|
|
5794
|
+
function findTranslationLoss(input, node, output, readBack, rules) {
|
|
5795
|
+
const unread = unconsumedSpans(node);
|
|
5796
|
+
if (unread.length) return { kind: "truncation", lost: unread };
|
|
5797
|
+
const unwritable = rules.unwritable?.(node) ?? [];
|
|
5798
|
+
if (unwritable.length) return { kind: "core-only", lost: unwritable };
|
|
5799
|
+
let back;
|
|
5800
|
+
try {
|
|
5801
|
+
back = readBack(output);
|
|
5802
|
+
} catch (e) {
|
|
5803
|
+
return { kind: "read-back", lost: [`the output does not read: ${e.message}`] };
|
|
5804
|
+
}
|
|
5805
|
+
const misread = unconsumedSpans(back);
|
|
5806
|
+
if (misread.length) return { kind: "read-back", lost: misread };
|
|
5807
|
+
const written = rules.written ? rules.written(node) : node;
|
|
5808
|
+
for (const difference of rules.differences) {
|
|
5809
|
+
const lost = difference(written, back);
|
|
5810
|
+
if (lost.length) return { kind: "read-back", lost };
|
|
5811
|
+
}
|
|
5812
|
+
const values = rules.missingValues?.(input, output) ?? [];
|
|
5813
|
+
if (values.length) return { kind: "invariant", lost: values };
|
|
5814
|
+
return void 0;
|
|
5815
|
+
}
|
|
5816
|
+
|
|
4478
5817
|
// src/aot/domain-scanner.ts
|
|
4479
5818
|
function buildAttributePatterns(attributes) {
|
|
4480
5819
|
const patterns = [];
|
|
@@ -4766,122 +6105,6 @@ var import_intent6 = require("@lokascript/intent");
|
|
|
4766
6105
|
// src/generation/diagnostics.ts
|
|
4767
6106
|
var import_intent7 = require("@lokascript/intent");
|
|
4768
6107
|
|
|
4769
|
-
// src/core/tokenization/token-utils.ts
|
|
4770
|
-
var TokenStreamImpl = class {
|
|
4771
|
-
constructor(tokens, language) {
|
|
4772
|
-
this.pos = 0;
|
|
4773
|
-
this.tokens = tokens;
|
|
4774
|
-
this.language = language;
|
|
4775
|
-
}
|
|
4776
|
-
peek(offset = 0) {
|
|
4777
|
-
const index = this.pos + offset;
|
|
4778
|
-
if (index < 0 || index >= this.tokens.length) {
|
|
4779
|
-
return null;
|
|
4780
|
-
}
|
|
4781
|
-
return this.tokens[index];
|
|
4782
|
-
}
|
|
4783
|
-
advance() {
|
|
4784
|
-
if (this.isAtEnd()) {
|
|
4785
|
-
throw new Error("Unexpected end of token stream");
|
|
4786
|
-
}
|
|
4787
|
-
return this.tokens[this.pos++];
|
|
4788
|
-
}
|
|
4789
|
-
isAtEnd() {
|
|
4790
|
-
return this.pos >= this.tokens.length;
|
|
4791
|
-
}
|
|
4792
|
-
mark() {
|
|
4793
|
-
return { position: this.pos };
|
|
4794
|
-
}
|
|
4795
|
-
reset(mark) {
|
|
4796
|
-
this.pos = mark.position;
|
|
4797
|
-
}
|
|
4798
|
-
position() {
|
|
4799
|
-
return this.pos;
|
|
4800
|
-
}
|
|
4801
|
-
/**
|
|
4802
|
-
* Get remaining tokens as an array.
|
|
4803
|
-
*/
|
|
4804
|
-
remaining() {
|
|
4805
|
-
return this.tokens.slice(this.pos);
|
|
4806
|
-
}
|
|
4807
|
-
/**
|
|
4808
|
-
* Consume tokens while predicate is true.
|
|
4809
|
-
*/
|
|
4810
|
-
takeWhile(predicate) {
|
|
4811
|
-
const result = [];
|
|
4812
|
-
while (!this.isAtEnd() && predicate(this.peek())) {
|
|
4813
|
-
result.push(this.advance());
|
|
4814
|
-
}
|
|
4815
|
-
return result;
|
|
4816
|
-
}
|
|
4817
|
-
/**
|
|
4818
|
-
* Skip tokens while predicate is true.
|
|
4819
|
-
*/
|
|
4820
|
-
skipWhile(predicate) {
|
|
4821
|
-
while (!this.isAtEnd() && predicate(this.peek())) {
|
|
4822
|
-
this.advance();
|
|
4823
|
-
}
|
|
4824
|
-
}
|
|
4825
|
-
};
|
|
4826
|
-
function createPosition(start, end) {
|
|
4827
|
-
return { start, end };
|
|
4828
|
-
}
|
|
4829
|
-
function createToken(valueOrParams, kind, position, normalizedOrOptions) {
|
|
4830
|
-
if (typeof valueOrParams === "object") {
|
|
4831
|
-
const { value: value2, kind: kind2, position: position2, normalized: normalized2, stem, stemConfidence, metadata } = valueOrParams;
|
|
4832
|
-
return {
|
|
4833
|
-
value: value2,
|
|
4834
|
-
kind: kind2,
|
|
4835
|
-
position: position2,
|
|
4836
|
-
...normalized2 !== void 0 && { normalized: normalized2 },
|
|
4837
|
-
...stem !== void 0 && { stem },
|
|
4838
|
-
...stemConfidence !== void 0 && { stemConfidence },
|
|
4839
|
-
...metadata !== void 0 && { metadata }
|
|
4840
|
-
};
|
|
4841
|
-
}
|
|
4842
|
-
const value = valueOrParams;
|
|
4843
|
-
if (!kind || !position) {
|
|
4844
|
-
throw new Error("createToken requires kind and position parameters");
|
|
4845
|
-
}
|
|
4846
|
-
if (typeof normalizedOrOptions === "string") {
|
|
4847
|
-
return { value, kind, position, normalized: normalizedOrOptions };
|
|
4848
|
-
}
|
|
4849
|
-
if (normalizedOrOptions) {
|
|
4850
|
-
const { normalized: normalized2, stem, stemConfidence, metadata } = normalizedOrOptions;
|
|
4851
|
-
return {
|
|
4852
|
-
value,
|
|
4853
|
-
kind,
|
|
4854
|
-
position,
|
|
4855
|
-
...normalized2 !== void 0 && { normalized: normalized2 },
|
|
4856
|
-
...stem !== void 0 && { stem },
|
|
4857
|
-
...stemConfidence !== void 0 && { stemConfidence },
|
|
4858
|
-
...metadata !== void 0 && { metadata }
|
|
4859
|
-
};
|
|
4860
|
-
}
|
|
4861
|
-
return { value, kind, position };
|
|
4862
|
-
}
|
|
4863
|
-
function isWhitespace(char) {
|
|
4864
|
-
return /\s/.test(char);
|
|
4865
|
-
}
|
|
4866
|
-
function isSelectorStart(char) {
|
|
4867
|
-
return char === "#" || char === "." || char === "[" || char === "@" || char === "*" || char === "<";
|
|
4868
|
-
}
|
|
4869
|
-
function isQuote(char) {
|
|
4870
|
-
return char === '"' || char === "'" || char === "`" || char === "\u300C" || char === "\u300D";
|
|
4871
|
-
}
|
|
4872
|
-
function isDigit(char) {
|
|
4873
|
-
return /\d/.test(char);
|
|
4874
|
-
}
|
|
4875
|
-
function stripOptionalDiacritics(word) {
|
|
4876
|
-
return word.replace(/[\u064b-\u0652\u0670]/g, "");
|
|
4877
|
-
}
|
|
4878
|
-
function isAsciiLetter(char) {
|
|
4879
|
-
return /[a-zA-Z]/.test(char);
|
|
4880
|
-
}
|
|
4881
|
-
function isAsciiIdentifierChar(char) {
|
|
4882
|
-
return /[a-zA-Z0-9_-]/.test(char);
|
|
4883
|
-
}
|
|
4884
|
-
|
|
4885
6108
|
// src/core/tokenization/extractors.ts
|
|
4886
6109
|
function extractCssSelector(input, startPos) {
|
|
4887
6110
|
if (startPos >= input.length) return null;
|
|
@@ -6727,6 +7950,8 @@ function accumulateIndented(statements, config) {
|
|
|
6727
7950
|
InMemoryDictionary,
|
|
6728
7951
|
InMemoryProfileProvider,
|
|
6729
7952
|
LatinExtendedIdentifierExtractor,
|
|
7953
|
+
LossyTranslationError,
|
|
7954
|
+
MatchSkeleton,
|
|
6730
7955
|
NullDictionary,
|
|
6731
7956
|
NullProfileProvider,
|
|
6732
7957
|
NumberExtractor,
|
|
@@ -6734,9 +7959,12 @@ function accumulateIndented(statements, config) {
|
|
|
6734
7959
|
PatternMatcher,
|
|
6735
7960
|
PatternTracker,
|
|
6736
7961
|
PunctuationExtractor,
|
|
7962
|
+
StockValueReader,
|
|
6737
7963
|
StringLiteralExtractor,
|
|
6738
7964
|
TokenStreamImpl,
|
|
7965
|
+
TranslationReadBackError,
|
|
6739
7966
|
UnicodeIdentifierExtractor,
|
|
7967
|
+
UnreadInputError,
|
|
6740
7968
|
WhitespaceExtractor,
|
|
6741
7969
|
accumulateBlocks,
|
|
6742
7970
|
buildDisambiguation,
|
|
@@ -6766,9 +7994,11 @@ function accumulateIndented(statements, config) {
|
|
|
6766
7994
|
createPosition,
|
|
6767
7995
|
createPropertyPath,
|
|
6768
7996
|
createReference,
|
|
7997
|
+
createSchemaPatternGenerator,
|
|
6769
7998
|
createSchemaRenderer,
|
|
6770
7999
|
createSelector,
|
|
6771
8000
|
createSimpleTokenizer,
|
|
8001
|
+
createStockReader,
|
|
6772
8002
|
createToken,
|
|
6773
8003
|
createTokenizerContext,
|
|
6774
8004
|
createTryNode,
|
|
@@ -6784,6 +8014,7 @@ function accumulateIndented(statements, config) {
|
|
|
6784
8014
|
extractUrl,
|
|
6785
8015
|
extractValue,
|
|
6786
8016
|
filterBySeverity,
|
|
8017
|
+
findTranslationLoss,
|
|
6787
8018
|
fromEnvelopeJSON,
|
|
6788
8019
|
fromError,
|
|
6789
8020
|
fromInterchangeNode,
|
|
@@ -6798,6 +8029,7 @@ function accumulateIndented(statements, config) {
|
|
|
6798
8029
|
getPossessiveReference,
|
|
6799
8030
|
getRoleSpec,
|
|
6800
8031
|
getRoleValue,
|
|
8032
|
+
greedyStopMarkers,
|
|
6801
8033
|
insertMarkers,
|
|
6802
8034
|
isAsciiIdentifierChar,
|
|
6803
8035
|
isAsciiLetter,
|
|
@@ -6825,6 +8057,7 @@ function accumulateIndented(statements, config) {
|
|
|
6825
8057
|
isWhitespace,
|
|
6826
8058
|
joinTokens,
|
|
6827
8059
|
jsonToSemanticNode,
|
|
8060
|
+
legacyMarkerAlternatives,
|
|
6828
8061
|
lookupKeyword,
|
|
6829
8062
|
lookupMarker,
|
|
6830
8063
|
matchBest,
|
|
@@ -6837,24 +8070,33 @@ function accumulateIndented(statements, config) {
|
|
|
6837
8070
|
parseExplicit,
|
|
6838
8071
|
parseJSONL,
|
|
6839
8072
|
patternMatcher,
|
|
8073
|
+
readGreedy,
|
|
8074
|
+
readRoleValue,
|
|
6840
8075
|
registryToAOTBackends,
|
|
6841
8076
|
renderDocument,
|
|
6842
8077
|
renderExplicit,
|
|
6843
8078
|
renderExpr,
|
|
8079
|
+
renderPattern,
|
|
6844
8080
|
reorderRoles,
|
|
8081
|
+
resolveMarkerForRole,
|
|
8082
|
+
schemaMarkerAlternatives,
|
|
8083
|
+
selectRenderPattern,
|
|
6845
8084
|
semanticNodeToJSON,
|
|
6846
8085
|
semanticNodeToRuntimeAST,
|
|
6847
8086
|
semanticValueToAST,
|
|
6848
8087
|
sortRolesByWordOrder,
|
|
8088
|
+
stockConfidenceModel,
|
|
6849
8089
|
stripOptionalDiacritics,
|
|
6850
8090
|
synthesizeFromSchemas,
|
|
6851
8091
|
toEnvelopeJSON,
|
|
6852
8092
|
toJSONL,
|
|
6853
8093
|
toJSONLRow,
|
|
6854
8094
|
toProtocolJSON,
|
|
8095
|
+
unconsumedSpans,
|
|
6855
8096
|
validateProtocolJSON,
|
|
6856
8097
|
validateSemanticJSON,
|
|
6857
8098
|
validateValueType,
|
|
6858
|
-
withDefaultExtractors
|
|
8099
|
+
withDefaultExtractors,
|
|
8100
|
+
withoutVariantOnlyRoles
|
|
6859
8101
|
});
|
|
6860
8102
|
//# sourceMappingURL=index.cjs.map
|