You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env rubyrequire"erb"require"syntax_tree"SyntaxTree.format(ERB.new(<<~RUBY,trim_mode: "-").result) def foo(x) if x == 0 return :"0" <%- (1...5000).each do |i| -%> elsif x == <%= i %> return :"<%= i %>" <%- end -%> end endRUBY
Output
ruby syntax_tree_nesting_error.rb
/Users/dave/.gem/ruby/3.3.4/gems/syntax_tree-6.2.0/lib/syntax_tree/parser.rb:2864:in `on_parse_error': nesting too deep (SyntaxTree::Parser::ParseError)
from /Users/dave/.gem/ruby/3.3.4/gems/syntax_tree-6.2.0/lib/syntax_tree.rb:124:in `parse'
from /Users/dave/.gem/ruby/3.3.4/gems/syntax_tree-6.2.0/lib/syntax_tree.rb:124:in `parse'
from /Users/dave/.gem/ruby/3.3.4/gems/syntax_tree-6.2.0/lib/syntax_tree.rb:68:in `format'
from syntax_tree_nesting_error.rb:6:in `<main>'
Interestingly, the same idea except with single-line conditionals works fine:
syntax_tree_single_line_conditionals.rb
#!/usr/bin/env rubyrequire"erb"require"syntax_tree"SyntaxTree.format(ERB.new(<<~RUBY,trim_mode: "-").result) def foo(x) return :"0" <%- (1...5000).each do |i| -%> return :"<%= i %>" if x == <%= i %> <%- end -%> endRUBY
This version runs without raising an error.
The text was updated successfully, but these errors were encountered:
davebenvenuti
changed the title
Level-nesting error when formatting many cascading elsif clauses.
Level nesting error when formatting many cascading elsif clauses.
Jan 24, 2025
I noticed
SyntaxTree.format
has trouble with many (thousands) of subsequentelsif
clauses. Here's an admittedly contrived example:OS: macOS Sequoia 15.2
Ruby Version: ruby 3.3.4 (2024-07-09 revision be1089c8ec) [arm64-darwin23]
syntax_tree Version: 6.2.0
syntax_tree_nesting_error.rb
Output
Interestingly, the same idea except with single-line conditionals works fine:
syntax_tree_single_line_conditionals.rb
This version runs without raising an error.
The text was updated successfully, but these errors were encountered: