Skip to content

Solving #37,#38,#29 and #10 - #46

Open
Subhiiiiii wants to merge 1 commit into
albertZhangTJ:grammar_optimizationfrom
Subhiiiiii:#45
Open

Solving #37,#38,#29 and #10#46
Subhiiiiii wants to merge 1 commit into
albertZhangTJ:grammar_optimizationfrom
Subhiiiiii:#45

Conversation

@Subhiiiiii

Copy link
Copy Markdown

Pull Request Description: Optimize Context Frame Handling in Unparser Rules

Key Changes in UnparserRuleNode.java:

  1. Variable & Method Renaming

    • Renamed is_fragmentis_standalone
    • Renamed set_fragment()set_standalone()
    // Before
    private boolean is_fragment;
    public void set_fragment() { ... }
    
    // After
    private boolean is_standalone;
    public void set_standalone() { ... }
  2. Inverted Default Behavior

    • Default value remains false but now indicates:
      this.is_standalone = false; // Default = fragment (no new context frame)
  3. Modifier Handling Update
    Rules with modifiers now mark themselves as standalone:

    // Before: Marked as fragment
    if (ruleSpec.ruleModifier()!=null) { rule.set_fragment(); }
    
    // After: Marked as standalone
    if (ruleSpec.ruleModifier()!=null) { rule.set_standalone(); }
  4. Context Frame Logic Flip

    // Before: Create frames by default
    if (!is_fragment) { ... }
    
    // After: Only create frames when standalone
    if (is_standalone) { ... }

Behavioral Impact:
✅ Performance Optimization

  • Reduces unnecessary context frame creation (now only for explicitly marked rules)
  • Fragments (default) reuse parent context frames

✅ Improved Semantics

  • standalone flag clearly indicates intentional frame creation
  • Aligns with common parser patterns:
    • Base rules = fragments (e.g., expression components)
    • Top-level rules = standalone (e.g., complete statements)

✅ Backward Compatibility

  • Default behavior matches previous fragment handling
  • Existing modifiers now trigger standalone behavior

Verification Steps:

  1. All rules with modifiers will now create dedicated context frames
  2. Fragmented rules show improved performance via shared contexts
  3. Return value handling remains consistent for standalone rules

This change better aligns context frame management with actual parsing needs while maintaining existing functionality.

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