Class: RubyParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_parser.rb,
lib/ruby_parser.rb

Overview

HACK

Defined Under Namespace

Classes: Parser, SyntaxError, V20, V21, V22, V23, V24, V25, V26

Constant Summary collapse

VERSIONS =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_current_rubyObject



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

def self.for_current_ruby
  name  = "V#{RUBY_VERSION[/^\d+\.\d+/].delete "."}"
  klass = if const_defined? name then
            const_get name
          else
            latest = VERSIONS.first
            warn "NOTE: RubyParser::#{name} undefined, using #{latest}."
            latest
          end

  klass.new
end

.latestObject



49
50
51
# File 'lib/ruby_parser.rb', line 49

def self.latest
  VERSIONS.first.new
end

Instance Method Details

#process(s, f = "(string)", t = 10) ⇒ Object Also known as: parse



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_parser.rb', line 30

def process s, f = "(string)", t = 10
  e = nil
  VERSIONS.each do |klass|
    parser = klass.new
    begin
      return parser.process s, f, t
    rescue Racc::ParseError, RubyParser::SyntaxError => exc
      e ||= exc
    end
  end
  raise e
end

#resetObject



45
46
47
# File 'lib/ruby_parser.rb', line 45

def reset
  # do nothing
end