Skip to content

Commit

Permalink
Reverse-sync ruby/ruby and deprecate old fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Aug 28, 2024
1 parent 75fd020 commit bc21c9f
Show file tree
Hide file tree
Showing 146 changed files with 518 additions and 473 deletions.
10 changes: 5 additions & 5 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ nodes:
type: node?
- name: conditions
type: node[]
- name: consequent
- name: else_clause
type: node?
kind: ElseNode
- name: case_keyword_loc
Expand All @@ -1330,7 +1330,7 @@ nodes:
type: node?
- name: conditions
type: node[]
- name: consequent
- name: else_clause
type: node?
kind: ElseNode
- name: case_keyword_loc
Expand Down Expand Up @@ -2187,7 +2187,7 @@ nodes:
baz
^^^
end
- name: consequent
- name: subsequent
type: node?
kind:
- ElseNode
Expand Down Expand Up @@ -3448,7 +3448,7 @@ nodes:
- name: statements
type: node?
kind: StatementsNode
- name: consequent
- name: subsequent
type: node?
kind: RescueNode
comment: |
Expand Down Expand Up @@ -3703,7 +3703,7 @@ nodes:
unless cond then bar end
^^^
- name: consequent
- name: else_clause
type: node?
kind: ElseNode
comment: |
Expand Down
2 changes: 1 addition & 1 deletion lib/prism/desugar_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def compile
location: node.location,
body: [public_send(read_class, location: node.name_loc, **arguments)]
),
consequent: else_node(
subsequent: else_node(
location: node.location,
else_keyword_loc: node.operator_loc,
statements: statements_node(
Expand Down
45 changes: 45 additions & 0 deletions lib/prism/node_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,49 @@ def operator_loc
binary_operator_loc
end
end

class CaseMatchNode < Node
# Returns the else clause of the case match node. This method is deprecated
# in favor of #else_clause.
def consequent
deprecated("else_clause")
else_clause
end
end

class CaseNode < Node
# Returns the else clause of the case node. This method is deprecated in
# favor of #else_clause.
def consequent
deprecated("else_clause")
else_clause
end
end

class IfNode < Node
# Returns the subsequent if/elsif/else clause of the if node. This method is
# deprecated in favor of #subsequent.
def consequent
deprecated("subsequent")
subsequent
end
end

class RescueNode < Node
# Returns the subsequent rescue clause of the rescue node. This method is
# deprecated in favor of #subsequent.
def consequent
deprecated("subsequent")
subsequent
end
end

class UnlessNode < Node
# Returns the else clause of the unless node. This method is deprecated in
# favor of #else_clause.
def consequent
deprecated("else_clause")
else_clause
end
end
end
36 changes: 18 additions & 18 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def visit_begin_node(node)
if (rescue_clause = node.rescue_clause)
begin
find_start_offset = (rescue_clause.reference&.location || rescue_clause.exceptions.last&.location || rescue_clause.keyword_loc).end_offset
find_end_offset = (rescue_clause.statements&.location&.start_offset || rescue_clause.consequent&.location&.start_offset || (find_start_offset + 1))
find_end_offset = (rescue_clause.statements&.location&.start_offset || rescue_clause.subsequent&.location&.start_offset || (find_start_offset + 1))

rescue_bodies << builder.rescue_body(
token(rescue_clause.keyword_loc),
Expand All @@ -191,7 +191,7 @@ def visit_begin_node(node)
srange_find(find_start_offset, find_end_offset, [";"]),
visit(rescue_clause.statements)
)
end until (rescue_clause = rescue_clause.consequent).nil?
end until (rescue_clause = rescue_clause.subsequent).nil?
end

begin_body =
Expand Down Expand Up @@ -410,8 +410,8 @@ def visit_case_node(node)
token(node.case_keyword_loc),
visit(node.predicate),
visit_all(node.conditions),
token(node.consequent&.else_keyword_loc),
visit(node.consequent),
token(node.else_clause&.else_keyword_loc),
visit(node.else_clause),
token(node.end_keyword_loc)
)
end
Expand All @@ -423,8 +423,8 @@ def visit_case_match_node(node)
token(node.case_keyword_loc),
visit(node.predicate),
visit_all(node.conditions),
token(node.consequent&.else_keyword_loc),
visit(node.consequent),
token(node.else_clause&.else_keyword_loc),
visit(node.else_clause),
token(node.end_keyword_loc)
)
end
Expand Down Expand Up @@ -858,8 +858,8 @@ def visit_if_node(node)
visit(node.predicate),
token(node.then_keyword_loc),
visit(node.statements),
token(node.consequent.else_keyword_loc),
visit(node.consequent)
token(node.subsequent.else_keyword_loc),
visit(node.subsequent)
)
elsif node.if_keyword_loc.start_offset == node.location.start_offset
builder.condition(
Expand All @@ -868,24 +868,24 @@ def visit_if_node(node)
if node.then_keyword_loc
token(node.then_keyword_loc)
else
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.consequent&.location || node.end_keyword_loc).start_offset, [";"])
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.subsequent&.location || node.end_keyword_loc).start_offset, [";"])
end,
visit(node.statements),
case node.consequent
case node.subsequent
when IfNode
token(node.consequent.if_keyword_loc)
token(node.subsequent.if_keyword_loc)
when ElseNode
token(node.consequent.else_keyword_loc)
token(node.subsequent.else_keyword_loc)
end,
visit(node.consequent),
visit(node.subsequent),
if node.if_keyword != "elsif"
token(node.end_keyword_loc)
end
)
else
builder.condition_mod(
visit(node.statements),
visit(node.consequent),
visit(node.subsequent),
token(node.if_keyword_loc),
visit(node.predicate)
)
Expand Down Expand Up @@ -1784,16 +1784,16 @@ def visit_unless_node(node)
if node.then_keyword_loc
token(node.then_keyword_loc)
else
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.consequent&.location || node.end_keyword_loc).start_offset, [";"])
srange_find(node.predicate.location.end_offset, (node.statements&.location || node.else_clause&.location || node.end_keyword_loc).start_offset, [";"])
end,
visit(node.consequent),
token(node.consequent&.else_keyword_loc),
visit(node.else_clause),
token(node.else_clause&.else_keyword_loc),
visit(node.statements),
token(node.end_keyword_loc)
)
else
builder.condition_mod(
visit(node.consequent),
visit(node.else_clause),
visit(node.statements),
token(node.keyword_loc),
visit(node.predicate)
Expand Down
28 changes: 14 additions & 14 deletions lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,8 @@ def visit_capture_pattern_node(node)
def visit_case_node(node)
predicate = visit(node.predicate)
clauses =
node.conditions.reverse_each.inject(visit(node.consequent)) do |consequent, condition|
on_when(*visit(condition), consequent)
node.conditions.reverse_each.inject(visit(node.else_clause)) do |current, condition|
on_when(*visit(condition), current)
end

bounds(node.location)
Expand All @@ -1286,8 +1286,8 @@ def visit_case_node(node)
def visit_case_match_node(node)
predicate = visit(node.predicate)
clauses =
node.conditions.reverse_each.inject(visit(node.consequent)) do |consequent, condition|
on_in(*visit(condition), consequent)
node.conditions.reverse_each.inject(visit(node.else_clause)) do |current, condition|
on_in(*visit(condition), current)
end

bounds(node.location)
Expand Down Expand Up @@ -1908,7 +1908,7 @@ def visit_if_node(node)
if node.then_keyword == "?"
predicate = visit(node.predicate)
truthy = visit(node.statements.body.first)
falsy = visit(node.consequent.statements.body.first)
falsy = visit(node.subsequent.statements.body.first)

bounds(node.location)
on_ifop(predicate, truthy, falsy)
Expand All @@ -1921,13 +1921,13 @@ def visit_if_node(node)
else
visit(node.statements)
end
consequent = visit(node.consequent)
subsequent = visit(node.subsequent)

bounds(node.location)
if node.if_keyword == "if"
on_if(predicate, statements, consequent)
on_if(predicate, statements, subsequent)
else
on_elsif(predicate, statements, consequent)
on_elsif(predicate, statements, subsequent)
end
else
statements = visit(node.statements.body.first)
Expand Down Expand Up @@ -1960,7 +1960,7 @@ def visit_implicit_rest_node(node)
# ^^^^^^^^^^^^^^^^^^^^^
def visit_in_node(node)
# This is a special case where we're not going to call on_in directly
# because we don't have access to the consequent. Instead, we'll return
# because we don't have access to the subsequent. Instead, we'll return
# the component parts and let the parent node handle it.
pattern = visit_pattern_node(node.pattern)
statements =
Expand Down Expand Up @@ -2808,10 +2808,10 @@ def visit_rescue_node(node)
visit(node.statements)
end

consequent = visit(node.consequent)
subsequent = visit(node.subsequent)

bounds(node.location)
on_rescue(exceptions, reference, statements, consequent)
on_rescue(exceptions, reference, statements, subsequent)
end

# def foo(*bar); end
Expand Down Expand Up @@ -3132,10 +3132,10 @@ def visit_unless_node(node)
else
visit(node.statements)
end
consequent = visit(node.consequent)
else_clause = visit(node.else_clause)

bounds(node.location)
on_unless(predicate, statements, consequent)
on_unless(predicate, statements, else_clause)
else
statements = visit(node.statements.body.first)
predicate = visit(node.predicate)
Expand Down Expand Up @@ -3176,7 +3176,7 @@ def visit_until_node(node)
# ^^^^^^^^^^^^^
def visit_when_node(node)
# This is a special case where we're not going to call on_when directly
# because we don't have access to the consequent. Instead, we'll return
# because we don't have access to the subsequent. Instead, we'll return
# the component parts and let the parent node handle it.
conditions = visit_arguments(node.conditions)
statements =
Expand Down
10 changes: 5 additions & 5 deletions lib/prism/translation/ruby_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def visit_begin_node(node)
end

current = node.rescue_clause
until (current = current.consequent).nil?
until (current = current.subsequent).nil?
result << visit(current)
end
end
Expand Down Expand Up @@ -347,13 +347,13 @@ def visit_capture_pattern_node(node)
# case foo; when bar; end
# ^^^^^^^^^^^^^^^^^^^^^^^
def visit_case_node(node)
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.consequent)
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.else_clause)
end

# case foo; in bar; end
# ^^^^^^^^^^^^^^^^^^^^^
def visit_case_match_node(node)
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.consequent)
s(node, :case, visit(node.predicate)).concat(visit_all(node.conditions)) << visit(node.else_clause)
end

# class Foo; end
Expand Down Expand Up @@ -700,7 +700,7 @@ def visit_hash_pattern_node(node)
# foo ? bar : baz
# ^^^^^^^^^^^^^^^
def visit_if_node(node)
s(node, :if, visit(node.predicate), visit(node.statements), visit(node.consequent))
s(node, :if, visit(node.predicate), visit(node.statements), visit(node.subsequent))
end

# 1i
Expand Down Expand Up @@ -1470,7 +1470,7 @@ def visit_undef_node(node)
# bar unless foo
# ^^^^^^^^^^^^^^
def visit_unless_node(node)
s(node, :if, visit(node.predicate), visit(node.consequent), visit(node.statements))
s(node, :if, visit(node.predicate), visit(node.else_clause), visit(node.statements))
end

# until foo; bar end
Expand Down
Loading

0 comments on commit bc21c9f

Please sign in to comment.