Class: RipperRubyParser::SexpProcessor Private
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- RipperRubyParser::SexpProcessor
- Includes:
- SexpHandlers, Unescape
- 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.
Constant Summary
Constants included from Unescape
Unescape::ESCAPE_SEQUENCE_REGEXP, Unescape::SINGLE_LETTER_ESCAPES, Unescape::SINGLE_LETTER_ESCAPES_REGEXP
Instance Attribute Summary collapse
- #extra_compatible ⇒ Object readonly private
- #filename ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(filename: nil, extra_compatible: nil) ⇒ SexpProcessor
constructor
private
A new instance of SexpProcessor.
- #process_at_backref(exp) ⇒ Object private
- #process_at_backtick(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_at_period(exp) ⇒ Object private
- #process_at_rational(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
- #process_void_stmt(exp) ⇒ Object private
Methods included from SexpHandlers
Methods included from Unescape
#fix_encoding, #simple_unescape, #simple_unescape_wordlist_word, #unescape, #unescape_regexp, #unescape_wordlist_word
Constructor Details
#initialize(filename: nil, extra_compatible: 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.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 17 def initialize(filename: nil, extra_compatible: nil) super() @processors[:@int] = :process_at_int @processors[:@float] = :process_at_float @processors[:@rational] = :process_at_rational @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[:@backtick] = :process_at_backtick @processors[:@period] = :process_at_period @processors[:@tstring_content] = :process_at_tstring_content @filename = filename @extra_compatible = extra_compatible @errors = [] @in_method_body = false @kwrest = [] @block_kwrest = [] @kept_comment = nil end |
Instance Attribute Details
#extra_compatible ⇒ 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.
15 16 17 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 15 def extra_compatible @extra_compatible end |
#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.
14 15 16 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 14 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.
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 240 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_backtick(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.
221 222 223 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 221 def process_at_backtick(exp) make_identifier(:backtick, exp) 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
187 188 189 190 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 187 def process_at_CHAR(exp) _, val, pos = exp.shift 3 with_position(pos, s(:str, 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
197 198 199 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 197 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.
201 202 203 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 201 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.
178 179 180 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 178 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.
205 206 207 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 205 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.
213 214 215 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 213 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
174 175 176 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 174 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.
209 210 211 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 209 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.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 225 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.
192 193 194 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 192 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.
217 218 219 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 217 def process_at_op(exp) make_identifier(:op, exp) end |
#process_at_period(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.
252 253 254 255 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 252 def process_at_period(exp) _, period, = exp.shift 3 s(:period, period) end |
#process_at_rational(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.
182 183 184 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 182 def process_at_rational(exp) make_literal(exp, &:to_r) 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.
161 162 163 164 165 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 161 def process_BEGIN(exp) _, body, pos = exp.shift 3 body = reject_void_stmt map_process_list body.sexp_body with_position pos, s(:iter, s(:preexe), 0, *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.
67 68 69 70 71 72 73 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 67 def process_class(exp) _, const_ref, parent, body, pos = exp.shift 5 const = const_ref_to_const const_ref parent = process(parent) with_position(pos, 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.
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 147 def process_comment(exp) _, comment, inner = exp.shift 3 comment = @kept_comment + comment if @kept_comment @kept_comment = nil sexp = process(inner) case sexp.sexp_type when :defs, :defn, :module, :class, :sclass sexp.comments = comment else @kept_comment = comment end 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.
119 120 121 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 119 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.
114 115 116 117 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 114 def process_const_path_ref(exp) _, left, right = exp.shift 3 s(:colon2, process(left), extract_node_symbol(process(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.
123 124 125 126 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 123 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.
167 168 169 170 171 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 167 def process_END(exp) _, body, pos = exp.shift 3 body = map_process_list_compact body.sexp_body with_position pos, s(:iter, s(:postexe), 0, *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.
60 61 62 63 64 65 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 60 def process_module(exp) _, const_ref, body, pos = exp.shift 4 const = const_ref_to_const const_ref with_position(pos, 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.
137 138 139 140 141 142 143 144 145 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 137 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.
54 55 56 57 58 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 54 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.
75 76 77 78 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 75 def process_sclass(exp) _, klass, block, pos = exp.shift 4 with_position pos, 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 80 def process_stmts(exp) _, *statements = shift_all(exp) statements = map_process_list_compact statements case statements.count when 0 s(:void_stmt) when 1 statements.first else first = statements.shift s(:block, *unwrap_block(first), *statements) 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.
133 134 135 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 133 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.
128 129 130 131 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 128 def process_top_const_ref(exp) _, ref = exp.shift 2 s(:colon3, extract_node_symbol(process(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.
104 105 106 107 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 104 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.
99 100 101 102 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 99 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.
94 95 96 97 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 94 def process_var_ref(exp) _, contents = exp.shift 2 process(contents) end |
#process_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.
109 110 111 112 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 109 def process_void_stmt(exp) _, pos = exp.shift 2 with_position pos, s(:void_stmt) end |