class RipperRubyParser::CommentingRipperParser

Variant of Ripper’s SexpBuilderPP parser class that inserts comments as Sexps into the built parse tree.

Public Instance Methods

on_alias_error(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 87
def on_alias_error *args
  raise SyntaxError.new(*args)
end
on_assign_error(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 91
def on_assign_error *args
  raise SyntaxError.new(*args)
end
on_class(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 43
def on_class *args
  commentize(:class, super)
end
on_class_name_error(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 83
def on_class_name_error *args
  raise SyntaxError.new(*args)
end
on_comment(tok) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 22
def on_comment tok
  @comment ||= ""
  @comment += tok
  super
end
on_def(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 51
def on_def *args
  commentize(:def, super)
end
on_defs(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 55
def on_defs *args
  commentize(:def, super)
end
on_dyna_symbol(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 74
def on_dyna_symbol *args
  @in_symbol = false
  super
end
on_embexpr_beg(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 69
def on_embexpr_beg *args
  @in_symbol = false
  super
end
on_kw(tok) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 28
def on_kw tok
  case tok
  when "class", "def", "module"
    unless @in_symbol
      @comment_stack.push [tok.to_sym, @comment]
      @comment = nil
    end
  end
  super
end
on_module(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 39
def on_module *args
  commentize(:module, super)
end
on_param_error(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 95
def on_param_error *args
  raise SyntaxError.new(*args)
end
on_parse_error(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 79
def on_parse_error *args
  raise SyntaxError.new(*args)
end
on_sclass(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 47
def on_sclass *args
  commentize(:class, super)
end
on_symbeg(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 59
def on_symbeg *args
  @in_symbol = true
  super
end
on_symbol(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 64
def on_symbol *args
  @in_symbol = false
  super
end
parse() click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 15
def parse
  result = suppress_warnings { super }
  raise "Ripper parse failed." unless result

  Sexp.from_array(result)
end

Public Class Methods

new(*args) click to toggle source
# File lib/ripper_ruby_parser/commenting_ripper_parser.rb, line 8
def initialize *args
  super
  @comment = nil
  @comment_stack = []
  @in_symbol = false
end