Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Combine Elsif node with IfNode #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
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
Next Next commit
Remove visit_elsif methods from all visitors
  • Loading branch information
egiurleo committed Mar 3, 2023
commit 57b030621c2cc8cf2e021cd1aae55ae22d4f151c
9 changes: 0 additions & 9 deletions lib/syntax_tree/field_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,6 @@ def visit_else(node)
end
end

def visit_elsif(node)
node(node, "elsif") do
field("predicate", node.predicate)
field("statements", node.statements)
field("consequent", node.consequent) if node.consequent
comments(node)
end
end

def visit_embdoc(node)
node(node, "embdoc") { field("value", node.value) }
end
Expand Down
8 changes: 0 additions & 8 deletions lib/syntax_tree/mutation_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,6 @@ def visit_else(node)
)
end

# Visit a Elsif node.
def visit_elsif(node)
node.copy(
statements: visit(node.statements),
consequent: visit(node.consequent)
)
end

# Visit a EmbDoc node.
def visit_embdoc(node)
node.copy
Expand Down
46 changes: 1 addition & 45 deletions lib/syntax_tree/translation/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1037,50 +1037,6 @@ def visit_else(node)
end
end

# Visit an Elsif node.
def visit_elsif(node)
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

else_token =
case node.consequent
when Elsif
srange_length(node.consequent.start_char, 5)
when Else
srange_length(node.consequent.start_char, 4)
end

expression = srange(node.start_char, node.statements.end_char - 1)

s(
:if,
[
visit(node.predicate),
visit(node.statements),
visit(node.consequent)
],
smap_condition(
srange_length(node.start_char, 5),
begin_token,
else_token,
nil,
expression
)
)
end

# Visit an ENDBlock node.
def visit_END(node)
s(
Expand Down Expand Up @@ -1361,7 +1317,7 @@ def visit_if(node)

else_token =
case node.consequent
when Elsif
when IfNode
srange_length(node.consequent.start_char, 5)
when Else
srange_length(node.consequent.start_char, 4)
Expand Down
3 changes: 0 additions & 3 deletions lib/syntax_tree/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ class Visitor < BasicVisitor
# Visit an Else node.
alias visit_else visit_child_nodes

# Visit an Elsif node.
alias visit_elsif visit_child_nodes

# Visit an EmbDoc node.
alias visit_embdoc visit_child_nodes

Expand Down