Class: RipperRubyParser::SexpProcessor Private
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- RipperRubyParser::SexpProcessor
- Includes:
- SexpHandlers
- Defined in:
- lib/ripper_ruby_parser/sexp_processor.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Processes the sexp created by Ripper to what RubyParser would produce.
Instance Attribute Summary collapse
- #filename ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(filename: nil) ⇒ SexpProcessor
constructor
private
A new instance of SexpProcessor.
- #process_at_backref(exp) ⇒ Object private
-
#process_at_CHAR(exp) ⇒ Object
private
character literals.
-
#process_at_const(exp) ⇒ Object
private
symbol-like sexps.
- #process_at_cvar(exp) ⇒ Object private
- #process_at_float(exp) ⇒ Object private
- #process_at_gvar(exp) ⇒ Object private
- #process_at_ident(exp) ⇒ Object private
-
#process_at_int(exp) ⇒ Object
private
number literals.
- #process_at_ivar(exp) ⇒ Object private
- #process_at_kw(exp) ⇒ Object private
- #process_at_label(exp) ⇒ Object private
- #process_at_op(exp) ⇒ Object private
- #process_BEGIN(exp) ⇒ Object private
- #process_class(exp) ⇒ Object private
- #process_comment(exp) ⇒ Object private
- #process_const_path_field(exp) ⇒ Object private
- #process_const_path_ref(exp) ⇒ Object private
- #process_const_ref(exp) ⇒ Object private
- #process_END(exp) ⇒ Object private
- #process_module(exp) ⇒ Object private
- #process_paren(exp) ⇒ Object private
- #process_program(exp) ⇒ Object private
- #process_sclass(exp) ⇒ Object private
- #process_stmts(exp) ⇒ Object private
- #process_top_const_field(exp) ⇒ Object private
- #process_top_const_ref(exp) ⇒ Object private
- #process_var_alias(exp) ⇒ Object private
- #process_var_field(exp) ⇒ Object private
- #process_var_ref(exp) ⇒ Object private
Methods included from SexpHandlers
Constructor Details
#initialize(filename: nil) ⇒ SexpProcessor
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.
Returns a new instance of SexpProcessor.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 12 def initialize(filename: nil) super() # TODO: Find these automatically @processors[:@int] = :process_at_int @processors[:@float] = :process_at_float @processors[:@CHAR] = :process_at_CHAR @processors[:@label] = :process_at_label @processors[:@const] = :process_at_const @processors[:@ident] = :process_at_ident @processors[:@cvar] = :process_at_cvar @processors[:@gvar] = :process_at_gvar @processors[:@ivar] = :process_at_ivar @processors[:@kw] = :process_at_kw @processors[:@op] = :process_at_op @processors[:@backref] = :process_at_backref @processors[:@tstring_content] = :process_at_tstring_content @filename = filename @errors = [] @in_method_body = false end |
Instance Attribute Details
#filename ⇒ Object (readonly)
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.
10 11 12 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 10 def filename @filename end |
Instance Method Details
#process_at_backref(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.
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 211 def process_at_backref(exp) _, str, pos = exp.shift 3 name = str[1..-1] with_position pos do if name =~ /[0-9]/ s(:nth_ref, name.to_i) else s(:back_ref, name.to_sym) end end end |
#process_at_CHAR(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.
character literals
162 163 164 165 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 162 def process_at_CHAR(exp) _, val, pos = exp.shift 3 with_position(pos, s(:str, Unescape.unescape(val[1..-1]))) end |
#process_at_const(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.
symbol-like sexps
172 173 174 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 172 def process_at_const(exp) make_identifier(:const, exp) end |
#process_at_cvar(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.
176 177 178 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 176 def process_at_cvar(exp) make_identifier(:cvar, exp) end |
#process_at_float(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.
157 158 159 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 157 def process_at_float(exp) make_literal(exp, &:to_f) end |
#process_at_gvar(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.
180 181 182 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 180 def process_at_gvar(exp) make_identifier(:gvar, exp) end |
#process_at_ident(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.
188 189 190 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 188 def process_at_ident(exp) make_identifier(:lvar, exp) end |
#process_at_int(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.
number literals
153 154 155 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 153 def process_at_int(exp) make_literal(exp) { |val| Integer(val) } end |
#process_at_ivar(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.
184 185 186 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 184 def process_at_ivar(exp) make_identifier(:ivar, exp) end |
#process_at_kw(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.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 196 def process_at_kw(exp) sym, pos = extract_node_symbol_with_position(exp) result = case sym when :__ENCODING__ s(:colon2, s(:const, :Encoding), :UTF_8) when :__FILE__ s(:str, @filename) when :__LINE__ s(:lit, pos[0]) else s(sym) end with_position(pos, result) end |
#process_at_label(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.
167 168 169 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 167 def process_at_label(exp) make_literal(exp) { |val| val.chop.to_sym } end |
#process_at_op(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.
192 193 194 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 192 def process_at_op(exp) make_identifier(:op, exp) end |
#process_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.
142 143 144 145 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 142 def process_BEGIN(exp) _, body = exp.shift 2 s(:iter, s(:preexe), s(:args), *map_process_sexp_body_compact(body)) end |
#process_class(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.
55 56 57 58 59 60 61 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 55 def process_class(exp) _, const_ref, parent, body = exp.shift 4 const, line = const_ref_to_const_with_line_number const_ref parent = process(parent) with_line_number(line, s(:class, const, parent, *class_or_module_body(body))) end |
#process_comment(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.
135 136 137 138 139 140 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 135 def process_comment(exp) _, comment, inner = exp.shift 3 sexp = process(inner) sexp.comments = comment sexp end |
#process_const_path_field(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.
107 108 109 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 107 def process_const_path_field(exp) s(:const, process_const_path_ref(exp)) end |
#process_const_path_ref(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.
102 103 104 105 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 102 def process_const_path_ref(exp) _, left, right = exp.shift 3 s(:colon2, process(left), extract_node_symbol(right)) end |
#process_const_ref(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.
111 112 113 114 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 111 def process_const_ref(exp) _, ref = exp.shift 3 process(ref) end |
#process_END(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.
147 148 149 150 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 147 def process_END(exp) _, body = exp.shift 2 s(:iter, s(:postexe), 0, *map_process_sexp_body_compact(body)) end |
#process_module(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.
48 49 50 51 52 53 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 48 def process_module(exp) _, const_ref, body = exp.shift 3 const, line = const_ref_to_const_with_line_number const_ref with_line_number(line, s(:module, const, *class_or_module_body(body))) end |
#process_paren(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.
125 126 127 128 129 130 131 132 133 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 125 def process_paren(exp) _, body = exp.shift 2 result = process body if result.sexp_type == :void_stmt s(:nil) else result end end |
#process_program(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.
42 43 44 45 46 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 42 def process_program(exp) _, content = exp.shift 2 process content end |
#process_sclass(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 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 63 def process_sclass(exp) _, klass, block = exp.shift 3 s(:sclass, process(klass), *class_or_module_body(block)) end |
#process_stmts(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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 68 def process_stmts(exp) _, *statements = shift_all(exp) statements = reject_void_stmt map_process_list statements case statements.count when 0 s(:void_stmt) when 1 statements.first else first = statements.shift if first.sexp_type == :block first.shift s(:block, *first, *statements) else s(:block, first, *statements) end end end |
#process_top_const_field(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.
121 122 123 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 121 def process_top_const_field(exp) s(:const, process_top_const_ref(exp)) end |
#process_top_const_ref(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.
116 117 118 119 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 116 def process_top_const_ref(exp) _, ref = exp.shift 2 s(:colon3, extract_node_symbol(ref)) end |
#process_var_alias(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.
97 98 99 100 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 97 def process_var_alias(exp) _, left, right = exp.shift 3 s(:valias, left[1].to_sym, right[1].to_sym) end |
#process_var_field(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.
92 93 94 95 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 92 def process_var_field(exp) _, contents = exp.shift 2 process(contents) end |
#process_var_ref(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.
87 88 89 90 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 87 def process_var_ref(exp) _, contents = exp.shift 2 process(contents) end |