Class: RubyParser

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

Overview

RubyParser is a compound parser that first attempts to parse using the 1.9 syntax parser and falls back to the 1.8 syntax parser on a parse error.

Defined Under Namespace

Classes: SyntaxError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRubyParser

Returns a new instance of RubyParser.



1284
1285
1286
1287
# File 'lib/ruby_parser_extras.rb', line 1284

def initialize
  @p18 = Ruby18Parser.new
  @p19 = Ruby19Parser.new
end

Class Method Details

.for_current_rubyObject



1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
# File 'lib/ruby_parser_extras.rb', line 1302

def self.for_current_ruby
  case RUBY_VERSION
  when /^1\.8/ then
    Ruby18Parser.new
  when /^1\.9/ then
    Ruby19Parser.new
  else
    raise "unrecognized RUBY_VERSION #{RUBY_VERSION}"
  end
end

Instance Method Details

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

parens for emacs sigh



1289
1290
1291
1292
1293
# File 'lib/ruby_parser_extras.rb', line 1289

def process(s, f = "(string)", t = 10) # parens for emacs *sigh*
  @p19.process s, f, t
rescue Racc::ParseError
  @p18.process s, f, t
end

#resetObject



1297
1298
1299
1300
# File 'lib/ruby_parser_extras.rb', line 1297

def reset
  @p18.reset
  @p19.reset
end