add take-while to state parser

db4
Doug Coleman 2009-04-01 02:45:20 -05:00
parent 99c3cd9517
commit f994654af3
1 changed files with 8 additions and 6 deletions

View File

@ -18,6 +18,9 @@ TUPLE: state-parser sequence n ;
: current ( state -- char/f )
[ n>> ] keep state-parser-nth ; inline
: previous ( state -- char/f )
[ n>> 1 - ] keep state-parser-nth ; inline
: peek-next ( state -- char/f )
[ n>> 1 + ] keep state-parser-nth ; inline
@ -27,9 +30,6 @@ TUPLE: state-parser sequence n ;
: get+increment ( state -- char/f )
[ current ] [ next drop ] bi ; inline
: state-parse ( sequence quot -- )
[ <state-parser> ] dip call ; inline
:: skip-until ( state quot: ( obj -- ? ) -- )
state current [
quot call [ state next quot skip-until ] unless
@ -46,6 +46,9 @@ TUPLE: state-parser sequence n ;
[ drop [ n>> ] [ sequence>> ] bi ] 2tri subseq
] if ; inline
: take-while ( state quot: ( obj -- ? ) -- sequence/f )
[ not ] compose take-until ; inline
:: take-until-sequence ( state-parser sequence -- sequence' )
sequence length <growing-circular> :> growing
state-parser
@ -66,6 +69,5 @@ TUPLE: state-parser sequence n ;
: take-until-object ( state obj -- sequence )
'[ _ = ] take-until ;
: take-stuff ( state delimiter -- sequence )
;
: state-parse ( sequence quot -- )
[ <state-parser> ] dip call ; inline