1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel summary assocs namespaces splitting sequences
4 strings math.parser lexer ;
9 M: bad-escape summary drop "Bad escape code" ;
11 : escape ( escape -- ch )
23 } at [ bad-escape ] unless* ;
25 SYMBOL: name>char-hook
27 name>char-hook global [
28 [ "Unicode support not available" throw ] or
31 : unicode-escape ( str -- ch str' )
33 CHAR: } over index cut-slice
34 >r >string name>char-hook get call r>
37 6 cut-slice >r hex> r>
40 : next-escape ( str -- ch str' )
44 unclip-slice escape swap
47 : (parse-string) ( str -- m )
48 dup [ "\"\\" member? ] find dup [
49 >r cut-slice >r % r> rest-slice r>
53 drop next-escape >r , r> (parse-string)
56 "Unterminated string" throw
59 : parse-string ( -- str )
61 [ swap tail-slice (parse-string) ] "" make swap
62 ] change-lexer-column ;