1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel assocs namespaces make splitting sequences
4 strings math.parser lexer accessors ;
9 : escape ( escape -- ch )
21 } at [ bad-escape ] unless* ;
23 SYMBOL: name>char-hook
25 name>char-hook global [
26 [ "Unicode support not available" throw ] or
29 : unicode-escape ( str -- ch str' )
31 CHAR: } over index cut-slice
32 [ >string name>char-hook get call ] dip
35 6 cut-slice [ hex> ] dip
38 : next-escape ( str -- ch str' )
42 unclip-slice escape swap
45 : (parse-string) ( str -- m )
46 dup [ "\"\\" member? ] find dup [
47 [ cut-slice [ % ] dip rest-slice ] dip
51 drop next-escape [ , ] dip (parse-string)
54 "Unterminated string" throw
57 : parse-string ( -- str )
59 [ swap tail-slice (parse-string) ] "" make swap
60 ] change-lexer-column ;
62 : (unescape-string) ( str -- str' )
63 dup [ CHAR: \\ = ] find [
64 cut-slice [ % ] dip rest-slice
71 : unescape-string ( str -- str' )
72 [ (unescape-string) ] "" make ;