@lokascript/framework 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/dist/aot/index.d.ts +1 -0
  2. package/dist/aot/index.d.ts.map +1 -1
  3. package/dist/aot/registry-bridge.d.ts +27 -0
  4. package/dist/aot/registry-bridge.d.ts.map +1 -0
  5. package/dist/api/create-dsl.d.ts.map +1 -1
  6. package/dist/api/dispatcher.d.ts +22 -0
  7. package/dist/api/dispatcher.d.ts.map +1 -1
  8. package/dist/api/domain-registry.d.ts +41 -0
  9. package/dist/api/domain-registry.d.ts.map +1 -1
  10. package/dist/api/index.js +1438 -21
  11. package/dist/api/index.js.map +1 -1
  12. package/dist/core/index.js +247 -10
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/pattern-matching/index.js +74 -10
  15. package/dist/core/pattern-matching/index.js.map +1 -1
  16. package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
  17. package/dist/core/tokenization/index.js +133 -0
  18. package/dist/core/tokenization/index.js.map +1 -1
  19. package/dist/core/tokenization/morphology/base-normalizer.d.ts +94 -0
  20. package/dist/core/tokenization/morphology/base-normalizer.d.ts.map +1 -0
  21. package/dist/core/tokenization/morphology/index.d.ts +3 -1
  22. package/dist/core/tokenization/morphology/index.d.ts.map +1 -1
  23. package/dist/core/types.d.ts +81 -2
  24. package/dist/core/types.d.ts.map +1 -1
  25. package/dist/core/types.js +40 -0
  26. package/dist/core/types.js.map +1 -1
  27. package/dist/feedback/confidence-gate.d.ts +28 -0
  28. package/dist/feedback/confidence-gate.d.ts.map +1 -0
  29. package/dist/feedback/feedback-formatter.d.ts +21 -0
  30. package/dist/feedback/feedback-formatter.d.ts.map +1 -0
  31. package/dist/feedback/index.d.ts +11 -0
  32. package/dist/feedback/index.d.ts.map +1 -0
  33. package/dist/feedback/pattern-tracker.d.ts +47 -0
  34. package/dist/feedback/pattern-tracker.d.ts.map +1 -0
  35. package/dist/feedback/types.d.ts +113 -0
  36. package/dist/feedback/types.d.ts.map +1 -0
  37. package/dist/generation/index.js +2 -1
  38. package/dist/generation/index.js.map +1 -1
  39. package/dist/index.cjs +3264 -132
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.ts +8 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +3223 -132
  44. package/dist/index.js.map +1 -1
  45. package/dist/ir/explicit-parser.d.ts +86 -0
  46. package/dist/ir/explicit-parser.d.ts.map +1 -0
  47. package/dist/ir/explicit-renderer.d.ts +34 -0
  48. package/dist/ir/explicit-renderer.d.ts.map +1 -0
  49. package/dist/ir/from-interchange.d.ts +51 -0
  50. package/dist/ir/from-interchange.d.ts.map +1 -0
  51. package/dist/ir/index.d.ts +31 -0
  52. package/dist/ir/index.d.ts.map +1 -0
  53. package/dist/ir/index.js +1934 -0
  54. package/dist/ir/index.js.map +1 -0
  55. package/dist/ir/json-schema.d.ts +40 -0
  56. package/dist/ir/json-schema.d.ts.map +1 -0
  57. package/dist/ir/protocol-json.d.ts +73 -0
  58. package/dist/ir/protocol-json.d.ts.map +1 -0
  59. package/dist/ir/references.d.ts +19 -0
  60. package/dist/ir/references.d.ts.map +1 -0
  61. package/dist/ir/to-runtime-ast.d.ts +53 -0
  62. package/dist/ir/to-runtime-ast.d.ts.map +1 -0
  63. package/dist/ir/types.d.ts +151 -0
  64. package/dist/ir/types.d.ts.map +1 -0
  65. package/dist/parsing/index.js +74 -10
  66. package/dist/parsing/index.js.map +1 -1
  67. package/dist/prompts/index.d.ts +9 -0
  68. package/dist/prompts/index.d.ts.map +1 -0
  69. package/dist/prompts/prompt-generator.d.ts +49 -0
  70. package/dist/prompts/prompt-generator.d.ts.map +1 -0
  71. package/dist/prompts/types.d.ts +64 -0
  72. package/dist/prompts/types.d.ts.map +1 -0
  73. package/dist/schema/command-schema.d.ts +17 -0
  74. package/dist/schema/command-schema.d.ts.map +1 -1
  75. package/dist/schema/index.js.map +1 -1
  76. package/dist/testing/index.js +8673 -8260
  77. package/dist/testing/index.js.map +1 -1
  78. package/dist/training/index.d.ts +11 -0
  79. package/dist/training/index.d.ts.map +1 -0
  80. package/dist/training/jsonl-writer.d.ts +42 -0
  81. package/dist/training/jsonl-writer.d.ts.map +1 -0
  82. package/dist/training/schema-synthesizer.d.ts +20 -0
  83. package/dist/training/schema-synthesizer.d.ts.map +1 -0
  84. package/dist/training/types.d.ts +73 -0
  85. package/dist/training/types.d.ts.map +1 -0
  86. package/package.json +5 -1
  87. package/src/aot/index.ts +1 -0
  88. package/src/aot/registry-bridge.test.ts +104 -0
  89. package/src/aot/registry-bridge.ts +66 -0
  90. package/src/api/create-dsl.test.ts +306 -0
  91. package/src/api/create-dsl.ts +21 -0
  92. package/src/api/dispatcher.test.ts +66 -0
  93. package/src/api/dispatcher.ts +77 -9
  94. package/src/api/domain-registry.ts +120 -4
  95. package/src/core/pattern-matching/pattern-matcher.test.ts +131 -0
  96. package/src/core/pattern-matching/pattern-matcher.ts +102 -19
  97. package/src/core/tokenization/morphology/base-normalizer.ts +249 -0
  98. package/src/core/tokenization/morphology/index.ts +3 -1
  99. package/src/core/types.ts +147 -2
  100. package/src/feedback/confidence-gate.test.ts +111 -0
  101. package/src/feedback/confidence-gate.ts +70 -0
  102. package/src/feedback/feedback-formatter.test.ts +198 -0
  103. package/src/feedback/feedback-formatter.ts +298 -0
  104. package/src/feedback/index.ts +24 -0
  105. package/src/feedback/pattern-tracker.test.ts +198 -0
  106. package/src/feedback/pattern-tracker.ts +140 -0
  107. package/src/feedback/types.ts +149 -0
  108. package/src/generation/pattern-generator.ts +2 -2
  109. package/src/index.ts +29 -0
  110. package/src/integration/llm-lse-integration.test.ts +457 -0
  111. package/src/ir/conformance.test.ts +120 -0
  112. package/src/ir/explicit-parser.test.ts +612 -0
  113. package/src/ir/explicit-parser.ts +793 -0
  114. package/src/ir/explicit-renderer.test.ts +229 -0
  115. package/src/ir/explicit-renderer.ts +198 -0
  116. package/src/ir/from-interchange.test.ts +853 -0
  117. package/src/ir/from-interchange.ts +594 -0
  118. package/src/ir/index.ts +77 -0
  119. package/src/ir/json-schema.test.ts +281 -0
  120. package/src/ir/json-schema.ts +299 -0
  121. package/src/ir/protocol-json.test.ts +1187 -0
  122. package/src/ir/protocol-json.ts +751 -0
  123. package/src/ir/references.test.ts +38 -0
  124. package/src/ir/references.ts +33 -0
  125. package/src/ir/round-trip.test.ts +557 -0
  126. package/src/ir/to-runtime-ast.ts +203 -0
  127. package/src/ir/types.ts +191 -0
  128. package/src/prompts/index.ts +15 -0
  129. package/src/prompts/prompt-generator.test.ts +386 -0
  130. package/src/prompts/prompt-generator.ts +531 -0
  131. package/src/prompts/types.ts +89 -0
  132. package/src/schema/command-schema.ts +19 -0
  133. package/src/training/index.ts +13 -0
  134. package/src/training/jsonl-writer.test.ts +138 -0
  135. package/src/training/jsonl-writer.ts +67 -0
  136. package/src/training/schema-synthesizer.test.ts +250 -0
  137. package/src/training/schema-synthesizer.ts +306 -0
  138. package/src/training/types.ts +103 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-runtime-ast.d.ts","sourceRoot":"","sources":["../../src/ir/to-runtime-ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAId,MAAM,eAAe,CAAC;AAMvB,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED,iEAAiE;AACjE,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,CAAC;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAC1D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C;AAED,4DAA4D;AAC5D,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,CAAC;CACjC;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAwB3E;AAiED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,CA4CvE"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * IR (Intermediate Representation) Types
