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::DELIMITER_PAIRS, 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_const(exp) ⇒ Object
private
symbol-like sexps.
- #process_at_cvar(exp) ⇒ Object private
- #process_at_gvar(exp) ⇒ Object private
- #process_at_ident(exp) ⇒ Object private
- #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_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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 16 def initialize(filename: nil, extra_compatible: nil) super() public_methods.each do |name| @processors[:"@#{Regexp.last_match(1)}"] = name.to_sym if name =~ /^process_at_(.*)/ end @filename = filename @extra_compatible = extra_compatible @errors = [] @in_method_body = false @local_variables = [] @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.
14 15 16 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 14 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.
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 193 def process_at_backref(exp) _, str, pos = exp.shift 3 name = str[1..] with_position pos do if /[0-9]/.match?(name) 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.
174 175 176 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 174 def process_at_backtick(exp) make_identifier(:backtick, exp) 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
150 151 152 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 150 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.
154 155 156 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 154 def process_at_cvar(exp) make_identifier(:cvar, exp) 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.
158 159 160 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 158 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.
166 167 168 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 166 def process_at_ident(exp) make_identifier(:lvar, exp) 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.
162 163 164 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 162 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.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 178 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.
145 146 147 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 145 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.
170 171 172 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 170 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.
205 206 207 208 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 205 def process_at_period(exp) _, period, = exp.shift 3 s(:period, period) 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.
133 134 135 136 137 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 133 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.
49 50 51 52 53 54 55 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 49 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.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 119 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.
95 96 97 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 95 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.
90 91 92 93 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 90 def process_const_path_ref(exp) _, left, right = exp.shift 3 s(:colon2, process(left), make_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.
99 100 101 102 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 99 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.
139 140 141 142 143 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 139 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.
42 43 44 45 46 47 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 42 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.
113 114 115 116 117 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 113 def process_paren(exp) _, body = exp.shift 2 result = process body convert_void_stmt_to_nil_symbol result 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.
36 37 38 39 40 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 36 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.
57 58 59 60 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 57 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.
62 63 64 65 66 67 68 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 62 def process_stmts(exp) _, *statements = shift_all(exp) statements = map_unwrap_begin_list map_process_list statements line = statements.first.line statements = reject_void_stmt statements wrap_in_block(statements, line) 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.
109 110 111 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 109 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.
104 105 106 107 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 104 def process_top_const_ref(exp) _, ref = exp.shift 2 s(:colon3, make_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.
80 81 82 83 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 80 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.
75 76 77 78 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 75 def process_var_field(exp) _, contents = exp.shift 2 process(contents) || s(:lvar, nil) 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.
70 71 72 73 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 70 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.
85 86 87 88 |
# File 'lib/ripper_ruby_parser/sexp_processor.rb', line 85 def process_void_stmt(exp) _, pos = exp.shift 2 with_position pos, s(:void_stmt) end |