Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
; delimiting unless nodes
  • Loading branch information
kddnewton committed Feb 19, 2023
commit 305ee004c932718ca39af8815a4debc1aa72e745
37 changes: 20 additions & 17 deletions lib/syntax_tree/translation/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1555,21 +1555,6 @@ def visit_massign(node)
# Visit a MethodAddBlock node.
def visit_method_add_block(node)
case node.call
when Break, Next, ReturnNode
type, arguments = block_children(node.block)
call = visit(node.call)

s(
call.type,
[
s(
type,
[*call.children, arguments, visit(node.block.bodystmt)],
nil
)
],
nil
)
when ARef, Super, ZSuper
type, arguments = block_children(node.block)

Expand All @@ -1578,7 +1563,10 @@ def visit_method_add_block(node)
[visit(node.call), arguments, visit(node.block.bodystmt)],
smap_collection(
srange_node(node.block.opening),
srange_length(node.block.end_char, node.block.opening.is_a?(Kw) ? -3 : -1),
srange_length(
node.block.end_char,
node.block.opening.is_a?(Kw) ? -3 : -1
),
srange_node(node)
)
)
Expand Down Expand Up @@ -2439,9 +2427,24 @@ def visit_unless(node)
srange_node(node)
)
else
begin_start = node.predicate.end_char
begin_end =
if node.statements.empty?
node.statements.end_char
else
node.statements.body.first.start_char
end

begin_token =
if buffer.source[begin_start...begin_end].include?("then")
srange_find(begin_start, begin_end, "then")
elsif buffer.source[begin_start...begin_end].include?(";")
srange_find(begin_start, begin_end, ";")
end

smap_condition(
srange_length(node.start_char, 6),
srange_search_between(node.predicate, node.statements, "then"),
begin_token,
nil,
srange_length(node.end_char, -3),
srange_node(node)
Expand Down