[gforth] / gforth / regexp.fs  

gforth: gforth/regexp.fs

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

version 1.15, Thu May 27 09:16:11 2010 UTC version 1.17, Sun Sep 5 19:09:55 2010 UTC
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 150 
Line 145 
     \G check for string end      \G check for string end
     ]] end-rex? ?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
   
 \ FORK/JOIN are like AHEAD THEN, but producing a call on AHEAD  \ FORK/JOIN are like AHEAD THEN, but producing a call on AHEAD
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 - ;
 : >>rest ( -- ) >>next >>string $+! ;  : >>rest ( -- ) >>next >>string $+! ;
 : s// ( addr u -- ptr )  : s// ( addr u -- ptr )
     \G start search/replace loop      \G start search/replace loop
     ]] (( // >> [[ ; immediate      ]] >>string0 (( // s>> [[ ; immediate
   : >> ( addr -- addr )
       ]] <<ptr >>ptr u> ?LEAVE ?end [[ ; immediate
   : //s ( ptr -- )
       \G search end
       ]] )) drop >>rest >>string@ [[ ; immediate
 : //o ( ptr addr u -- addr' u' )  : //o ( ptr addr u -- addr' u' )
     \G end search/replace single loop      \G end search/replace single loop
     ]] << )) drop >>rest >>string@ [[ ; immediate      ]] << //s [[ ; immediate
 : //g ( ptr addr u -- addr' u' )  : //g ( ptr addr u -- addr' u' )
     \G end search/replace all loop      \G end search/replace all loop
     ]] << LEAVE )) drop >>string@ [[ ; immediate      ]] << LEAVE //s [[ ; immediate


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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help