Class: RubyParser
- Inherits:
-
Object
- Object
- RubyParser
- 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
-
#initialize ⇒ RubyParser
constructor
A new instance of RubyParser.
- #process(s, f = "(string)", t = 10) ⇒ Object (also: #parse)
- #reset ⇒ Object
Constructor Details
#initialize ⇒ RubyParser
Returns a new instance of RubyParser.
1346 1347 1348 1349 1350 1351 |
# File 'lib/ruby_parser_extras.rb', line 1346 def initialize @p18 = Ruby18Parser.new @p19 = Ruby19Parser.new @p20 = Ruby20Parser.new @p21 = Ruby21Parser.new end |
Class Method Details
.for_current_ruby ⇒ Object
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 |
# File 'lib/ruby_parser_extras.rb', line 1374 def self.for_current_ruby case RUBY_VERSION when /^1\.8/ then Ruby18Parser.new when /^1\.9/ then Ruby19Parser.new when /^2.0/ then Ruby20Parser.new when /^2.1/ then Ruby21Parser.new else raise "unrecognized RUBY_VERSION #{RUBY_VERSION}" end end |
Instance Method Details
#process(s, f = "(string)", t = 10) ⇒ Object Also known as: parse
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 |
# File 'lib/ruby_parser_extras.rb', line 1353 def process s, f = "(string)", t = 10 e = nil [@p21, @p20, @p19, @p18].each do |parser| begin return parser.process s, f, t rescue Racc::ParseError, RubyParser::SyntaxError => exc e = exc end end raise e end |
#reset ⇒ Object
1367 1368 1369 1370 1371 1372 |
# File 'lib/ruby_parser_extras.rb', line 1367 def reset @p18.reset @p19.reset @p20.reset @p21.reset end |