-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Changed superclasses of all parsers to RubyParser::Parser
Fixed requires in a few of the new files + Moved RubyParser from ruby_parser_extras.rb into ruby_parser.rb to fix bootstrap issues. + Subclasses of RubyParser::Parser register themselves into RubyParser::VERSIONS. + RubyParser.for_current_ruby falls back to latest if current not available. + Added RubyParser.latest. + Renamed all parsers to RubyParser::V##. [git-p4: depot-paths = "//src/ruby_parser/dev/": change = 11261]
- Loading branch information
Showing
7 changed files
with
98 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ class String | |
attr_accessor :lineno | ||
end | ||
|
||
require "sexp" | ||
|
||
class Sexp | ||
attr_writer :paren | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require "strscan" | ||
|
||
class RPStringScanner < StringScanner | ||
# if ENV['TALLY'] then | ||
# alias :old_getch :getch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,80 @@ | ||
require 'ruby18_parser' | ||
require 'ruby19_parser' | ||
require 'ruby20_parser' | ||
require 'ruby21_parser' | ||
require 'ruby22_parser' | ||
require 'ruby23_parser' | ||
require 'ruby_parser_extras' | ||
require "ruby_parser_extras" | ||
require "racc/parser" | ||
|
||
## | ||
# RubyParser is a compound parser that uses all known versions to | ||
# attempt to parse. | ||
|
||
class RubyParser | ||
|
||
VERSIONS = [] | ||
|
||
class Parser < Racc::Parser | ||
include RubyParserStuff | ||
|
||
def self.inherited x | ||
RubyParser::VERSIONS << x | ||
end | ||
end | ||
|
||
class SyntaxError < RuntimeError; end | ||
|
||
def process s, f = "(string)", t = 10 | ||
e = nil | ||
VERSIONS.each do |klass| | ||
parser = klass.new | ||
begin | ||
return parser.process s, f, t | ||
rescue Racc::ParseError, RubyParser::SyntaxError => exc | ||
e = exc | ||
end | ||
end | ||
raise e | ||
end | ||
|
||
alias :parse :process | ||
|
||
def reset | ||
# do nothing | ||
end | ||
|
||
def self.latest | ||
VERSIONS.first.new | ||
end | ||
|
||
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 | ||
end | ||
|
||
## | ||
# Unfortunately a problem with racc is that it won't let me namespace | ||
# properly, so instead of RubyParser::V18, I still have to generate | ||
# the old Ruby23Parser and shove it in as V23. | ||
|
||
require "ruby18_parser" | ||
require "ruby19_parser" | ||
require "ruby20_parser" | ||
require "ruby21_parser" | ||
require "ruby22_parser" | ||
require "ruby23_parser" | ||
|
||
class RubyParser # HACK | ||
VERSIONS.clear # also a HACK caused by racc namespace issues | ||
|
||
class V23 < ::Ruby23Parser; end | ||
class V22 < ::Ruby22Parser; end | ||
class V21 < ::Ruby21Parser; end | ||
class V20 < ::Ruby20Parser; end | ||
class V19 < ::Ruby19Parser; end | ||
class V18 < ::Ruby18Parser; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters