From b1846b7fb31de1bbe126322688ac109fd86a924e Mon Sep 17 00:00:00 2001 From: Noah Lavine Date: Tue, 11 Jan 2011 16:32:17 -0500 Subject: [PATCH] Add ECMAScript Unicode literal support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * module/language/ecmascript/tokenize.scm: add unicode literals * test-suite/tests/ecmascript.test ("parser"): Add new tests for Latin-1 and Unicode escapes in string literals. Signed-off-by: Ludovic Courtès --- module/language/ecmascript/tokenize.scm | 8 ++++++-- test-suite/tests/ecmascript.test | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/module/language/ecmascript/tokenize.scm b/module/language/ecmascript/tokenize.scm index f7214458e..083c9434d 100644 --- a/module/language/ecmascript/tokenize.scm +++ b/module/language/ecmascript/tokenize.scm @@ -1,6 +1,6 @@ ;;; ECMAScript for Guile -;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -150,7 +150,11 @@ (else (syntax-error "bad hex character escape" loc (string a b)))))) ((#\u) - (syntax-error "unicode not supported" loc #f)) + (let* ((a (read-char port)) + (b (read-char port)) + (c (read-char port)) + (d (read-char port))) + (integer->char (string->number (string a b c d) 16)))) (else c)))) (let lp ((str (read-until terms port loc))) diff --git a/test-suite/tests/ecmascript.test b/test-suite/tests/ecmascript.test index b0861bbef..e96d383a4 100644 --- a/test-suite/tests/ecmascript.test +++ b/test-suite/tests/ecmascript.test @@ -48,7 +48,11 @@ (parse "var x = { foo: 12, bar: \"hello\" };" '(begin (var (x (object (foo (number 12)) (bar (string "hello"))))) - (begin)))) + (begin))) + (parse "\"\\x12\";" ; Latin-1 escape in string literal + '(string "\x12")) + (parse "\"\\u1234\";" ; Unicode escape in string literal + '(string "\u1234"))) (define-syntax ecompile