Skip to content

Parser: Fix lambda block detection#1250

Merged
marcoroth merged 1 commit into
mainfrom
lambda-block-detection
Feb 27, 2026
Merged

Parser: Fix lambda block detection#1250
marcoroth merged 1 commit into
mainfrom
lambda-block-detection

Conversation

@marcoroth

@marcoroth marcoroth commented Feb 27, 2026

Copy link
Copy Markdown
Owner

This pull request updates the parser to correctly recognize lambda blocks (-> do / -> { and lambda do / lambda {) as ERB block openers.

Previously, code like <% content = -> do %> was parsed as an ERBContentNode and its corresponding <% end %> produced a false ERBControlFlowScopeError.

For an template like:

<% content = -> do %>
  Hello
<% end %>

It parsed as

@ DocumentNode (location: (1:0)-(4:0))
└── children: (4 items)
    ├── @ ERBContentNode (location: (1:0)-(1:21))
       ├── tag_opening: "<%" (location: (1:0)-(1:2))
       ├── content: " content = -> do " (location: (1:2)-(1:19))
       ├── tag_closing: "%>" (location: (1:19)-(1:21))
       ├── parsed: true
       └── valid: false
    
    ├── @ HTMLTextNode (location: (1:21)-(3:0))
       └── content: "\n    Hello\n"
    
    ├── @ ERBContentNode (location: (3:0)-(3:9))
       ├── errors: (1 error)
          └── @ ERBControlFlowScopeError (location: (3:0)-(3:9))
              ├── message: "`<% end %>` appears outside its control flow block. Keep ERB control flow statements together within the same HTML scope (tag, attribute, or content)."
              └── keyword: "`<% end %>`"
       
       ├── tag_opening: "<%" (location: (3:0)-(3:2))
       ├── content: " end " (location: (3:2)-(3:7))
       ├── tag_closing: "%>" (location: (3:7)-(3:9))
       ├── parsed: true
       └── valid: false
    
    └── @ HTMLTextNode (location: (3:9)-(4:0))
        └── content: "\n"

Now it correctly parses as:

@ DocumentNode (location: (1:0)-(4:0))
└── children: (2 items)
    ├── @ ERBBlockNode (location: (1:0)-(3:9))
       ├── tag_opening: "<%" (location: (1:0)-(1:2))
       ├── content: " content = -> do " (location: (1:2)-(1:19))
       ├── tag_closing: "%>" (location: (1:19)-(1:21))├── body: (1 item)
          └── @ HTMLTextNode (location: (1:21)-(3:0))
              └── content: "\n    Hello\n"
       
       └── end_node:
           └── @ ERBEndNode (location: (3:0)-(3:9))
               ├── tag_opening: "<%" (location: (3:0)-(3:2))├── content: " end " (location: (3:2)-(3:7))
               └── tag_closing: "%>" (location: (3:7)-(3:9))
    
    └── @ HTMLTextNode (location: (3:9)-(4:0))
        └── content: "\n"

@github-actions

github-actions Bot commented Feb 27, 2026

Copy link
Copy Markdown

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit d3253ba


✅ Preview deployment has been cleaned up.

@marcoroth marcoroth merged commit 37b27aa into main Feb 27, 2026
36 of 38 checks passed
@marcoroth marcoroth deleted the lambda-block-detection branch February 27, 2026 15:43
@marcoroth marcoroth added this to the v1.0.0 milestone Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant