1. Kaspar Schiess
  2. par

Commits

Kaspar Schiess  committed 07cbd37

Optional parse steps

  • Participants
  • Parent commits 4cf23ba
  • Branches master

Comments (0)

Files changed (4)

File examples/integers.rb

View file
 include Par
 
 def integer source
-  source.pattern(/\+|-/) >>
+  source.pattern(/\+|-/).maybe >>
     source.pattern(/\d+/)
 end
 

File lib/par.rb

View file
     def | other
       self
     end
+    def maybe
+      self
+    end
 
     def new obj
       self.class.new obj

File spec/lib/par/result_spec.rb

View file
     it "should allow alternation" do
       (a | b).should == a
     end
+    it "allow calling maybe" do
+      a.maybe.should == a
+    end
   end
   context '.bot' do
     let(:any) { result 'any' }

File spec/lib/par_spec.rb

View file
     it "allows optional parsing" do
       (s.string('baz').maybe >> s.string('foobar')).should == 'foobar'
     end
+    it "allows maybe on results" do
+      s.string('foo').maybe.should == 'foo'
+    end
   end
 end