diff options
author | Kevin Newton <kddnewton@gmail.com> | 2024-03-05 21:06:52 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-03-06 16:42:49 +0000 |
commit | 7ee404a24a2a74a1e78666c31cffc2f18607e51f (patch) | |
tree | 5636749ec495ed634b7195d98c7b996f94d6ae92 /lib/prism/translation/ripper.rb | |
parent | 7273c4dd60aa8e61e29053042d085cabc3246e23 (diff) |
[ruby/prism] Implement special array literals for ripper translation
https://github.com/ruby/prism/commit/a5c3d634ef
Diffstat (limited to 'lib/prism/translation/ripper.rb')
-rw-r--r-- | lib/prism/translation/ripper.rb | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index 1d16ca1ca8..bda6478bf2 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -239,7 +239,66 @@ module Prism # [] # ^^ def visit_array_node(node) - elements = visit_arguments(node.elements) unless node.elements.empty? + bounds(node.location) + elements = + case node.opening + when /^%w/ + node.elements.inject(on_qwords_new) do |qwords, element| + bounds(element.location) + on_qwords_add(qwords, on_tstring_content(element.content)) + end + when /^%i/ + node.elements.inject(on_qsymbols_new) do |qsymbols, element| + bounds(element.location) + on_qsymbols_add(qsymbols, on_tstring_content(element.value)) + end + when /^%W/ + node.elements.inject(on_words_new) do |words, element| + bounds(element.location) + word = + if element.is_a?(StringNode) + on_word_add(on_word_new, on_tstring_content(element.content)) + else + element.parts.inject(on_word_new) do |word, part| + word_part = + if part.is_a?(StringNode) + bounds(part.location) + on_tstring_content(part.content) + else + visit(part) + end + + on_word_add(word, word_part) + end + end + + on_words_add(words, word) + end + when /^%I/ + node.elements.inject(on_symbols_new) do |symbols, element| + bounds(element.location) + symbol = + if element.is_a?(SymbolNode) + on_word_add(on_word_new, on_tstring_content(element.value)) + else + element.parts.inject(on_word_new) do |word, part| + word_part = + if part.is_a?(StringNode) + bounds(part.location) + on_tstring_content(part.content) + else + visit(part) + end + + on_word_add(word, word_part) + end + end + + on_symbols_add(symbols, symbol) + end + else + visit_arguments(node.elements) unless node.elements.empty? + end bounds(node.location) on_array(elements) |