diff options
-rw-r--r-- | lib/rubygems/request_set/gem_dependency_api.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/request_set/lockfile/parser.rb | 97 | ||||
-rw-r--r-- | lib/rubygems/request_set/lockfile/tokenizer.rb | 29 |
3 files changed, 71 insertions, 57 deletions
@@ -396,7 +396,7 @@ Gem dependencies file #{@path} requires #{name} more than once. ## # Handles the git: option from +options+ for gem +name+. # - # Returns +true+ if the path option was handled. def gem_git name, options # :nodoc: if gist = options.delete(:gist) then @@ -11,13 +11,13 @@ class Gem::RequestSet::Lockfile::Parser def parse until @tokens.empty? do - type, data, column, line = get - case type when :section then @tokens.skip :newline - case data when 'DEPENDENCIES' then parse_DEPENDENCIES when 'GIT' then @@ -29,10 +29,10 @@ class Gem::RequestSet::Lockfile::Parser when 'PLATFORMS' then parse_PLATFORMS else - type, = get until @tokens.empty? or peek.first == :section end else - raise "BUG: unhandled token #{type} (#{data.inspect}) at line #{line} column #{column}" end end end @@ -41,35 +41,33 @@ class Gem::RequestSet::Lockfile::Parser # Gets the next token for a Lockfile def get expected_types = nil, expected_value = nil # :nodoc: - current_token = @tokens.shift - type, value, column, line = current_token - if expected_types and not Array(expected_types).include? type then - unget current_token - - message = "unexpected token [#{type.inspect}, #{value.inspect}], " + "expected #{expected_types.inspect}" - raise Gem::RequestSet::Lockfile::ParseError.new message, column, line, @filename end - if expected_value and expected_value != value then - unget current_token - message = "unexpected token [#{type.inspect}, #{value.inspect}], " + "expected [#{expected_types.inspect}, " + "#{expected_value.inspect}]" - raise Gem::RequestSet::Lockfile::ParseError.new message, column, line, @filename end - current_token end def parse_DEPENDENCIES # :nodoc: - while not @tokens.empty? and :text == peek.first do - _, name, = get :text requirements = [] @@ -77,17 +75,17 @@ class Gem::RequestSet::Lockfile::Parser when :bang then get :bang - requirements << pinned_requirement(name) when :l_paren then get :l_paren loop do - _, op, = get :requirement - _, version, = get :text requirements << "#{op} #{version}" - break unless peek[0] == :comma get :comma end @@ -96,13 +94,13 @@ class Gem::RequestSet::Lockfile::Parser if peek[0] == :bang then requirements.clear - requirements << pinned_requirement(name) get :bang end end - @set.gem name, *requirements skip :newline end @@ -113,7 +111,7 @@ class Gem::RequestSet::Lockfile::Parser while [:entry, 'remote'] == peek.first(2) do get :entry, 'remote' - _, data, = get :text skip :newline sources << Gem::Source.new(data) @@ -128,8 +126,10 @@ class Gem::RequestSet::Lockfile::Parser set = Gem::Resolver::LockSet.new sources last_specs = nil - while not @tokens.empty? and :text == peek.first do - _, name, column, = get :text case peek[0] when :newline then @@ -139,7 +139,9 @@ class Gem::RequestSet::Lockfile::Parser when :l_paren then get :l_paren - type, data, = get [:text, :requirement] if type == :text and column == 4 then version, platform = data.split '-', 2 @@ -169,16 +171,17 @@ class Gem::RequestSet::Lockfile::Parser def parse_GIT # :nodoc: get :entry, 'remote' - _, repository, = get :text skip :newline get :entry, 'revision' - _, revision, = get :text skip :newline - type, value = peek.first 2 if type == :entry and %w[branch ref tag].include? value then get get :text @@ -195,8 +198,10 @@ class Gem::RequestSet::Lockfile::Parser last_spec = nil - while not @tokens.empty? and :text == peek.first do - _, name, column, = get :text case peek[0] when :newline then @@ -204,7 +209,9 @@ class Gem::RequestSet::Lockfile::Parser when :l_paren then get :l_paren - type, data, = get [:text, :requirement] if type == :text and column == 4 then last_spec = set.add_git_spec name, data, repository, revision, true @@ -227,7 +234,7 @@ class Gem::RequestSet::Lockfile::Parser def parse_PATH # :nodoc: get :entry, 'remote' - _, directory, = get :text skip :newline @@ -239,7 +246,9 @@ class Gem::RequestSet::Lockfile::Parser last_spec = nil while not @tokens.empty? and :text == peek.first do - _, name, column, = get :text case peek[0] when :newline then @@ -247,7 +256,9 @@ class Gem::RequestSet::Lockfile::Parser when :l_paren then get :l_paren - type, data, = get [:text, :requirement] if type == :text and column == 4 then last_spec = set.add_vendor_gem name, directory @@ -270,7 +281,7 @@ class Gem::RequestSet::Lockfile::Parser def parse_PLATFORMS # :nodoc: while not @tokens.empty? and :text == peek.first do - _, name, = get :text @platforms << name @@ -285,14 +296,14 @@ class Gem::RequestSet::Lockfile::Parser def parse_dependency name, op # :nodoc: return Gem::Dependency.new name, op unless peek[0] == :text - _, version, = get :text requirements = ["#{op} #{version}"] - while peek[0] == :comma do get :comma - _, op, = get :requirement - _, version, = get :text requirements << "#{op} #{version}" end @@ -2,6 +2,9 @@ require 'strscan' require 'rubygems/request_set/lockfile/parser' class Gem::RequestSet::Lockfile::Tokenizer def self.from_file file new File.read(file), file end @@ -19,11 +22,11 @@ class Gem::RequestSet::Lockfile::Tokenizer end def to_a - @tokens end def skip type - @tokens.shift while not @tokens.empty? and peek.first == type end ## @@ -48,7 +51,7 @@ class Gem::RequestSet::Lockfile::Tokenizer alias :shift :next_token def peek - @tokens.first || [:EOF] end private @@ -71,7 +74,7 @@ class Gem::RequestSet::Lockfile::Tokenizer @tokens << case when s.scan(/\r?\n/) then - token = [:newline, nil, *token_pos(pos)] @line_pos = s.pos @line += 1 token @@ -79,25 +82,25 @@ class Gem::RequestSet::Lockfile::Tokenizer if leading_whitespace then text = s.matched text += s.scan(/[^\s)]*/).to_s # in case of no match - [:text, text, *token_pos(pos)] else - [:section, s.matched, *token_pos(pos)] end when s.scan(/([a-z]+):\s/) then s.pos -= 1 # rewind for possible newline - [:entry, s[1], *token_pos(pos)] when s.scan(/\(/) then - [:l_paren, nil, *token_pos(pos)] when s.scan(/\)/) then - [:r_paren, nil, *token_pos(pos)] when s.scan(/<=|>=|=|~>|<|>|!=/) then - [:requirement, s.matched, *token_pos(pos)] when s.scan(/,/) then - [:comma, nil, *token_pos(pos)] when s.scan(/!/) then - [:bang, nil, *token_pos(pos)] when s.scan(/[^\s),!]*/) then - [:text, s.matched, *token_pos(pos)] else raise "BUG: can't create token for: #{s.string[s.pos..-1].inspect}" end |