module RipperRubyParser::SexpHandlers::Loops

Sexp handlers for loops

Public Instance Methods

process_for(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 23
def process_for(exp)
  _, var, coll, block = exp.shift 4
  coll = process(coll)
  var = process(var)

  var.sexp_type = :lasgn if var.sexp_type == :lvar
  block = unwrap_nil process(block)
  if block
    s(:for, coll, var, block)
  else
    s(:for, coll, var)
  end
end
process_until(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 7
def process_until(exp)
  handle_conditional_loop :until, :while, exp
end
process_until_mod(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 11
def process_until_mod(exp)
  handle_conditional_loop_mod :until, :while, exp
end
process_while(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 15
def process_while(exp)
  handle_conditional_loop :while, :until, exp
end
process_while_mod(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 19
def process_while_mod(exp)
  handle_conditional_loop_mod :while, :until, exp
end

Private Instance Methods

check_at_start?(block) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 39
def check_at_start?(block)
  block.sexp_type != :begin
end
construct_conditional_loop(type, negated_type, cond, body, check_at_start) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 64
def construct_conditional_loop(type, negated_type, cond, body, check_at_start)
  if cond.sexp_type == :not
    _, inner = cond
    s(negated_type, inner, body, check_at_start)
  else
    s(type, cond, body, check_at_start)
  end
end
handle_conditional_loop(type, negated_type, exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 43
def handle_conditional_loop(type, negated_type, exp)
  _, cond, body = exp.shift 3

  construct_conditional_loop(type, negated_type,
                             unwrap_begin(process(cond)),
                             unwrap_nil(process(body)),
                             true)
end
handle_conditional_loop_mod(type, negated_type, exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/loops.rb, line 52
def handle_conditional_loop_mod(type, negated_type, exp)
  _, cond, body = exp.shift 3

  cond = process(cond)
  body = process(body)
  check_at_start = check_at_start?(body)
  construct_conditional_loop(type, negated_type,
                             unwrap_begin(cond),
                             unwrap_begin(body),
                             check_at_start)
end