Pasberth Usbean avatar Pasberth Usbean committed a17c27e

bug fix

Comments (0)

Files changed (6)

lib/regparsec/parser/combinators.rb

-module RegParsec::Regparseable
+module RegParsec::Regparsers
 
   def try *regparsers, &result_proc
     ::RegParsec::Regparsers::TryParser.new.curry!(*regparsers, &result_proc)

lib/regparsec/parser/primary_parsers.rb

   def __regparse__ state, regexp
     case state.input                                       # case "abc;def;"
     when /\A#{regexp}\z/                                   # when /\A(.*?);\z/
-      md = $~; md.string =~ /\A#{regexp}/                  #   "abc;def;" =~ /\A(.*?);/
-      if $~[0] != md.string                                #   if "abc;" != "abc;def;"
+      md = $~; md[0] =~ /\A#{regexp}/                  #   "abc;def;" =~ /\A(.*?);/
+      if $~[0] != md[0]                                    #   if "abc;" != "abc;def;"
         md = $~
-        state.input.sub!(md.string, '')
+        state.input.sub!(md[0], '')
         Result::Success.new( :return_value => md,
-                             :matching_string => md.string )
+                             :matching_string => md[0] )
       else
         Result::Accepted.new( :return_value => md,
-                              :matching_string => md.string )
+                              :matching_string => md[0] )
       end
     when /\A#{regexp}/
       md = $~
-      state.input.sub!(md.string, '')
+      state.input.sub!(md[0], '')
       Result::Success.new( :return_value => md,
-                           :matching_string => md.string )
+                           :matching_string => md[0] )
     else
       Result::Invalid.new( :return_value => nil )
     end

lib/regparsec/parser/state.rb

 require 'regparsec/regparsers'
 
-module RegParsec::Regparseable
+module RegParsec::Regparsers
 
   def update_state *regparsers, &result_proc
     ::RegParsec::Regparsers::UpdateStateParser.new.curry!(*regparsers, &result_proc)

lib/regparsec/regparseable.rb

 require 'regparsec'
 
 module RegParsec::Regparseable
-
+  
   [ :regparse, :parse ].each do |method|
     class_eval(<<-DEFINE)
       def __#{method}__(*args, &block)

lib/regparsec/regparsers.rb

 require 'regparsec'
+require 'regparsec/regparseable'
 
 module RegParsec
 
   module Regparsers
-
     extend self
-
-    require 'regparsec/parser/base'
-    require 'regparsec/parser/state'
-    require 'regparsec/parser/primary_parsers'
-    require 'regparsec/parser/combinators'
+  end
+  
+  module Regparseable
+    include Regparsers
   end
 end
+
+require 'regparsec/parser/base'
+require 'regparsec/parser/state'
+require 'regparsec/parser/primary_parsers'
+require 'regparsec/parser/combinators'

spec/regparsers/regexp_parser_spec.rb

     example { subject.regparse("abc;def;").should be_is_a ::RegParsec::Result::Success }
   end
   
+  context ' /./ case ' do
+    subject { described_class.new.curry!(/./) }
+
+    example { subject.parse("a").should be_nil }
+    example { subject.regparse("a").should be_is_a ::RegParsec::Result::Accepted }
+    example { subject.parse("ab")[0].should == "a" }
+    example { subject.regparse("ab").should be_is_a ::RegParsec::Result::Success }
+    example { subject.parse("").should be_nil }
+    example { subject.regparse("").should be_is_a ::RegParsec::Result::Invalid }
+  end
+  
+  context ' /.*/ case ' do
+    subject { described_class.new.curry!(/.*/) }
+
+    example { subject.parse("abc").should be_nil }
+    example { subject.regparse("abc").should be_is_a ::RegParsec::Result::Accepted }
+    example { subject.parse("abc\n")[0].should == "abc" }
+    example { subject.regparse("abc\n").should be_is_a ::RegParsec::Result::Success }
+    example { subject.parse("abc\ndef")[0].should == "abc" }
+    example { subject.regparse("abc\ndef").should be_is_a ::RegParsec::Result::Success }
+    example { subject.parse("abc\ndef\n")[0].should == "abc" }
+    example { subject.regparse("abc\ndef\n").should be_is_a ::RegParsec::Result::Success }
+  end
+  
   context ' /#(.*)\n/ case ' do
     subject { described_class.new.curry!(/\#(.*?)\n/) }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.