Class: RipperRubyParser::CommentingRipperParser Private
- Inherits:
-
Ripper::SexpBuilder
- Object
- Ripper::SexpBuilder
- RipperRubyParser::CommentingRipperParser
- Defined in:
- lib/ripper_ruby_parser/commenting_ripper_parser.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.
Variant of Ripper’s SexpBuilder parser class that inserts comments as Sexps into the built parse tree.
Constant Summary collapse
- NUMBER_LITERAL_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[:@int, :@float].freeze
Instance Method Summary collapse
-
#initialize(*args) ⇒ CommentingRipperParser
constructor
private
A new instance of CommentingRipperParser.
- #on_alias_error(*args) ⇒ Object private
- #on_args_add(list, elem) ⇒ Object private
- #on_args_new ⇒ Object private
- #on_assign_error(*args) ⇒ Object private
- #on_backtick(delimiter) ⇒ Object private
- #on_class(*args) ⇒ Object private
- #on_class_name_error(*args) ⇒ Object private
- #on_comment(tok) ⇒ Object private
- #on_def(*args) ⇒ Object private
- #on_defs(*args) ⇒ Object private
- #on_dyna_symbol(*args) ⇒ Object private
- #on_embexpr_beg(_delimiter) ⇒ Object private
- #on_float(_token) ⇒ Object private
- #on_heredoc_beg(delimiter) ⇒ Object private
- #on_heredoc_end(delimiter) ⇒ Object private
- #on_int(_token) ⇒ Object private
- #on_kw(tok) ⇒ Object private
- #on_mlhs_add(list, elem) ⇒ Object private
- #on_mlhs_new ⇒ Object private
- #on_module(*args) ⇒ Object private
- #on_mrhs_add(list, elem) ⇒ Object private
- #on_mrhs_new ⇒ Object private
- #on_op(token) ⇒ Object private
- #on_param_error(*args) ⇒ Object private
- #on_parse_error(*args) ⇒ Object private
- #on_qsymbols_add(list, elem) ⇒ Object private
- #on_qsymbols_beg(delimiter) ⇒ Object private
- #on_qsymbols_new ⇒ Object private
- #on_qwords_add(list, elem) ⇒ Object private
- #on_qwords_beg(delimiter) ⇒ Object private
- #on_qwords_new ⇒ Object private
- #on_regexp_add(list, elem) ⇒ Object private
- #on_regexp_beg(delimiter) ⇒ Object private
- #on_regexp_end(delimiter) ⇒ Object private
- #on_regexp_new ⇒ Object private
- #on_sclass(*args) ⇒ Object private
- #on_sp(_token) ⇒ Object private
- #on_stmts_add(list, elem) ⇒ Object private
- #on_stmts_new ⇒ Object private
- #on_string_add(list, elem) ⇒ Object private
- #on_symbeg(delimiter) ⇒ Object private
- #on_symbol(*args) ⇒ Object private
- #on_symbols_add(list, elem) ⇒ Object private
- #on_symbols_beg(delimiter) ⇒ Object private
- #on_symbols_new ⇒ Object private
- #on_tstring_beg(delimiter) ⇒ Object private
- #on_tstring_content(content) ⇒ Object private
- #on_tstring_end(delimiter) ⇒ Object private
- #on_unary(operator, value) ⇒ Object private
- #on_word_add(list, elem) ⇒ Object private
- #on_word_new ⇒ Object private
- #on_words_add(list, elem) ⇒ Object private
- #on_words_beg(delimiter) ⇒ Object private
- #on_words_new ⇒ Object private
- #on_xstring_add(list, elem) ⇒ Object private
- #on_xstring_new ⇒ Object private
- #parse ⇒ Object private
Constructor Details
#initialize(*args) ⇒ CommentingRipperParser
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 CommentingRipperParser.
11 12 13 14 15 16 17 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 11 def initialize(*args) super @comment = nil @comment_stack = [] @delimiter_stack = [] @in_symbol = false end |
Instance Method Details
#on_alias_error(*args) ⇒ 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.
290 291 292 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 290 def on_alias_error(*args) raise SyntaxError, *args end |
#on_args_add(list, elem) ⇒ 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.
72 73 74 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 72 def on_args_add(list, elem) list << elem end |
#on_args_new ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 68 def on_args_new [:args] end |
#on_assign_error(*args) ⇒ 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.
294 295 296 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 294 def on_assign_error(*args) raise SyntaxError, *args end |
#on_backtick(delimiter) ⇒ 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/commenting_ripper_parser.rb', line 26 def on_backtick(delimiter) @delimiter_stack.push delimiter super end |
#on_class(*args) ⇒ 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.
52 53 54 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 52 def on_class(*args) commentize(:class, super) end |
#on_class_name_error(*args) ⇒ 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.
286 287 288 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 286 def on_class_name_error(*args) raise SyntaxError, *args end |
#on_comment(tok) ⇒ 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 35 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 31 def on_comment(tok) @comment ||= '' @comment += tok super end |
#on_def(*args) ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 60 def on_def(*args) commentize(:def, super) end |
#on_defs(*args) ⇒ 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.
64 65 66 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 64 def on_defs(*args) commentize(:def, super) end |
#on_dyna_symbol(*args) ⇒ 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.
277 278 279 280 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 277 def on_dyna_symbol(*args) @in_symbol = false super end |
#on_embexpr_beg(_delimiter) ⇒ 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.
272 273 274 275 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 272 def on_embexpr_beg(_delimiter) @in_symbol = false super end |
#on_float(_token) ⇒ 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.
241 242 243 244 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 241 def on_float(_token) @space_before = @seen_space super end |
#on_heredoc_beg(delimiter) ⇒ 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.
76 77 78 79 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 76 def on_heredoc_beg(delimiter) @delimiter_stack.push delimiter super end |
#on_heredoc_end(delimiter) ⇒ 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.
81 82 83 84 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 81 def on_heredoc_end(delimiter) @delimiter_stack.pop super end |
#on_int(_token) ⇒ 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.
236 237 238 239 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 236 def on_int(_token) @space_before = @seen_space super end |
#on_kw(tok) ⇒ 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.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 37 def on_kw(tok) case tok when 'class', 'def', 'module' unless @in_symbol @comment_stack.push [tok.to_sym, @comment] @comment = nil end end super end |
#on_mlhs_add(list, elem) ⇒ 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 94 95 96 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 90 def on_mlhs_add(list, elem) if list.first == :mlhs list << elem else [:mlhs_add_post, list, elem] end end |
#on_mlhs_new ⇒ 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.
86 87 88 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 86 def on_mlhs_new [:mlhs] end |
#on_module(*args) ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 48 def on_module(*args) commentize(:module, super) end |
#on_mrhs_add(list, elem) ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 102 def on_mrhs_add(list, elem) list << elem end |
#on_mrhs_new ⇒ 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.
98 99 100 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 98 def on_mrhs_new [:mrhs] end |
#on_op(token) ⇒ 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.
226 227 228 229 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 226 def on_op(token) @seen_space = false super end |
#on_param_error(*args) ⇒ 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.
298 299 300 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 298 def on_param_error(*args) raise SyntaxError, *args end |
#on_parse_error(*args) ⇒ 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.
282 283 284 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 282 def on_parse_error(*args) raise SyntaxError, *args end |
#on_qsymbols_add(list, elem) ⇒ 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.
115 116 117 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 115 def on_qsymbols_add(list, elem) list << elem end |
#on_qsymbols_beg(delimiter) ⇒ 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.
106 107 108 109 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 106 def on_qsymbols_beg(delimiter) @delimiter_stack.push delimiter super end |
#on_qsymbols_new ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 111 def on_qsymbols_new [:qsymbols] end |
#on_qwords_add(list, elem) ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 128 def on_qwords_add(list, elem) list << elem end |
#on_qwords_beg(delimiter) ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 119 def on_qwords_beg(delimiter) @delimiter_stack.push delimiter super end |
#on_qwords_new ⇒ 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.
124 125 126 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 124 def on_qwords_new [:qwords] end |
#on_regexp_add(list, elem) ⇒ 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.
146 147 148 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 146 def on_regexp_add(list, elem) list << elem end |
#on_regexp_beg(delimiter) ⇒ 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.
132 133 134 135 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 132 def on_regexp_beg(delimiter) @delimiter_stack.push delimiter super end |
#on_regexp_end(delimiter) ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 137 def on_regexp_end(delimiter) @delimiter_stack.pop super end |
#on_regexp_new ⇒ 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 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 142 def on_regexp_new [:regexp] end |
#on_sclass(*args) ⇒ 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.
56 57 58 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 56 def on_sclass(*args) commentize(:class, super) end |
#on_sp(_token) ⇒ 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.
231 232 233 234 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 231 def on_sp(_token) @seen_space = true super end |
#on_stmts_add(list, elem) ⇒ 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/commenting_ripper_parser.rb', line 154 def on_stmts_add(list, elem) list << elem end |
#on_stmts_new ⇒ 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.
150 151 152 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 150 def on_stmts_new [:stmts] end |
#on_string_add(list, elem) ⇒ 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/commenting_ripper_parser.rb', line 158 def on_string_add(list, elem) list << elem end |
#on_symbeg(delimiter) ⇒ 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.
261 262 263 264 265 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 261 def on_symbeg(delimiter) @delimiter_stack.push delimiter @in_symbol = true super end |
#on_symbol(*args) ⇒ 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.
267 268 269 270 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 267 def on_symbol(*args) @in_symbol = false super end |
#on_symbols_add(list, elem) ⇒ 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.
171 172 173 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 171 def on_symbols_add(list, elem) list << elem end |
#on_symbols_beg(delimiter) ⇒ 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 165 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 162 def on_symbols_beg(delimiter) @delimiter_stack.push delimiter super end |
#on_symbols_new ⇒ 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/commenting_ripper_parser.rb', line 167 def on_symbols_new [:symbols] end |
#on_tstring_beg(delimiter) ⇒ 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.
175 176 177 178 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 175 def on_tstring_beg(delimiter) @delimiter_stack.push delimiter super end |
#on_tstring_content(content) ⇒ 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 183 184 185 186 187 188 189 190 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 180 def on_tstring_content(content) content = case @delimiter_stack.last when '"', '`', ':"', /^<</, /^%I/, /^%Q/, /^%W/ Unescape.unescape(content) when "'", ":'" Unescape.simple_unescape(content) else content end super(content) end |
#on_tstring_end(delimiter) ⇒ 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 195 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 192 def on_tstring_end(delimiter) @delimiter_stack.pop super end |
#on_unary(operator, value) ⇒ 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.
248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 248 def on_unary(operator, value) if !@space_before && operator == :-@ && NUMBER_LITERAL_TYPES.include?(value.first) type, literal, lines = value if literal[0] == '-' super else [type, "-#{literal}", lines] end else super end end |
#on_word_add(list, elem) ⇒ 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/commenting_ripper_parser.rb', line 201 def on_word_add(list, elem) list << elem end |
#on_word_new ⇒ 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.
197 198 199 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 197 def on_word_new [:word] end |
#on_words_add(list, elem) ⇒ 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.
214 215 216 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 214 def on_words_add(list, elem) list << elem end |
#on_words_beg(delimiter) ⇒ 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/commenting_ripper_parser.rb', line 205 def on_words_beg(delimiter) @delimiter_stack.push delimiter super end |
#on_words_new ⇒ 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.
210 211 212 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 210 def on_words_new [:words] end |
#on_xstring_add(list, elem) ⇒ 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.
222 223 224 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 222 def on_xstring_add(list, elem) list << elem end |
#on_xstring_new ⇒ 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.
218 219 220 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 218 def on_xstring_new [:xstring] end |
#parse ⇒ 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.
19 20 21 22 23 24 |
# File 'lib/ripper_ruby_parser/commenting_ripper_parser.rb', line 19 def parse result = suppress_warnings { super } raise 'Ripper parse failed.' unless result Sexp.from_array(result) end |