diff --git a/extra/pcre/info/info-tests.factor b/extra/pcre/info/info-tests.factor deleted file mode 100644 index be689fd988..0000000000 --- a/extra/pcre/info/info-tests.factor +++ /dev/null @@ -1,9 +0,0 @@ -USING: accessors pcre pcre.info pcre.utils sequences tools.test ; - -[ { { 3 "day" } { 2 "month" } { 1 "year" } } ] -[ - "(?P\\d{4})-(?P\\d{2})-(?P\\d{2})" - nametable>> -] unit-test - -[ { 100 110 120 130 } ] [ 100 10 4 gen-array-addrs ] unit-test diff --git a/extra/pcre/info/info.factor b/extra/pcre/info/info.factor deleted file mode 100644 index faad07969c..0000000000 --- a/extra/pcre/info/info.factor +++ /dev/null @@ -1,36 +0,0 @@ -USING: - accessors - alien alien.accessors alien.c-types alien.data alien.strings - arrays - io.encodings.utf8 - kernel - math math.bitwise - pcre.ffi pcre.utils - sequences ; -IN: pcre.info - -! Mostly internal -: fullinfo ( pcre extra what -- obj ) - { int } [ pcre_fullinfo ] with-out-parameters nip ; - -: name-count ( pcre extra -- n ) - PCRE_INFO_NAMECOUNT fullinfo ; - -: name-table ( pcre extra -- addr ) - [ drop alien-address 32 on-bits unmask ] - [ PCRE_INFO_NAMETABLE fullinfo ] 2bi + ; - -: name-entry-size ( pcre extra -- size ) - PCRE_INFO_NAMEENTRYSIZE fullinfo ; - -: name-table-entry ( addr -- group-index group-name ) - [ 1 alien-unsigned-1 ] - [ 2 + utf8 alien>string ] bi ; - -: options ( pcre -- opts ) - f PCRE_INFO_OPTIONS fullinfo ; - -! Exported -: name-table-entries ( pcre extra -- addrs ) - [ name-table ] [ name-entry-size ] [ name-count ] 2tri - gen-array-addrs [ name-table-entry 2array ] map ; diff --git a/extra/pcre/pcre-tests.factor b/extra/pcre/pcre-tests.factor index 2a78fa4a0b..3d51014c26 100644 --- a/extra/pcre/pcre-tests.factor +++ b/extra/pcre/pcre-tests.factor @@ -1,18 +1,19 @@ -USING: - accessors - arrays - assocs - http.client - kernel - math math.ranges - pcre pcre.ffi pcre.info - random - sequences - system - tools.test ; +USING: accessors arrays assocs http.client kernel math.ranges +pcre pcre.ffi pcre.private random sequences system tools.test ; QUALIFIED: regexp IN: pcre.tests +[ { "Bords" "words" "word" } ] [ + "Bords, words, word." { ", " ", " "." } split-subseqs +] unit-test + +[ { { 3 "day" } { 2 "month" } { 1 "year" } } ] [ + "(?P\\d{4})-(?P\\d{2})-(?P\\d{2})" + nametable>> +] unit-test + +[ { 100 110 120 130 } ] [ 100 10 4 gen-array-addrs ] unit-test + CONSTANT: iso-date "(?P\\d{4})-(?P\\d{2})-(?P\\d{2})" ! On windows the erroffset appears to be set to 0 despite there being diff --git a/extra/pcre/pcre.factor b/extra/pcre/pcre.factor index 008a04a90a..e66e1ad769 100644 --- a/extra/pcre/pcre.factor +++ b/extra/pcre/pcre.factor @@ -1,18 +1,51 @@ -USING: - accessors - alien.c-types alien.data alien.enums alien.strings - arrays - assocs - io.encodings.utf8 io.encodings.string - kernel - math - mirrors - pcre.ffi pcre.info pcre.utils - sequences sequences.generalizations - strings ; +USING: accessors alien alien.accessors alien.c-types alien.data +alien.enums alien.strings arrays assocs fry io.encodings.string +io.encodings.utf8 kernel math math.bitwise mirrors pcre.ffi +sequences sequences.generalizations splitting strings ; QUALIFIED: regexp IN: pcre + 1 alien-unsigned-1 ] + [ 2 + utf8 alien>string ] bi ; + +: options ( pcre -- opts ) + f PCRE_INFO_OPTIONS fullinfo ; + +: name-table-entries ( pcre extra -- addrs ) + [ name-table ] [ name-entry-size ] [ name-count ] 2tri + gen-array-addrs [ name-table-entry 2array ] map ; + +PRIVATE> + ERROR: malformed-regexp expr error ; ERROR: pcre-error value ; @@ -86,7 +119,7 @@ GENERIC: findall ( subject obj -- matches ) M: compiled-pcre findall [ [ findnext ] follow [ match>> ] map harvest ] - [ nametable>> rot [ parse-match ] 2with map ] 2bi >array ; + [ nametable>> rot [ parse-match ] 2with { } map-as ] 2bi ; M: string findall findall ; @@ -97,5 +130,15 @@ M: regexp:regexp findall : matches? ( subject obj -- ? ) dupd findall [ nip length 1 = ] [ ?first ?first ?last = ] 2bi and ; +string ] map harvest ; + +PRIVATE> + : split ( subject obj -- strings ) dupd findall [ first second ] map split-subseqs ; diff --git a/extra/pcre/utils/utils-tests.factor b/extra/pcre/utils/utils-tests.factor deleted file mode 100644 index f53b823cea..0000000000 --- a/extra/pcre/utils/utils-tests.factor +++ /dev/null @@ -1,6 +0,0 @@ -USING: pcre.utils tools.test ; -IN: pcre.utils.tests - -[ { "Bords" "words" "word" } ] [ - "Bords, words, word." { ", " ", " "." } split-subseqs -] unit-test diff --git a/extra/pcre/utils/utils.factor b/extra/pcre/utils/utils.factor deleted file mode 100644 index f5fea26eae..0000000000 --- a/extra/pcre/utils/utils.factor +++ /dev/null @@ -1,21 +0,0 @@ -USING: assocs fry kernel math mirrors sequences splitting strings ; -IN: pcre.utils - -: replace-all ( seq subseqs new -- seq ) - swapd '[ _ replace ] reduce ; - -: split-subseqs ( seq subseqs -- seqs ) - dup first [ replace-all ] keep split-subseq [ >string ] map harvest ; - -: 2with ( param1 param2 obj quot -- obj curry ) - [ -rot ] dip [ [ rot ] dip call ] 3curry ; inline - -: gen-array-addrs ( base size n -- addrs ) - iota [ * + ] 2with map ; - -: utf8-start-byte? ( byte -- ? ) - 0xc0 bitand 0x80 = not ; - -: next-utf8-char ( byte-array pos -- pos' ) - 1 + 2dup swap ?nth - [ utf8-start-byte? [ nip ] [ next-utf8-char ] if ] [ 2drop f ] if* ;