1 USING: assocs circular combinators continuations hashtables
2 hashtables.private io kernel math
3 namespaces prettyprint quotations sequences splitting
4 state-parser strings sequences.lib ;
7 : string-parse-end? ( -- ? ) get-next not ;
9 : take-string* ( match -- string )
10 dup length <circular-string>
11 [ 2dup string-matches? ] take-until nip
12 dup length rot length 1- - head next* ;
14 : trim1 ( seq ch -- newseq )
15 [ ?head drop ] [ ?tail drop ] bi ;
17 : single-quote ( str -- newstr )
18 "'" swap "'" 3append ;
20 : double-quote ( str -- newstr )
21 "\"" swap "\"" 3append ;
23 : quote ( str -- newstr )
25 [ double-quote ] [ single-quote ] if ;
27 : quoted? ( str -- ? )
29 [ [ first ] [ peek ] bi [ = ] keep "'\"" member? and ] if-empty ;
31 : ?quote ( str -- newstr )
32 dup quoted? [ quote ] unless ;
34 : unquote ( str -- newstr )
35 dup quoted? [ but-last-slice rest-slice >string ] when ;
37 : quote? ( ch -- ? ) "'\"" member? ;