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)
parens for emacs sigh.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ RubyParser
Returns a new instance of RubyParser.
1313 1314 1315 1316 1317 |
# File 'lib/ruby_parser_extras.rb', line 1313 def initialize @p18 = Ruby18Parser.new @p19 = Ruby19Parser.new @p20 = Ruby20Parser.new end |
Class Method Details
.for_current_ruby ⇒ Object
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 |
# File 'lib/ruby_parser_extras.rb', line 1336 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 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
1319 1320 1321 1322 1323 1324 1325 1326 1327 |
# File 'lib/ruby_parser_extras.rb', line 1319 def process(s, f = "(string)", t = 10) # parens for emacs *sigh* @p20.process s, f, t rescue Racc::ParseError, RubyParser::SyntaxError begin @p19.process s, f, t rescue Racc::ParseError, RubyParser::SyntaxError @p18.process s, f, t end end |
#reset ⇒ Object
1331 1332 1333 1334 |
# File 'lib/ruby_parser_extras.rb', line 1331 def reset @p18.reset @p19.reset end |