Module: RipperRubyParser::SexpHandlers::Conditionals Private

Defined in:
lib/ripper_ruby_parser/sexp_handlers/conditionals.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 conditionals

Instance Method Summary collapse

Instance Method Details

#process_aryptn(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.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 92

def process_aryptn(exp)
  _, _, body, rest, = exp.shift 5

  elements = body.map do |elem|
    if elem.sexp_type == :var_field
      create_valueless_assignment_sub_type process(elem)
    else
      unwrap_begin process(elem)
    end
  end
  if rest
    rest_var = handle_pattern(rest)
    elements << convert_marked_argument(s(:splat, rest_var))
  end
  s(:array_pat, nil, *elements)
end

#process_case(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.



48
49
50
51
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 48

def process_case(exp)
  _, expr, clauses = exp.shift 3
  s(:case, process(expr), *process(clauses).sexp_body)
end

#process_else(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.



87
88
89
90
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 87

def process_else(exp)
  _, body = exp.shift 2
  process(body)
end

#process_elsif(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.



15
16
17
18
19
20
21
22
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 15

def process_elsif(exp)
  _, cond, truepart, falsepart = exp.shift 4

  s(:if,
    unwrap_begin(process(cond)),
    handle_consequent(truepart),
    handle_consequent(falsepart))
end

#process_fndptn(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.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 122

def process_fndptn(exp)
  _, wrapper, before, patterns, after = exp.shift 5

  wrapper = process(wrapper)
  before = make_splat process(before)
  after = make_splat process(after)
  patterns = patterns.map do |elem|
    if elem.sexp_type == :var_field
      create_valueless_assignment_sub_type process(elem)
    else
      unwrap_begin process(elem)
    end
  end

  s(:find_pat, wrapper, before, *patterns, after)
end

#process_hshptn(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
118
119
120
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 109

def process_hshptn(exp)
  _, _, body, = exp.shift 4

  elements = body.flat_map do |key, value|
    if value
      [process(key), process(value)]
    else
      [handle_pattern(key), nil]
    end
  end
  s(:hash_pat, nil, *elements)
end

#process_if(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
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 7

def process_if(exp)
  _, cond, truepart, falsepart = exp.shift 4

  construct_conditional(handle_condition(cond),
                        handle_consequent(truepart),
                        handle_consequent(falsepart))
end

#process_if_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.



24
25
26
27
28
29
30
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 24

def process_if_mod(exp)
  _, cond, truepart = exp.shift 3

  construct_conditional(handle_condition(cond),
                        process(truepart),
                        nil)
end

#process_in(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
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 67

def process_in(exp)
  _, pattern, truepart, falsepart = exp.shift 4

  falsepart = process(falsepart)
  falsepart = if falsepart.nil?
                [nil]
              else
                falsepart.sexp_body
              end
  pattern = process(pattern)
  adjust_rightward_assignment_pattern(pattern)

  truepart = process(truepart)
  truepart = unwrap_nil(truepart) if truepart

  s(:case_body,
    s(:in, pattern, truepart),
    *falsepart)
end

#process_unless(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.



32
33
34
35
36
37
38
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 32

def process_unless(exp)
  _, cond, truepart, falsepart = exp.shift 4

  construct_conditional(handle_condition(cond),
                        handle_consequent(falsepart),
                        handle_consequent(truepart))
end

#process_unless_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.



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

def process_unless_mod(exp)
  _, cond, truepart = exp.shift 3

  construct_conditional(handle_condition(cond),
                        nil,
                        process(truepart))
end

#process_when(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.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ripper_ruby_parser/sexp_handlers/conditionals.rb', line 53

def process_when(exp)
  _, values, truepart, falsepart = exp.shift 4

  falsepart ||= s(:void_stmt)

  falsepart = unwrap_case_body process(falsepart)
  values = process(values).sexp_body
  truepart = unwrap_block process(truepart)

  s(:case_body,
    s(:when, s(:array, *values), *truepart),
    *falsepart)
end