summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-05 07:13:05 -0500
committergit <svn-admin@ruby-lang.org>2024-03-06 16:42:39 +0000
commita47d0f03dba40fa2e7f1d564151810058dafbcc1 (patch)
tree790dd7179e2b4d97768bf08b1e8e49bcdae637ed
parent751b4d34bc4b3e652eeef247ea76bf3c7f309896 (diff)
[ruby/prism] Implement module for ripper translation
https://github.com/ruby/prism/commit/93d06436f7
-rw-r--r--lib/prism/translation/ripper.rb48
1 files changed, 37 insertions, 11 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index 98dde07714..d6846ed8b5 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -969,20 +969,18 @@ module Prism
# {}
# ^^
def visit_hash_node(node)
- elements = visit_hash_node_elements(node.elements) unless node.elements.empty?
+ elements =
+ if node.elements.any?
+ args = visit_all(node.elements)
+
+ bounds(node.elements.first.location)
+ on_assoclist_from_args(args)
+ end
bounds(node.location)
on_hash(elements)
end
- # Visit the elements of a hash node.
- private def visit_hash_node_elements(elements)
- args = visit_all(elements)
-
- bounds(elements.first.location)
- on_assoclist_from_args(args)
- end
-
# foo => {}
# ^^
def visit_hash_pattern_node(node)
@@ -1196,7 +1194,10 @@ module Prism
# foo(bar: baz)
# ^^^^^^^^
def visit_keyword_hash_node(node)
- raise NoMethodError, __method__
+ elements = visit_all(node.elements)
+
+ bounds(node.location)
+ on_bare_assoc_hash(elements)
end
# def foo(**bar); end
@@ -1333,7 +1334,32 @@ module Prism
# module Foo; end
# ^^^^^^^^^^^^^^^
def visit_module_node(node)
- raise NoMethodError, __method__
+ constant_path =
+ if node.constant_path.is_a?(ConstantReadNode)
+ bounds(node.constant_path.location)
+ on_const_ref(on_const(node.constant_path.name.to_s))
+ else
+ visit(node.constant_path)
+ end
+
+ bodystmt =
+ case node.body
+ when nil
+ bounds(node.location)
+ on_bodystmt(visit_statements_node_body([nil]), nil, nil, nil)
+ when StatementsNode
+ body = visit(node.body)
+
+ bounds(node.body.location)
+ on_bodystmt(body, nil, nil, nil)
+ when BeginNode
+ visit_begin_node_clauses(node.body)
+ else
+ raise
+ end
+
+ bounds(node.location)
+ on_module(constant_path, bodystmt)
end
# foo, bar = baz