Backport #4365
closedRipper.sexp should return an :array node for words/qwords
Description
=begin
Currently, Ripper has no rule for the words/qwords base rule. It simply returns the array of string literals (and embexprs... etc) contained within the qwords/words expression. Example:
[:program,
[[
[:@tstring_content, "abc", [1, 3]], [:@tstring_content, "def", [1, 7]]]]]
pp Ripper.sexp('["abc", "def"]')
[:program,
[[:array,
[[:string_literal, [:string_content, [:@tstring_content, "abc", [1, 2]]]],
[:string_literal,
[:string_content, [:@tstring_content, "def", [1, 9]]]]]]]]
Note that in the first example, the root node of the program (after the :program node) does not have a node type at all. I believe this is an error, and makes discovering words/qwords nodes in an AST quite difficult. I feel that for consistency with array literals, it should create an array node, or at least have a node type of its own. I'd prefer that:
['a', 'b', 'c']
and
%w(a b c)
return the same AST, as the latter is merely syntactic sugar for the former. I've attached a small patch to that effect, though if a different node type is desired for words/qwords, that's more than possible by renaming the node in the added calls to dispatch1.
=end
Files