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, V18, V19, V20, V21, V22, V23, V24, V25

Constant Summary collapse

VERSIONS =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_current_rubyObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ruby_parser.rb', line 49

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



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

def self.latest
  VERSIONS.first.new
end

Instance Method Details

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



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_parser.rb', line 26

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



41
42
43
# File 'lib/ruby_parser.rb', line 41

def reset
  # do nothing
end