Not logged in

Artifact 9d51704f0da49c5916990e107e69f9a1b565519b

File grep.rx part of check-in [f0269c2f92] - add "grep" example by crc on 2011-03-21 16:22:18. [annotate]


( "filename"  "substring" grep )
( display all lines containing "substring" in "filename" )

{{
  3 elements base token content

  : clean ( $- )
    withLength
    [ dup @ 10 13 within [ 999 swap &! sip ] ifTrue 1+ ] times drop ;

  : tokenize ( $-$$ )
    32 ^strings'splitAtChar ^strings'chop ;

  : getLine ( $-$$ )
    999 ^strings'splitAtChar ^strings'chop ;

  : process ( $- )
    dup @token ^strings'search [ puts cr ] &drop if ;

  : loadSourceData ( $- )
    here swap ^files'slurp here !content heap +! 32 , 0 ,
    @content clean ;
---reveal---
  : grep ( $$- )
    cr here !base
    keepString !token
    loadSourceData @content [ getLine process dup 1 <> ] while drop
    @base !heap ;
}}