]> gitweb.factorcode.org Git - factor.git/commitdiff
strings.parser: support "\x" ascii hex escapes.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 27 Jul 2012 02:24:25 +0000 (19:24 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 27 Jul 2012 02:24:25 +0000 (19:24 -0700)
core/strings/parser/parser-tests.factor
core/strings/parser/parser.factor

index 1ec482890d9a1b1d355853b04bb9aafddbd73b83..82fd5aa504922d2cf4216b5e133bc55c530b5f05 100644 (file)
@@ -34,3 +34,6 @@ IN: strings.parser.tests
 
 
 [ "\"\\" ] [ "\"\\" ] unit-test
+
+[ "\e" ] [ "\u00001b" ] unit-test
+[ "\e" ] [ "\x1b" ] unit-test
index e0c7cea1b4a0fc2706f9cae49f3e9acccc842f66..037b0ad52f13f922e30413483b98565d9666dbe9 100644 (file)
@@ -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 [