From f994654af31bcabe23a695fb6ddaffd10c5cc992 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 02:45:20 -0500 Subject: [PATCH] add take-while to state parser --- extra/html/parser/state/state.factor | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index 177a427716..e1951fbd7c 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -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 -- ) - [ ] 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 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 -- ) + [ ] dip call ; inline