Permalink
Browse files

Parse gems that are followed by inline comments

  • Loading branch information...
remomueller authored and laserlemon committed Jan 20, 2012
1 parent d053c42 commit b2b3c5a33250304f449e1127e7f0df1443709e46
@@ -19,8 +19,9 @@ module Patterns
VALUE = /(?:#{BOOLEAN}|#{NIL}|#{ELEMENT}|#{ARRAY}|)/
PAIR = /(?:(#{KEY})\s*=>\s*(#{VALUE})|(\w+):\s+(#{VALUE}))/
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})*/
GROUP_CALL = /^(?<i1>\s*)group\(?\s*(?<grps>#{SYMBOLS})\s*\)?\s+do\s*?\n(?<blk>.*?)\n^\k<i1>end\s*$/m
@@ -31,7 +32,7 @@ module Patterns
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)
{}.tap do |hash|
@@ -241,4 +241,10 @@ def reset
dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7"
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
@@ -135,4 +135,14 @@ def reset
dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7"
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

0 comments on commit b2b3c5a

Please sign in to comment.