pcre: split the module into a ffi part and a main part for easier maintanability
parent
ad1e1d8455
commit
152ccf4b27
|
@ -0,0 +1,66 @@
|
||||||
|
USING:
|
||||||
|
alien alien.c-types alien.data alien.libraries alien.syntax
|
||||||
|
classes.struct
|
||||||
|
combinators
|
||||||
|
system ;
|
||||||
|
IN: pcre.ffi
|
||||||
|
|
||||||
|
<< {
|
||||||
|
{ [ os unix? ] [ "libpcre" "libpcre.so" cdecl add-library ] }
|
||||||
|
} cond >>
|
||||||
|
|
||||||
|
CONSTANT: PCRE_INFO_OPTIONS 0
|
||||||
|
CONSTANT: PCRE_INFO_SIZE 1
|
||||||
|
CONSTANT: PCRE_INFO_CAPTURECOUNT 2
|
||||||
|
CONSTANT: PCRE_INFO_BACKREFMAX 3
|
||||||
|
CONSTANT: PCRE_INFO_FIRSTBYTE 4
|
||||||
|
CONSTANT: PCRE_INFO_FIRSTCHAR 4
|
||||||
|
CONSTANT: PCRE_INFO_FIRSTTABLE 5
|
||||||
|
CONSTANT: PCRE_INFO_LASTLITERAL 6
|
||||||
|
CONSTANT: PCRE_INFO_NAMEENTRYSIZE 7
|
||||||
|
CONSTANT: PCRE_INFO_NAMECOUNT 8
|
||||||
|
CONSTANT: PCRE_INFO_NAMETABLE 9
|
||||||
|
CONSTANT: PCRE_INFO_STUDYSIZE 10
|
||||||
|
CONSTANT: PCRE_INFO_DEFAULT_TABLES 11
|
||||||
|
CONSTANT: PCRE_INFO_OKPARTIAL 12
|
||||||
|
CONSTANT: PCRE_INFO_JCHANGED 13
|
||||||
|
CONSTANT: PCRE_INFO_HASCRORLF 14
|
||||||
|
CONSTANT: PCRE_INFO_MINLENGTH 15
|
||||||
|
|
||||||
|
STRUCT: pcre_extra
|
||||||
|
{ flags int }
|
||||||
|
{ study_data void* }
|
||||||
|
{ match_limit long }
|
||||||
|
{ callout_data void* }
|
||||||
|
{ tables uchar* }
|
||||||
|
{ match_limit_recursion int }
|
||||||
|
{ mark uchar** } ;
|
||||||
|
|
||||||
|
FUNCTION: void* pcre_compile ( c-string pattern,
|
||||||
|
int options,
|
||||||
|
char** errptr,
|
||||||
|
int* erroffset,
|
||||||
|
char* tableptr ) ;
|
||||||
|
|
||||||
|
FUNCTION: int pcre_info ( void* pcre, int* optptr, int* first_byte ) ;
|
||||||
|
FUNCTION: int pcre_fullinfo ( void* pcre, pcre_extra* extra, int what, void *where ) ;
|
||||||
|
|
||||||
|
FUNCTION: pcre_extra* pcre_study ( void* pcre, int options, char** errptr ) ;
|
||||||
|
FUNCTION: int pcre_exec ( void* pcre,
|
||||||
|
pcre_extra* extra,
|
||||||
|
c-string subject,
|
||||||
|
int length,
|
||||||
|
int startoffset,
|
||||||
|
int options,
|
||||||
|
int* ovector,
|
||||||
|
int ovecsize ) ;
|
||||||
|
|
||||||
|
FUNCTION: int pcre_get_substring ( c-string subject,
|
||||||
|
int* ovector,
|
||||||
|
int stringcount,
|
||||||
|
int stringnumber,
|
||||||
|
void *stringptr ) ;
|
||||||
|
|
||||||
|
FUNCTION: c-string pcre_version ( ) ;
|
||||||
|
|
||||||
|
FUNCTION: uchar* pcre_maketables ( ) ;
|
|
@ -1,42 +1,45 @@
|
||||||
USING:
|
USING:
|
||||||
alien alien.c-types alien.data alien.libraries alien.syntax
|
accessors
|
||||||
classes.struct
|
alien.c-types alien.data
|
||||||
combinators
|
arrays
|
||||||
system ;
|
kernel
|
||||||
|
pcre.ffi
|
||||||
|
sequences ;
|
||||||
IN: pcre
|
IN: pcre
|
||||||
|
|
||||||
<< {
|
ERROR: malformed-regexp expr error ;
|
||||||
{ [ os unix? ] [ "libpcre" "libpcre.so" cdecl add-library ] }
|
|
||||||
} cond >>
|
|
||||||
|
|
||||||
STRUCT: pcre_extra
|
TUPLE: compiled-pcre pcre extra ;
|
||||||
{ flags int }
|
|
||||||
{ study_data void* }
|
|
||||||
{ match_limit long }
|
|
||||||
{ callout_data void* }
|
|
||||||
{ tables uchar* }
|
|
||||||
{ match_limit_recursion int }
|
|
||||||
{ mark uchar** } ;
|
|
||||||
|
|
||||||
FUNCTION: void* pcre_compile ( c-string pattern,
|
! Low-level
|
||||||
int options,
|
|
||||||
char** errptr,
|
|
||||||
int* erroffset,
|
|
||||||
char* tableptr ) ;
|
|
||||||
|
|
||||||
FUNCTION: int pcre_info ( void* pcre, int* optptr, int* first_byte ) ;
|
: exec ( pcre extra subject ofs -- count match-data )
|
||||||
|
[ dup length ] dip 0 30 int <c-array> [ 30 pcre_exec ] keep ;
|
||||||
|
|
||||||
FUNCTION: pcre_extra* pcre_study ( void* pcre, int options, char** errptr ) ;
|
: (pcre) ( expr -- pcre err-message err-offset )
|
||||||
|
|
||||||
FUNCTION: c-string pcre_version ( ) ;
|
|
||||||
|
|
||||||
FUNCTION: uchar* pcre_maketables ( ) ;
|
|
||||||
|
|
||||||
: <pcre> ( expr -- pcre err-message err-offset )
|
|
||||||
0 { c-string int } [ f pcre_compile ] with-out-parameters ;
|
0 { c-string int } [ f pcre_compile ] with-out-parameters ;
|
||||||
|
|
||||||
|
: <pcre> ( expr -- pcre )
|
||||||
|
dup (pcre) 2array swap [ 2nip ] [ malformed-regexp ] if* ;
|
||||||
|
|
||||||
|
: <pcre-extra> ( pcre -- pcre-extra )
|
||||||
|
0 { c-string } [ pcre_study ] with-out-parameters drop ;
|
||||||
|
|
||||||
|
! High-level
|
||||||
|
|
||||||
|
: <compiled-pcre> ( expr -- compiled-pcre )
|
||||||
|
<pcre> dup <pcre-extra> compiled-pcre boa ;
|
||||||
|
|
||||||
|
: findall ( subject compiled-pcre -- matches )
|
||||||
|
[ pcre>> ] [ extra>> ] bi rot 0 exec nip ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
: info ( pcre -- x x x )
|
: info ( pcre -- x x x )
|
||||||
{ int int } [ pcre_info ] with-out-parameters ;
|
{ int int } [ pcre_info ] with-out-parameters ;
|
||||||
|
|
||||||
: study ( pcre -- pcre-extra err-message )
|
: fullinfo ( pcre pcre-extra what -- num x )
|
||||||
0 { c-string } [ pcre_study ] with-out-parameters ;
|
{ int } [ pcre_fullinfo ] with-out-parameters ;
|
||||||
|
|
||||||
|
: substring ( subject match-data count n -- str )
|
||||||
|
{ c-string } [ pcre_get_substring drop ] with-out-parameters ;
|
||||||
|
|
Loading…
Reference in New Issue