release 0.2.6: lambda actions via RuleId#17
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughIntroduced a programmatic action attachment mechanism enabling type-safe lambda binding to grammar rules via sealed Changes
Sequence DiagramsequenceDiagram
participant User as User Code
participant PP as PegParser
participant PE as PegEngine
participant Gen as ParserGenerator
participant Interp as Generated<br/>Parser
User->>PP: fromGrammar(grammarText,<br/>config, actions)
PP->>PP: parse(grammarText)<br/>→ Grammar
PP->>PE: create(grammar,<br/>config, actions)
PE->>PE: compile inline<br/>actions
PE->>PE: mergeActions(inline,<br/>lambda actions)
PE-->>PP: return PegEngine
PP-->>User: return Parser
User->>Interp: parse(input)
loop For each matched rule
Interp->>Interp: compute<br/>ruleClassName
alt Lambda action exists
Interp->>Interp: create SemanticValues<br/>(matched text, values)
Interp->>Interp: invoke lambda<br/>→ result
else No lambda
Interp->>Interp: apply inline<br/>action / default
end
end
Interp-->>User: return Result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
Programmatic action attachment via type-safe
RuleId. Callers attach action lambdas to grammar rules without modifying the grammar file.Inline grammar actions (
{ return ...; }blocks) remain fully supported. Lambda wins when both attached to the same rule.Forward compatibility
RuleIdshape is designed forparseRuleAt(Class<? extends RuleId>, String input, int offset)which will be added in 0.3.0 alongside the multi-module reshape.Tests
618 → 635 passing, 1 skipped (
RoundTripTest). +17 new tests:RuleIdEmissionTest,LambdaActionTest,LambdaVsInlineActionTest,ActionsImmutabilityTest.Test plan
mvn test— 635/635 + 1 skippedGeneratorFlagInertnessTest3/3Summary by CodeRabbit
New Features
Documentation
Tests