1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

Add ECMAScript Unicode literal support

* 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 <ludo@gnu.org>
This commit is contained in:
Noah Lavine 2011-01-11 16:32:17 -05:00 committed by Ludovic Courtès
parent a7d8a8a63b
commit b1846b7fb3
2 changed files with 11 additions and 3 deletions

View file

@ -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)))

View file

@ -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