]> gitweb.factorcode.org Git - factor.git/commitdiff
globs: making glob-matches? support wildcards.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 6 Apr 2016 21:02:48 +0000 (14:02 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 6 Apr 2016 21:02:48 +0000 (14:02 -0700)
basis/globs/globs-tests.factor
basis/globs/globs.factor

index 4af63c3d59a46fe28434bb18a5a8c98480454596..1e5728f9c6fbb6df3230bd4f04c42de798ed366b 100755 (executable)
@@ -22,6 +22,8 @@ tools.test ;
 
 { f } [ "foo" "bar" append-path "*" glob-matches? ] unit-test
 { t } [ "foo" "bar" append-path "*" "*" append-path glob-matches? ] unit-test
+{ t } [ "foo" "bar" append-path "**/bar" glob-matches? ] unit-test
+{ t } [ "foo" "bar" append-path "**/b*" glob-matches? ] unit-test
 { f } [ "foo" "bar" append-path "foo?bar" glob-matches? ] unit-test
 { t } [ "foo" "bar" append-path "fo?" "bar" append-path glob-matches? ] unit-test
 
index e72cd007d6dd344bc706282da421e01f1dcd6301..0e83e917b613c1337a229b35d20a29bc00c4bda3 100644 (file)
@@ -9,6 +9,9 @@ IN: globs
 : not-path-separator ( -- sep )
     os windows? R/ [^\\/\\]/ R/ [^\\/]/ ? ; foldable
 
+: wild-path-separator ( -- sep )
+    os windows? R/ [^\\/\\][\\/\\]|[^\\/\\]/ R/ [^\\/][\\/]|[^\\/]/ ? ; foldable
+
 EBNF: <glob>
 
 Character = "\\" .:c => [[ c 1string <literal> ]]
@@ -29,7 +32,8 @@ CharClass = "^"?:n Ranges:e => [[ e <or> n [ <not> ] when ]]
 AlternationBody = Concatenation:c "," AlternationBody:a => [[ a c prefix ]]
                 | Concatenation => [[ 1array ]]
 
-Element = "*" => [[ not-path-separator <zero-or-more> ]]
+Element = "**" => [[ wild-path-separator <zero-or-more> ]]
+        | "*" => [[ not-path-separator <zero-or-more> ]]
         | "?" => [[ not-path-separator ]]
         | "[" CharClass:c "]" => [[ c ]]
         | "{" AlternationBody:b "}" => [[ b <or> ]]