[gforth] / gforth / regexp.fs  

gforth: gforth/regexp.fs

Diff for /gforth/regexp.fs between version 1.10 and 1.17

version 1.10, Mon Dec 31 18:40:24 2007 UTC version 1.17, Sun Sep 5 19:09:55 2010 UTC
Line 1 
Line 1 
 \ Regexp compile  \ Regexp compile
   
 \ Copyright (C) 2005,2006,2007 Free Software Foundation, Inc.  \ Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc.
   
 \ This file is part of Gforth.  \ This file is part of Gforth.
   
Line 101 
Line 101 
 : ` ( "char" -- ) \ regexp-pattern  : ` ( "char" -- ) \ regexp-pattern
     \G check for particular char      \G check for particular char
     ]] count [[  char ]] Literal <> ?LEAVE [[ ;  immediate      ]] count [[  char ]] Literal <> ?LEAVE [[ ;  immediate
   : -` ( "char" -- ) \ regexp-pattern
 \ A word for string comparison      \G check for particular char
       ]] count [[  char ]] Literal = ?LEAVE [[ ;  immediate
 : $= ( addr1 addr2 u -- f )  tuck compare ;  
 : ,=" ( addr u -- ) tuck ]] dup SLiteral $= ?LEAVE Literal + noop [[ ;  
 : =" ( <string>" -- ) \ regexp-pattern  
     \G check for string  
     '" parse ,=" ; immediate  
   
 \ loop stack  \ loop stack
   
Line 137 
Line 132 
 0 Value end$  0 Value end$
 0 Value start$  0 Value start$
 : !end ( addr u -- addr )  over + to end$ dup to start$ ;  : !end ( addr u -- addr )  over + to end$ dup to start$ ;
 : $? ( addr -- addr flag ) dup end$ u< ;  : end-rex? ( addr -- addr flag ) dup end$ u< ;
 : ^? ( addr -- addr flag ) dup start$ u> ;  : start-rex? ( addr -- addr flag ) dup start$ u> ;
 : ?end ( addr -- addr ) ]] dup end$ u> ?LEAVE [[ ; immediate  : ?end ( addr -- addr ) ]] dup end$ u> ?LEAVE [[ ; immediate
   
 \ start and end  \ start and end
   
 : \^ ( addr -- addr ) \ regexp-pattern  : \^ ( addr -- addr ) \ regexp-pattern
     \G check for string start      \G check for string start
     ]] ^? ?LEAVE [[ ; immediate      ]] start-rex? ?LEAVE [[ ; immediate
 : \$ ( addr -- addr ) \ regexp-pattern  : \$ ( addr -- addr ) \ regexp-pattern
     \G check for string end      \G check for string end
     ]] $? ?LEAVE [[ ; immediate      ]] end-rex? ?LEAVE [[ ; immediate
   
   \ A word for string comparison
   
   : ,=" ( addr u -- ) tuck ]] dup SLiteral tuck compare ?LEAVE Literal + noop [[ ;
   : =" ( <string>" -- ) \ regexp-pattern
       \G check for string
       '" parse ,=" ; immediate
   
 \ regexp block  \ regexp block
   
Line 179 
Line 181 
     immediate      immediate
 : n*} ( sys n -- ) \ regexp-pattern  : n*} ( sys n -- ) \ regexp-pattern
     \G At least @var{n} pattern      \G At least @var{n} pattern
     >r ]] r> 1+ >r $? 0= UNTIL dup [[ DONE, ]] drop [[      >r ]] r> 1+ >r end-rex? 0= UNTIL dup [[ DONE, ]] drop [[
     r@ IF r@ ]] r@ Literal u< IF  r> 1+ drops false  EXIT  THEN [[ THEN      r@ IF r@ ]] r@ Literal u< IF  r> 1+ drops false  EXIT  THEN [[ THEN
     r@ ]] r> 1+ Literal U+DO FORK BUT [[      r@ ]] r> 1+ Literal U+DO FORK BUT [[
     ]] IF  I' I - [[ r@ 1- ]] Literal + drops true UNLOOP EXIT  THEN  LOOP [[      ]] IF  I' I - [[ r@ 1- ]] Literal + drops true UNLOOP EXIT  THEN  LOOP [[
Line 263 
Line 265 
 0 Value >>ptr  0 Value >>ptr
 0 Value <<ptr  0 Value <<ptr
 Variable >>string  Variable >>string
 : >>  ( addr -- addr ) \ regexp-replace  : s>>  ( addr -- addr ) \ regexp-replace
     \G Start replace pattern region      \G Start replace pattern region
     dup to >>ptr ;      dup to >>ptr ;
 : << ( run-addr addr u -- run-addr ) \ regexp-replace  : << ( run-addr addr u -- run-addr ) \ regexp-replace
     \G Replace string from start of replace pattern region with      \G Replace string from start of replace pattern region with
     \G @var{addr} @var{u}      \G @var{addr} @var{u}
     <<ptr 0= IF  start$ to <<ptr  THEN  
     >>string @ 0= IF  s" " >>string $!  THEN  
     <<ptr >>ptr over - >>string $+!      <<ptr >>ptr over - >>string $+!
     >>string $+! dup to <<ptr ;      >>string $+! dup to <<ptr ;
 : <<" ( "string<">" -- ) \ regexp-replace  : <<" ( "string<">" -- ) \ regexp-replace
Line 278 
Line 278 
     \G @var{string}      \G @var{string}
     '" parse postpone SLiteral postpone << ; immediate      '" parse postpone SLiteral postpone << ; immediate
 : >>string@ ( -- addr u )  : >>string@ ( -- addr u )
     >>string $@ >>string off      >>string $@ ;
     0 to >>ptr  0 to <<ptr ;  : >>string0 ( addr u -- addr u )  s" " >>string $!
       0 to >>ptr  over to <<ptr ;
 : >>next ( -- addr u ) <<ptr end$ over - ;  : >>next ( -- addr u ) <<ptr end$ over - ;
 : s// ( -- sys ) \ regexp-replace  : >>rest ( -- ) >>next >>string $+! ;
   : s// ( addr u -- ptr )
     \G start search/replace loop      \G start search/replace loop
     ]] BEGIN [[ ; immediate      ]] >>string0 (( // s>> [[ ; immediate
 : //g ( sys -- ) \ regexp-replace  : >> ( addr -- addr )
     \G end search/replace loop      ]] <<ptr >>ptr u> ?LEAVE ?end [[ ; immediate
     ]] WHILE >>next REPEAT end$ [[  : //s ( ptr -- )
     s" " ]] SLiteral << >>string@ rot drop [[ ; immediate      \G search end
       ]] )) drop >>rest >>string@ [[ ; immediate
   : //o ( ptr addr u -- addr' u' )
       \G end search/replace single loop
       ]] << //s [[ ; immediate
   : //g ( ptr addr u -- addr' u' )
       \G end search/replace all loop
       ]] << LEAVE //s [[ ; immediate


Generate output suitable for use with a patch program
Legend:
Removed from v.1.10  
changed lines
  Added in v.1.17

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help