Skip to content

Commit

Permalink
Parse gems that are followed by inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
remomueller authored and laserlemon committed Jan 26, 2012
1 parent d053c42 commit b2b3c5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/gemnasium/parser/patterns.rb
Expand Up @@ -19,8 +19,9 @@ module Patterns
VALUE = /(?:#{BOOLEAN}|#{NIL}|#{ELEMENT}|#{ARRAY}|)/ VALUE = /(?:#{BOOLEAN}|#{NIL}|#{ELEMENT}|#{ARRAY}|)/
PAIR = /(?:(#{KEY})\s*=>\s*(#{VALUE})|(\w+):\s+(#{VALUE}))/ PAIR = /(?:(#{KEY})\s*=>\s*(#{VALUE})|(\w+):\s+(#{VALUE}))/
OPTIONS = /#{PAIR}(?:\s*,\s*#{PAIR})*/ OPTIONS = /#{PAIR}(?:\s*,\s*#{PAIR})*/
COMMENT = /(#.*)?/


GEM_CALL = /^\s*gem\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENT_LIST})?(?:\s*,\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/ GEM_CALL = /^\s*gem\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENT_LIST})?(?:\s*,\s*(?<opts>#{OPTIONS}))?\s*\)?\s*#{COMMENT}$/


SYMBOLS = /#{SYMBOL}(\s*,\s*#{SYMBOL})*/ SYMBOLS = /#{SYMBOL}(\s*,\s*#{SYMBOL})*/
GROUP_CALL = /^(?<i1>\s*)group\(?\s*(?<grps>#{SYMBOLS})\s*\)?\s+do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m GROUP_CALL = /^(?<i1>\s*)group\(?\s*(?<grps>#{SYMBOLS})\s*\)?\s+do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
Expand All @@ -31,7 +32,7 @@ module Patterns


GEMSPEC_CALL = /^\s*gemspec(?:\(?\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/ GEMSPEC_CALL = /^\s*gemspec(?:\(?\s*(?<opts>#{OPTIONS}))?\s*\)?\s*$/


ADD_DEPENDENCY_CALL = /^\s*\w+\.add(?<type>_runtime|_development)?_dependency\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENTS})?\s*\)?\s*$/ ADD_DEPENDENCY_CALL = /^\s*\w+\.add(?<type>_runtime|_development)?_dependency\(?\s*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:\s*,\s*#{REQUIREMENTS})?\s*\)?\s*#{COMMENT}$/


def self.options(string) def self.options(string)
{}.tap do |hash| {}.tap do |hash|
Expand Down
6 changes: 6 additions & 0 deletions spec/gemnasium/parser/gemfile_spec.rb
Expand Up @@ -241,4 +241,10 @@ def reset
dependency.name.should == "rake" dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7" dependency.requirement.should == ">= 0.8.7"
end end

it "parses gems followed by inline comments" do
content(%(gem "rake", ">= 0.8.7" # Comment))
dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7"
end
end end
10 changes: 10 additions & 0 deletions spec/gemnasium/parser/gemspec_spec.rb
Expand Up @@ -135,4 +135,14 @@ def reset
dependency.name.should == "rake" dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7" dependency.requirement.should == ">= 0.8.7"
end end

it "parses gems followed by inline comments" do
content(<<-EOF)
Gem::Specification.new do |gem|
gem.add_dependency "rake", ">= 0.8.7" # Comment
end
EOF
dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7"
end
end end

0 comments on commit b2b3c5a

Please sign in to comment.