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 >r >string name>char-hook get call r>
35 6 cut-slice >r hex> r>
38 : next-escape ( str -- ch str' )
42 unclip-slice escape swap
45 : (parse-string) ( str -- m )
46 dup [ "\"\\" member? ] find dup [
47 >r cut-slice >r % r> rest-slice r>
51 drop next-escape >r , r> (parse-string)
54 "Unterminated string" throw
57 : parse-string ( -- str )
59 [ swap tail-slice (parse-string) ] "" make swap
60 ] change-lexer-column ;