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

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.



49
50
51
52
53
54
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 49

def process_begin(exp)
  _, body, pos = exp.shift 3

  body = convert_empty_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.



41
42
43
44
45
46
47
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 41

def process_block_var(exp)
  _, args, = exp.shift 3

  names = process(args)

  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.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 84

def process_bodystmt(exp)
  _, main, rescue_block, else_block, ensure_block = exp.shift 5

  body = s()

  main_list = map_unwrap_begin_list map_process_list main.sexp_body
  line = main_list.first.line
  main = wrap_in_block reject_void_stmt main_list
  body << main if main

  if rescue_block
    body.push(*process(rescue_block))
    body << process(else_block) if else_block
    body = s(s(:rescue, *body))
  elsif else_block
    body << process(else_block)
  end

  if ensure_block
    body << process(ensure_block)
    body = s(s(:ensure, *body))
  end

  wrap_in_block(body) || s().line(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.



131
132
133
134
135
136
137
138
139
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 131

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.



116
117
118
119
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 116

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.



36
37
38
39
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 36

def process_kwrest_param(exp)
  _, sym, = exp.shift 3
  process(sym)
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.



141
142
143
144
145
146
147
148
149
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 141

def process_lambda(exp)
  _, args, statements = exp.shift 3
  old_type = args.sexp_type
  args = convert_arguments(process(args))
  args = nil if args == s(:args) && old_type == :params
  make_iter(s(:call, nil, :lambda),
            args,
            safe_unwrap_void_stmt(process(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_kwrest(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.



121
122
123
124
125
126
127
128
129
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 121

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.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 17

def process_params(exp)
  _, normal, defaults, splat, rest, kwargs, doublesplat, block = exp.shift 8

  args = handle_normal_arguments normal
  args += handle_default_arguments defaults
  args += handle_splat splat
  args += handle_normal_arguments rest
  args += handle_kwargs kwargs
  args += handle_double_splat doublesplat
  args += 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.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 56

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 = if eclass
              if eclass.first.is_a? Symbol
                eclass = process(eclass)
                body = eclass.sexp_body
                if eclass.sexp_type == :mrhs
                  body.first
                else
                  s(:array, *body)
                end
              else
                s(:array, process(eclass.first))
              end
            else
              s(:array)
            end

  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.



110
111
112
113
114
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 110

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.



31
32
33
34
# File 'lib/ripper_ruby_parser/sexp_handlers/blocks.rb', line 31

def process_rest_param(exp)
  _, ident = exp.shift 2
  s(:splat, process(ident))
end