diff --git a/basis/unicode/syntax/syntax.factor b/basis/unicode/syntax/syntax.factor index bf4610ab0d..b7ac022d0e 100644 --- a/basis/unicode/syntax/syntax.factor +++ b/basis/unicode/syntax/syntax.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: unicode.data kernel math sequences parser lexer bit-arrays namespaces make sequences.private arrays quotations -assocs classes.predicate math.order eval ; +assocs classes.predicate math.order strings.parser ; IN: unicode.syntax ! Character classes (categories) @@ -26,7 +26,7 @@ IN: unicode.syntax categories [ swap member? ] with map >bit-array ; : as-string ( strings -- bit-array ) - concat "\"" tuck 3append eval ; + concat unescape-string ; : [category] ( categories -- quot ) [ diff --git a/core/strings/parser/parser-tests.factor b/core/strings/parser/parser-tests.factor new file mode 100644 index 0000000000..80f649c204 --- /dev/null +++ b/core/strings/parser/parser-tests.factor @@ -0,0 +1,4 @@ +IN: strings.parser.tests +USING: strings.parser tools.test ; + +[ "Hello\n\rworld" ] [ "Hello\\n\\rworld" unescape-string ] unit-test diff --git a/core/strings/parser/parser.factor b/core/strings/parser/parser.factor index cfe5d1a90a..4062e16e3d 100644 --- a/core/strings/parser/parser.factor +++ b/core/strings/parser/parser.factor @@ -58,3 +58,15 @@ name>char-hook global [ lexer get [ [ swap tail-slice (parse-string) ] "" make swap ] change-lexer-column ; + +: (unescape-string) ( str -- str' ) + dup [ CHAR: \\ = ] find [ + cut-slice [ % ] dip rest-slice + next-escape [ , ] dip + (unescape-string) + ] [ + drop % + ] if ; + +: unescape-string ( str -- str' ) + [ (unescape-string) ] "" make ;