Skip to content

Commit

Permalink
Merge pull request #222 from Shopify/emily/next
Browse files Browse the repository at this point in the history
Implement translation for `next` node
  • Loading branch information
egiurleo authored Aug 28, 2024
2 parents e1524fb + beb5661 commit b9bf92a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
9 changes: 8 additions & 1 deletion parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
return make_unique<parser::Module>(parser.translateLocation(loc), parser.translateLocation(declLoc),
std::move(name), std::move(body));
}
case PM_NEXT_NODE: {
auto nextNode = reinterpret_cast<pm_next_node *>(node);
pm_location_t *loc = &nextNode->base.location;

auto arguments = translateArguments(nextNode->arguments);

return make_unique<parser::Next>(parser.translateLocation(loc), std::move(arguments));
}
case PM_NIL_NODE: {
auto nilNode = reinterpret_cast<pm_nil_node *>(node);
pm_location_t *loc = &nilNode->base.location;
Expand Down Expand Up @@ -757,7 +765,6 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
case PM_MISSING_NODE:
case PM_MULTI_TARGET_NODE:
case PM_MULTI_WRITE_NODE:
case PM_NEXT_NODE:
case PM_NO_KEYWORDS_PARAMETER_NODE:
case PM_NUMBERED_PARAMETERS_NODE:
case PM_NUMBERED_REFERENCE_READ_NODE:
Expand Down
23 changes: 23 additions & 0 deletions test/prism_regression/next.parse-tree.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Begin {
stmts = [
While {
cond = True {
}
body = Next {
exprs = [
]
}
}
While {
cond = True {
}
body = Next {
exprs = [
Integer {
val = "1"
}
]
}
}
]
}
12 changes: 12 additions & 0 deletions test/prism_regression/next.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# typed: false

# without arguments
while true
next
end

# with arguments
while true
next 1
end

0 comments on commit b9bf92a

Please sign in to comment.