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, V27, V30

Constant Summary collapse

VERSIONS =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currentObject

Returns the value of attribute current


12
13
14
# File 'lib/ruby_parser.rb', line 12

def current
  @current
end

Class Method Details

.for_current_rubyObject


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_parser.rb', line 14

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


27
28
29
# File 'lib/ruby_parser.rb', line 27

def self.latest
  VERSIONS.first.new
end

Instance Method Details

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


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

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

#resetObject


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

def reset
  # do nothing
end