Project

General

Profile

Actions

Backport #4365

closed

Ripper.sexp should return an :array node for words/qwords

Added by adgar (Michael Edgar) about 13 years ago. Updated almost 13 years ago.

Status:
Closed

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

ripper.words.diff (488 Bytes) ripper.words.diff adgar (Michael Edgar), 02/04/2011 07:14 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0