Module: RipperRubyParser::SexpHandlers::HelperMethods Private
- Defined in:
- lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Utility methods used in several of the sexp handler modules
Instance Method Summary collapse
- #extract_node_symbol(exp) ⇒ Object private
- #extract_node_symbol_with_position(exp) ⇒ Object private
- #generic_add_star(exp) ⇒ Object private
- #handle_return_argument_list(arglist) ⇒ Object private
- #integer_literal?(exp) ⇒ Boolean private
- #map_process_list(list) ⇒ Object private
- #map_process_list_compact(list) ⇒ Object private
- #map_unwrap_begin_list(list) ⇒ Object private
- #reject_void_stmt(body) ⇒ Object private
- #safe_unwrap_void_stmt(exp) ⇒ Object private
- #shift_all(exp) ⇒ Object private
- #unwrap_begin(exp) ⇒ Object private
- #unwrap_block(exp) ⇒ Object private
- #unwrap_nil(exp) ⇒ Object private
- #with_line_number(line, exp) ⇒ Object private
- #with_position(pos, exp = nil) ⇒ Object private
- #with_position_from_node_symbol(exp) ⇒ Object private
Instance Method Details
#extract_node_symbol(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 18 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 12 def extract_node_symbol(exp) return nil if exp.nil? raise "Unexpected number of children: #{exp.length}" if exp.length != 2 _, ident = exp.shift 2 ident.to_sym end |
#extract_node_symbol_with_position(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 10 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 7 def extract_node_symbol_with_position(exp) _, ident, pos = exp.shift 3 return ident.to_sym, pos end |
#generic_add_star(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 36 def generic_add_star(exp) _, args, splatarg, *rest = shift_all exp items = process args items.push s(:splat, unwrap_begin(process(splatarg))) items.push(*map_process_list(rest)) end |
#handle_return_argument_list(arglist) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 91 def handle_return_argument_list(arglist) args = process(arglist).sexp_body case args.length when 0 args when 1 arg = args.first if arg.sexp_type == :splat s(:svalue, arg) else arg end else s(:array, *args) end end |
#integer_literal?(exp) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 43 def integer_literal?(exp) exp.sexp_type == :lit && exp[1].is_a?(Integer) end |
#map_process_list(list) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 55 def map_process_list(list) list.map { |exp| process(exp) } end |
#map_process_list_compact(list) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 51 def map_process_list_compact(list) reject_void_stmt map_unwrap_begin_list map_process_list list end |
#map_unwrap_begin_list(list) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 59 def map_unwrap_begin_list(list) list.map { |exp| unwrap_begin(exp) } end |
#reject_void_stmt(body) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 47 def reject_void_stmt(body) body.reject { |sub_exp| sub_exp.sexp_type == :void_stmt } end |
#safe_unwrap_void_stmt(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 71 def safe_unwrap_void_stmt(exp) unwrap_nil(exp) || s() end |
#shift_all(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
109 110 111 112 113 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 109 def shift_all(exp) [].tap do |result| result << exp.shift until exp.empty? end end |
#unwrap_begin(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 78 79 80 81 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 75 def unwrap_begin(exp) if exp.sexp_type == :begin exp[1] else exp end end |
#unwrap_block(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 87 88 89 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 83 def unwrap_block(exp) if exp.sexp_type == :block exp.sexp_body else [exp] end end |
#unwrap_nil(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 67 68 69 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 63 def unwrap_nil(exp) if exp.sexp_type == :void_stmt nil else exp end end |
#with_line_number(line, exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 26 def with_line_number(line, exp) exp.line = line exp end |
#with_position(pos, exp = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 20 def with_position(pos, exp = nil) (line,) = pos exp = yield if exp.nil? with_line_number line, exp end |
#with_position_from_node_symbol(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 |
# File 'lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb', line 31 def with_position_from_node_symbol(exp) sym, pos = extract_node_symbol_with_position exp with_position(pos, yield(sym)) end |