1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs circular combinators continuations hashtables
4 hashtables.private io kernel math namespaces prettyprint
5 quotations sequences splitting state-parser strings ;
8 : string-parse-end? ( -- ? ) get-next not ;
10 : take-string* ( match -- string )
11 dup length <circular-string>
12 [ 2dup string-matches? ] take-until nip
13 dup length rot length 1- - head next* ;
15 : trim1 ( seq ch -- newseq )
16 [ ?head drop ] [ ?tail drop ] bi ;
18 : single-quote ( str -- newstr )
21 : double-quote ( str -- newstr )
24 : quote ( str -- newstr )
26 [ double-quote ] [ single-quote ] if ;
28 : quoted? ( str -- ? )
30 [ [ first ] [ peek ] bi [ = ] keep "'\"" member? and ] if-empty ;
32 : ?quote ( str -- newstr )
33 dup quoted? [ quote ] unless ;
35 : unquote ( str -- newstr )
36 dup quoted? [ but-last-slice rest-slice >string ] when ;
38 : quote? ( ch -- ? ) "'\"" member? ;