Permalink
Browse files

Create If Any pattern from negative Integer.

  • Loading branch information...
1 parent c948322 commit 888bd8838fb3075dd8aea6bfbb82555ea9be0c24 @brixen committed Nov 6, 2010
Showing with 9 additions and 1 deletion.
  1. +3 −1 lib/pegarus/ast/pattern.rb
  2. +6 −0 spec/ast/pattern_spec.rb
@@ -6,7 +6,9 @@ def pattern(spec)
when Array
Set.new spec
when Integer
- Any.new spec
+ node = Any.new spec.abs
+ node = If.new node if spec < 0
+ node
when String
Character.new spec
when Pattern
View
@@ -5,6 +5,12 @@
Pegarus.pattern(5).should be_an_instance_of(Pegarus::Any)
end
+ it "returns an If Any pattern when passed a negative Integer" do
+ pat = Pegarus.pattern(-1)
+ pat.should be_an_instance_of(Pegarus::If)
+ pat.pattern.should be_an_instance_of(Pegarus::Any)
+ end
+
it "returns an Character pattern when passed a String" do
Pegarus.pattern("abc").should be_an_instance_of(Pegarus::Character)
end

0 comments on commit 888bd88

Please sign in to comment.