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.
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_ruby ⇒ Object
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 |
#reset ⇒ Object
1297 1298 1299 1300 |
# File 'lib/ruby_parser_extras.rb', line 1297 def reset @p18.reset @p19.reset end |