diff --git a/core/strings/parser/parser-tests.factor b/core/strings/parser/parser-tests.factor index 1ec482890d..82fd5aa504 100644 --- a/core/strings/parser/parser-tests.factor +++ b/core/strings/parser/parser-tests.factor @@ -34,3 +34,6 @@ IN: strings.parser.tests [ "\"\\" ] [ "\"\\" ] unit-test + +[ "\e" ] [ "\u00001b" ] unit-test +[ "\e" ] [ "\x1b" ] unit-test diff --git a/core/strings/parser/parser.factor b/core/strings/parser/parser.factor index e0c7cea1b4..037b0ad52f 100644 --- a/core/strings/parser/parser.factor +++ b/core/strings/parser/parser.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2008, 2009 Slava Pestov, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs kernel lexer make math math.parser -namespaces parser sequences splitting strings arrays -math.order ; +USING: accessors arrays assocs combinators kernel lexer make +math math.order math.parser namespaces parser sequences +splitting strings ; IN: strings.parser ERROR: bad-escape char ; @@ -27,6 +27,9 @@ name>char-hook [ [ "Unicode support not available" throw ] ] initialize +: hex-escape ( str -- ch str' ) + 2 cut-slice [ hex> ] dip ; + : unicode-escape ( str -- ch str' ) "{" ?head-slice [ CHAR: } over index cut-slice @@ -37,11 +40,11 @@ name>char-hook [ ] if ; : next-escape ( str -- ch str' ) - "u" ?head-slice [ - unicode-escape - ] [ - unclip-slice escape swap - ] if ; + dup first { + { CHAR: u [ 1 tail-slice unicode-escape ] } + { CHAR: x [ 1 tail-slice hex-escape ] } + [ drop unclip-slice escape swap ] + } case ; : (unescape-string) ( str -- ) CHAR: \\ over index dup [