Skip to content

Conversation

@AsaiYusuke
Copy link
Contributor

This change adds an analysis to detect grammar rules that always succeed and updates code generation to elide unnecessary branches, reducing generated complexity and improving coverage. It also introduces tests to validate the analysis.

  • Parser/codegen

    • Add node.CheckAlwaysSucceeds in peg.go with recursion handling and cycle guards.
    • Use the analysis in codegen to emit direct rule calls instead of conditional guards when a rule cannot fail.
  • Generated parser simplifications

    • Remove redundant conditionals around Spacing and selected Expression invocations in contexts that cannot fail per the analysis, reducing unnecessary branches in peg.peg.go.
  • Tests

    • Add a table-driven TestCheckAlwaysSucceeds in peg_test.go covering core PEG constructs and combinations.

Impact: fewer branches in generated code, simpler parser output, and improved generated-code coverage, with no intended behavior changes.

@pointlander pointlander merged commit aedf00c into pointlander:main Aug 12, 2025
1 check passed
@pointlander
Copy link
Owner

Thanks!

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.

2 participants