3
+ *
4
+ * Types for the explicit bracket syntax, LLM JSON format, and
5
+ * schema-based validation. These are domain-agnostic — they work
6
+ * for any DSL built on the framework.
7
+ */
8
+ import type { CommandSchema } from '../schema/command-schema';
9
+ /**
10
+ * Structured input format for LLMs.
11
+ * No parsing ambiguity — action and roles are explicitly typed.
12
+ *
13
+ * @example
14
+ * ```json
15
+ * {
16
+ * "action": "toggle",
17
+ * "roles": { "patient": { "type": "selector", "value": ".active" } },
18
+ * "trigger": { "event": "click" }
19
+ * }
20
+ * ```
21
+ */
22
+ export interface SemanticJSON {
23
+ /** The command/action name */
24
+ action: string;
25
+ /** Named semantic roles with typed values */
26
+ roles: Record<string, SemanticJSONValue>;
27
+ /** Optional event trigger (wraps command in event handler) */
28
+ trigger?: {
29
+ event: string;
30
+ modifiers?: Record<string, unknown>;
31
+ };
32
+ }
33
+ /**
34
+ * A typed value in the LLM JSON format.
35
+ */
36
+ export interface SemanticJSONValue {
37
+ type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
38
+ value: string | number | boolean;
39
+ }
40
+ /**
41
+ * Interface for optional schema-based role validation in the explicit parser.
42
+ * Consumers provide this to validate roles against command definitions.
43
+ *
44
+ * When not provided, the parser accepts any role names.
45
+ */
46
+ export interface SchemaLookup {
47
+ getSchema(action: string): CommandSchema | undefined;
48
+ }
49
+ /**
50
+ * Options for parseExplicit().
51
+ */
52
+ export interface ParseExplicitOptions {
53
+ /** Optional schema lookup for role validation */
54
+ schemaLookup?: SchemaLookup;
55
+ /** Custom set of valid reference names (defaults to DEFAULT_REFERENCES) */
56
+ referenceSet?: ReadonlySet<string>;
57
+ /**
58
+ * When true, validation errors are collected as diagnostics on the
59
+ * returned node instead of throwing. Fatal parse errors (missing brackets,
60
+ * empty input) still throw. Default: false.
61
+ */
62
+ collectDiagnostics?: boolean;
63
+ }
64
+ /**
65
+ * A diagnostic message from IR validation.
66
+ *
67
+ * Uses required `code` field (compatible with both framework Diagnostic
68
+ * and compilation-service Diagnostic types via structural typing).
69
+ */
70
+ export interface IRDiagnostic {
71
+ severity: 'error' | 'warning' | 'info';
72
+ code: string;
73
+ message: string;
74
+ suggestion?: string;
75
+ }
76
+ export type ProtocolNodeKind = 'command' | 'event-handler' | 'compound';
77
+ export type ProtocolChainType = 'then' | 'and' | 'async' | 'sequential' | 'pipe';
78
+ /**
79
+ * A typed semantic value in the protocol full-fidelity JSON format.
80
+ * Matches protocol/spec/wire-format.md "Value Shapes" table.
81
+ */
82
+ export interface ProtocolValueJSON {
83
+ type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
84
+ value?: string | number | boolean;
85
+ dataType?: 'string' | 'number' | 'boolean' | 'duration';
86
+ raw?: string;
87
+ name?: string;
88
+ enabled?: boolean;
89
+ selectorKind?: 'id' | 'class' | 'attribute' | 'element' | 'complex';
90
+ }
91
+ /**
92
+ * Protocol JSON node — matches protocol/spec/wire-format.md.
93
+ * Produced by toProtocolJSON() and consumed by fromProtocolJSON().
94
+ *
95
+ * `kind` defaults to `"command"` when omitted.
96
+ * `trigger` is convenience sugar that wraps a command in an event handler.
97
+ */
98
+ export interface ProtocolNodeJSON {
99
+ kind?: ProtocolNodeKind;
100
+ action: string;
101
+ roles: Record<string, ProtocolValueJSON>;
102
+ trigger?: {
103
+ event: string;
104
+ modifiers?: Record<string, unknown>;
105
+ };
106
+ body?: ProtocolNodeJSON[];
107
+ statements?: ProtocolNodeJSON[];
108
+ chainType?: ProtocolChainType;
109
+ thenBranch?: ProtocolNodeJSON[];
110
+ elseBranch?: ProtocolNodeJSON[];
111
+ loopVariant?: 'forever' | 'times' | 'for' | 'while' | 'until';
112
+ loopBody?: ProtocolNodeJSON[];
113
+ loopVariable?: string;
114
+ indexVariable?: string;
115
+ diagnostics?: ProtocolDiagnosticJSON[];
116
+ annotations?: AnnotationJSON[];
117
+ catchBranch?: ProtocolNodeJSON[];
118
+ finallyBranch?: ProtocolNodeJSON[];
119
+ asyncVariant?: 'all' | 'race';
120
+ asyncBody?: ProtocolNodeJSON[];
121
+ arms?: MatchArmJSON[];
122
+ defaultArm?: ProtocolNodeJSON[];
123
+ }
124
+ /** A diagnostic in protocol wire format (v1.2, extended v1.2.1). */
125
+ export interface ProtocolDiagnosticJSON {
126
+ level: 'error' | 'warning' | 'info';
127
+ role?: string;
128
+ message: string;
129
+ code?: string;
130
+ /** v1.2.1: source parser/stage that produced this diagnostic. */
131
+ source?: string;
132
+ /** v1.2.1: actionable fix suggestions. */
133
+ suggestions?: string[];
134
+ }
135
+ /** A metadata annotation in protocol wire format (v1.2). */
136
+ export interface AnnotationJSON {
137
+ name: string;
138
+ value?: string;
139
+ }
140
+ /** A match arm in protocol wire format (v1.2). */
141
+ export interface MatchArmJSON {
142
+ pattern: ProtocolValueJSON;
143
+ body: ProtocolNodeJSON[];
144
+ }
145
+ /** Versioned envelope for multi-node LSE documents (v1.2). */
146
+ export interface LSEEnvelopeJSON {
147
+ lseVersion: string;
148
+ features?: string[];
149
+ nodes: ProtocolNodeJSON[];
150
+ }
151
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ir/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAM9D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACzC,8DAA8D;IAC9D,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe,GAAG,MAAM,CAAC;IACrF,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAClC;AAMD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,2EAA2E;IAC3E,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAMD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CA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 @@ var _PatternMatcher = class _PatternMatcher {
224
224
  * a token and the immediately following pattern token fails, the matcher
225
225
  * resets to before the optional role and retries the failed token.
226
226
  */
227
- matchTokenSequence(tokens, patternTokens, captured) {
227
+ matchTokenSequence(tokens, patternTokens, captured, parentStopMarkers) {
228
228
  const firstPatternToken = patternTokens[0];
229
229
  const patternExpectsConjunction = firstPatternToken?.type === "literal" && (firstPatternToken.value === "and" || firstPatternToken.value === "then" || firstPatternToken.alternatives?.includes("and") || firstPatternToken.alternatives?.includes("then"));
230
230
  if (this.currentProfile?.code === "ar" && !patternExpectsConjunction) {
@@ -248,6 +248,9 @@ var _PatternMatcher = class _PatternMatcher {
248
248
  );
249
249
  if (patternToken.type === "role" && patternToken.greedy) {
250
250
  const stopMarkers = this.collectStopMarkers(patternTokens, i + 1);
251
+ if (parentStopMarkers) {
252
+ for (const m of parentStopMarkers) stopMarkers.add(m);
253
+ }
251
254
  const values = [];
252
255
  while (!tokens.isAtEnd()) {
253
256
  const nextToken = tokens.peek();
@@ -267,8 +270,58 @@ var _PatternMatcher = class _PatternMatcher {
267
270
  return false;
268
271
  }
269
272
  }
273
+ if (patternToken.type === "group") {
274
+ const siblingStopMarkers = this.collectStopMarkers(patternTokens, i + 1);
275
+ if (parentStopMarkers) {
276
+ for (const m of parentStopMarkers) siblingStopMarkers.add(m);
277
+ }
278
+ const groupMatched = this.matchGroupToken(
279
+ tokens,
280
+ patternToken,
281
+ captured,
282
+ siblingStopMarkers
283
+ );
284
+ if (groupMatched) {
285
+ prevOptionalMark = null;
286
+ prevOptionalRole = null;
287
+ continue;
288
+ }
289
+ if (this.isOptional(patternToken)) {
290
+ continue;
291
+ }
292
+ return false;
293
+ }
270
294
  const isOptionalRole = patternToken.type === "role" && patternToken.optional === true;
271
295
  const markBefore = isOptionalRole ? tokens.mark() : null;
296
+ const isRoleToken = patternToken.type === "role";
297
+ if (isRoleToken && !isOptionalRole) {
298
+ const nextPT = i + 1 < patternTokens.length ? patternTokens[i + 1] : null;
299
+ if (nextPT?.type === "literal") {
300
+ const currentToken = tokens.peek();
301
+ if (currentToken && this.getMatchType(currentToken, nextPT.value) !== "none") {
302
+ this.logger.debug(
303
+ " >> MARKER-STEAL GUARD: current token matches next literal, skipping role"
304
+ );
305
+ this.logger.debug(" >> Token match FAILED");
306
+ if (this.isOptional(patternToken)) {
307
+ continue;
308
+ }
309
+ if (prevOptionalMark && prevOptionalRole) {
310
+ this.logger.debug(" >> BACKTRACKING: undoing optional role", prevOptionalRole);
311
+ tokens.reset(prevOptionalMark);
312
+ captured.delete(prevOptionalRole);
313
+ prevOptionalMark = null;
314
+ prevOptionalRole = null;
315
+ const retryMatched = this.matchPatternToken(tokens, patternToken, captured);
316
+ this.logger.debug(" >> Backtrack retry result:", retryMatched);
317
+ if (retryMatched) {
318
+ continue;
319
+ }
320
+ }
321
+ return false;
322
+ }
323
+ }
324
+ }
272
325
  const matched = this.matchPatternToken(tokens, patternToken, captured);
273
326
  this.logger.debug(" >> Match result:", matched);
274
327
  if (matched) {
@@ -389,7 +442,7 @@ var _PatternMatcher = class _PatternMatcher {
389
442
  const possessiveValue = this.tryMatchPossessiveExpression(tokens);
390
443
  if (possessiveValue) {
391
444
  if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
392
- if (!patternToken.expectedTypes.includes(possessiveValue.type) && !patternToken.expectedTypes.includes("expression")) {
445
+ if (!isTypeCompatible(possessiveValue.type, patternToken.expectedTypes)) {
393
446
  return patternToken.optional || false;
394
447
  }
395
448
  }
@@ -399,7 +452,7 @@ var _PatternMatcher = class _PatternMatcher {
399
452
  const methodCallValue = this.tryMatchMethodCallExpression(tokens);
400
453
  if (methodCallValue) {
401
454
  if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
402
- if (!patternToken.expectedTypes.includes(methodCallValue.type) && !patternToken.expectedTypes.includes("expression")) {
455
+ if (!isTypeCompatible(methodCallValue.type, patternToken.expectedTypes)) {
403
456
  return patternToken.optional || false;
404
457
  }
405
458
  }
@@ -419,7 +472,7 @@ var _PatternMatcher = class _PatternMatcher {
419
472
  const propertyAccessValue = this.tryMatchPropertyAccessExpression(tokens);
420
473
  if (propertyAccessValue) {
421
474
  if (patternToken.expectedTypes && patternToken.expectedTypes.length > 0) {
422
- if (!patternToken.expectedTypes.includes(propertyAccessValue.type) && !patternToken.expectedTypes.includes("expression")) {
475
+ if (!isTypeCompatible(propertyAccessValue.type, patternToken.expectedTypes)) {
423
476
  return patternToken.optional || false;
424
477
  }
425
478
  }
@@ -739,10 +792,15 @@ var _PatternMatcher = class _PatternMatcher {
739
792
  * (e.g., a value like 'hello') to sit between groups without blocking later
740
793
  * marker matches.
741
794
  */
742
- matchGroupToken(tokens, patternToken, captured) {
795
+ matchGroupToken(tokens, patternToken, captured, parentStopMarkers) {
743
796
  const mark = tokens.mark();
744
797
  const capturedBefore = new Set(captured.keys());
745
- const success = this.matchTokenSequence(tokens, patternToken.tokens, captured);
798
+ const success = this.matchTokenSequence(
799
+ tokens,
800
+ patternToken.tokens,
801
+ captured,
802
+ parentStopMarkers
803
+ );
746
804
  if (success) return true;
747
805
  tokens.reset(mark);
748
806
  for (const role of captured.keys()) {
@@ -764,7 +822,12 @@ var _PatternMatcher = class _PatternMatcher {
764
822
  "- skipping intervening tokens"
765
823
  );
766
824
  for (let s = 0; s < offset; s++) tokens.advance();
767
- const retrySuccess = this.matchTokenSequence(tokens, patternToken.tokens, captured);
825
+ const retrySuccess = this.matchTokenSequence(
826
+ tokens,
827
+ patternToken.tokens,
828
+ captured,
829
+ parentStopMarkers
830
+ );
768
831
  if (retrySuccess) return true;
769
832
  tokens.reset(mark);
770
833
  for (const role of captured.keys()) {
@@ -831,7 +894,7 @@ var _PatternMatcher = class _PatternMatcher {
831
894
  break;
832
895
  }
833
896
  }
834
- break;
897
+ if (!pt.optional) break;
835
898
  }
836
899
  }
837
900
  return markers;
@@ -841,8 +904,9 @@ var _PatternMatcher = class _PatternMatcher {
841
904
  */
842
905
  isStopMarker(token, stopMarkers) {
843
906
  if (stopMarkers.size === 0) return false;
844
- const value = (token.normalized || token.value).toLowerCase();
845
- return stopMarkers.has(value);
907
+ if (stopMarkers.has(token.value.toLowerCase())) return true;
908
+ if (token.normalized && stopMarkers.has(token.normalized.toLowerCase())) return true;
909
+ return false;
846
910
  }
847
911
  /**
848
912
  * Convert a language token to a semantic value.