class RubyParser

RubyParser is a compound parser that uses all known versions to attempt to parse.

Constants

VERSIONS

Attributes

current[RW]

Public Class Methods

for_current_ruby() click to toggle source
# 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
latest() click to toggle source
# File lib/ruby_parser.rb, line 27
def self.latest
  VERSIONS.first.new
end

Public Instance Methods

parse(s, f = "(string)", t = 10)
Alias for: process
process(s, f = "(string)", t = 10) click to toggle source
# 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
Also aliased as: parse
reset() click to toggle source
# File lib/ruby_parser.rb, line 46
def reset
  # do nothing
end