Skip to content

AGR: Detect epsilon-reachable cycles in grammar compiler#1955

Merged
curtisman merged 1 commit intomicrosoft:mainfrom
curtisman:agr-grammar-compiler-tests
Feb 28, 2026
Merged

AGR: Detect epsilon-reachable cycles in grammar compiler#1955
curtisman merged 1 commit intomicrosoft:mainfrom
curtisman:agr-grammar-compiler-tests

Conversation

@curtisman
Copy link
Member

@curtisman curtisman commented Feb 28, 2026

Summary

  • Epsilon-reachable cycle detection in grammarCompiler.ts: adds compiling and nullable fields to DefinitionRecord to track in-progress rule compilation and whether a rule alternative can match the empty string (ε). During compilation, the set of rule names entered since the last mandatory token was consumed (epsilonReachable) is threaded through createNamedGrammarRules / createGrammarRules / createGrammarRule. A compile-time error is raised when a rule reference is encountered whose name is already in that set, meaning the grammar would loop infinitely at match time.
  • New tests (grammarCompileError.spec.ts): 13 error cases (direct self-reference, mutual cycles, optional parts before back-references, Kleene-star groups, multiple independent cycles, etc.) and 10 valid-grammar cases confirming that non-epsilon recursion (mandatory literal before back-reference, Kleene-plus, number/wildcard variables, etc.) is accepted without error.
  • Matcher tests (grammarMatcher.spec.ts): 2 new tests verifying that right-recursive rules (which are valid) correctly match multi-token input at runtime.
  • Grammar store tests (grammarStore.spec.ts): minor updates to align with the revised compiler behaviour.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@curtisman curtisman enabled auto-merge February 28, 2026 00:38
@curtisman curtisman added this pull request to the merge queue Feb 28, 2026
Merged via the queue into microsoft:main with commit e4b3a9d Feb 28, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant