Module: RipperRubyParser::SexpHandlers::Blocks Private
- Defined in:
- lib/ripper_ruby_parser/sexp_handlers/blocks.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.
Sexp handlers for blocks and related constructs
Instance Method Summary collapse
- #process_begin(exp) ⇒ Object private
- #process_block_var(exp) ⇒ Object private
- #process_bodystmt(exp) ⇒ Object private
- #process_break(exp) ⇒ Object private
- #process_ensure(exp) ⇒ Object private
- #process_kwrest_param(exp) ⇒ Object private
- #process_lambda(exp) ⇒ Object private
- #process_method_add_block(exp) ⇒ Object private
- #process_next(exp) ⇒ Object private
-
#process_params(exp) ⇒ Object
private
NOTE: Argument forwarding is handled differently in Ruby 3.0 and 3.1 3.0: s(:params, nil, nil, s(:args_forward), nil, nil, nil, nil) 3.1: s(:params, nil, nil, nil, nil, nil, s(:args_forward), :&).
- #process_rescue(exp) ⇒ Object private
- #process_rescue_mod(exp) ⇒ Object private
- #process_rest_param(exp) ⇒ Object private
Instance Method Details
#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.
58 59 60 61 62 63 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 58 def process_begin(exp) _, body, pos = exp.shift 3 body = convert_void_stmt_to_nil_symbol process(body) with_position pos, s(:begin, body) end |
#process_block_var(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.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 45 def process_block_var(exp) _, args, shadowargs = exp.shift 3 names = process(args) if shadowargs shadowargs = map_process_list(shadowargs).map { |item| item[1] } names << s(:shadow, *shadowargs) end convert_arguments names end |
#process_bodystmt(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.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 77 def process_bodystmt(exp) _, main, rescue_block, else_block, ensure_block = exp.shift 5 body_list = [] main_block = process(main) line = main_block.line body_list << main_block if main_block.sexp_type != :void_stmt body_list.push(*process(rescue_block)) if rescue_block body_list << process(else_block) if else_block body_list = [s(:rescue, *body_list)] if rescue_block if ensure_block body_list << process(ensure_block) body_list = [s(:ensure, *body_list)] end wrap_in_block(body_list, line) end |
#process_break(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 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 119 def process_break(exp) _, args = exp.shift 2 args = handle_return_argument_list(args) if args.empty? s(:break) else s(:break, args) end end |
#process_ensure(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_handlers/blocks.rb', line 104 def process_ensure(exp) _, block = exp.shift 2 convert_empty_to_nil_symbol safe_unwrap_void_stmt process(block) end |
#process_kwrest_param(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.
40 41 42 43 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 40 def process_kwrest_param(exp) _, sym, = exp.shift 3 process(sym) || s(:lvar, :"") end |
#process_lambda(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.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 129 def process_lambda(exp) _, args, statements = exp.shift 3 old_type = args.sexp_type args = convert_arguments(process(args)) statements = process(statements) line = args.line || statements.line args = nil if args == s(:args) && old_type == :params call = s(:lambda) call.line = line make_iter call, args, safe_unwrap_void_stmt(statements) end |
#process_method_add_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.
7 8 9 10 11 12 13 14 15 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 7 def process_method_add_block(exp) _, call, block = exp.shift 3 _, args, stmt = block call = process(call) args = process(args) kwrest = kwrest_param(args) if args stmt = with_new_lvar_scope(kwrest) { process(stmt) } make_iter call, args, safe_unwrap_void_stmt(stmt) end |
#process_next(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 114 115 116 117 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 109 def process_next(exp) _, args = exp.shift 2 args = handle_return_argument_list(args) if args.empty? s(:next) else s(:next, args) end end |
#process_params(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.
NOTE: Argument forwarding is handled differently in Ruby 3.0 and 3.1 3.0: s(:params, nil, nil, s(:args_forward), nil, nil, nil, nil) 3.1: s(:params, nil, nil, nil, nil, nil, s(:args_forward), :&)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 20 def process_params(exp) _, normal, defaults, splat, rest, kwargs, doublesplat, block = exp.shift 8 args = handle_normal_arguments(normal) + handle_default_arguments(defaults) + handle_splat(splat) + handle_normal_arguments(rest) + handle_kwargs(kwargs) + handle_double_splat(doublesplat) + handle_block_argument(block) s(:args, *args) end |
#process_rescue(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.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 65 def process_rescue(exp) _, eclass, evar, block, after = exp.shift 5 rescue_block = map_process_list_compact block.sexp_body rescue_block << nil if rescue_block.empty? capture = handle_rescue_class_list eclass capture << create_assignment_sub_type(process(evar), s(:gvar, :$!)) if evar s(s(:resbody, capture, *rescue_block), *process(after)) end |
#process_rescue_mod(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.
98 99 100 101 102 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 98 def process_rescue_mod(exp) _, scary, safe = exp.shift 3 s(:rescue, process(scary), s(:resbody, s(:array), process(safe))) end |
#process_rest_param(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.
35 36 37 38 |
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 35 def process_rest_param(exp) _, ident = exp.shift 2 s(:splat, process(ident)) end |