module RipperRubyParser::SexpHandlers::Literals

Constants

SINGLE_LETTER_ESCAPES
SINGLE_LETTER_ESCAPES_REGEXP

Public Instance Methods

process_at_tstring_content(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 107
def process_at_tstring_content exp
  _, string, _ = exp.shift 3
  s(:str, string)
end
process_dyna_symbol(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 96
def process_dyna_symbol exp
  _, list = exp.shift 2

  string, rest = extract_unescaped_string_parts list
  if rest.empty?
    s(:lit, string.to_sym)
  else
    s(:dsym, string, *rest)
  end
end
process_regexp_literal(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 67
def process_regexp_literal exp
  _, content, (_, flags, _) = exp.shift 3

  string, rest = extract_string_parts content
  numflags = character_flags_to_numerical flags

  if rest.empty?
    s(:lit, Regexp.new(string, numflags))
  else
    rest << numflags if numflags > 0
    sexp_type = if flags =~ /o/
               :dregx_once
             else
               :dregx
             end
    s(sexp_type, string, *rest)
  end
end
process_string_concat(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 40
def process_string_concat exp
  _, left, right = exp.shift 3

  left = process(left)
  right = process(right)

  if left.sexp_type == :str
    right[1] = left[1] + right[1]
    right
  else # Expecting left.sexp_type == :dstr
    _, first, *rest = right
    left.push s(:str, first) unless first.empty?
    left.push(*rest)
    left
  end
end
process_string_content(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 9
def process_string_content exp
  exp.shift

  string, rest = extract_unescaped_string_parts exp

  if rest.empty?
    s(:str, string)
  else
    s(:dstr, string, *rest)
  end
end
process_string_dvar(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 34
def process_string_dvar exp
  _, list = exp.shift 2
  val = process(list)
  s(:dstr, "", s(:evstr, val))
end
process_string_embexpr(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 21
def process_string_embexpr exp
  _, list = exp.shift 2
  val = process(list.first)
  case val.sexp_type
  when :str
    val
  when :void_stmt
    s(:dstr, "", s(:evstr))
  else
    s(:dstr, "", s(:evstr, val))
  end
end
process_string_literal(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 4
def process_string_literal exp
  _, content = exp.shift 2
  process(content)
end
process_symbol(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 91
def process_symbol exp
  _, node = exp.shift 2
  with_position_from_node_symbol(node) {|sym| s(:lit, sym) }
end
process_symbol_literal(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 86
def process_symbol_literal exp
  _, symbol = exp.shift 2
  process(symbol)
end
process_xstring_literal(exp) click to toggle source
# File lib/ripper_ruby_parser/sexp_handlers/literals.rb, line 57
def process_xstring_literal exp
  _, content = exp.shift 2
  string, rest = extract_unescaped_string_parts content
  if rest.empty?
    s(:xstr, string)
  else
    s(:dxstr, string, *rest)
  end
end