[Bese-devel] Darcs patch parenscript

Henrik Hjelte henrik at evahjelte.com
Thu Feb 2 12:57:58 UTC 2006


Lisp strings are now properly converted to javascript strings.
Newlines, quotes, backquotes, tabs, unicode and other annoyances
should now be perfectly safe.

/Henrik Hjelte







-------------- next part --------------

New patches:

[proper escape sequences in strings
henrik.hjelte at poboxes.com**20060202123912] {
hunk ./src/js.lisp 383
-  (declare (ignore start-pos))
+  (declare (ignore start-pos)
+           (inline lisp-special-char-to-js))
hunk ./src/js.lisp 387
-             initially (write-char #\' escaped)
-             for char across (value string)
-             if (char= #\' char)
-               do (write-string "\\'" escaped)
-             else
-               do (write-char char escaped)
-             finally (write-char #\' escaped)))))
+           initially (write-char #\' escaped)
+           for char across (value string)
+           for code = (char-code char)
+           for special = (lisp-special-char-to-js char)
+           do
+           (cond
+             (special
+              (write-char #\\ escaped)
+              (write-char special escaped))
+             ((or (<= code #x1f) (>= code #x80))
+              (format escaped "\\u~4,'0x" code))
+             (t (write-char char escaped)))
+           finally (write-char #\' escaped)))))
+
+(defparameter *js-lisp-escaped-chars*
+  '((#\' . #\')
+    (#\\ . #\\)
+    (#\b . #\Backspace)
+    (#\f . #\Form)
+    (#\n . #\Newline)
+    (#\r . #\Return)
+    (#\t . #\Tab)))
+
+(defun lisp-special-char-to-js(lisp-char)
+    (car (rassoc lisp-char *js-lisp-escaped-chars*)))
hunk ./t/test.lisp 137
+(test escape-sequences-in-string
+  (let ((escapes `((#\\ . #\\)
+                   (#\b . #\Backspace)
+                   (#\f . #\Form)
+                   ("u000B" . ,(code-char #x000b));;Vertical tab, too uncommon to bother with
+                   (#\n . #\Newline)
+                   (#\r . #\Return)
+                   (#\' . #\');;Double quote need not be quoted because parenscript strings are single quoted
+                   (#\t . #\Tab)
+                   ("u001F" . ,(code-char #x001f));; character below 32
+                   ("u0080" . ,(code-char 128)) ;;Character over 127. Actually valid, parenscript escapes them to be sure.
+                   ("uABCD" . ,(code-char #xabcd)))));; Really above ascii.
+    (loop for (js-escape . lisp-char) in escapes
+          for generated = (js-to-string `(let ((x , (format nil "hello~ahi" lisp-char)))))
+          for wanted = (format nil "{
+  var x = 'hello\\~ahi';
+}" js-escape)
+          do (is (string= generated wanted)))))
+
}

Context:

[ref2test finds reference.lisp in docs dir
henrik.hjelte at poboxes.com**20060201111712] 
[merge parenscript-test.asd into parenscript.asd
Luca Capello <luca at pca.it>**20060127085709] 
[move doc files to docs/
Luca Capello <luca at pca.it>**20060123222548] 
[move test files to t/ and modify parenscript-test.asd as well
Luca Capello <luca at pca.it>**20060123215026] 
[move source files to src/ and modify parenscript.asd as well
Luca Capello <luca at pca.it>**20060123213152] 
[remove trailing spaces at endlines in *.lisp
Luca Capello <luca at pca.it>**20060123211927] 
[remove trailing spaces at empty lines in *.lisp
Luca Capello <luca at pca.it>**20060122215742] 
[pbook.py: convert endlines to Unix format
Luca Capello <luca at pca.it>**20060122211704] 
[css-inline compiles with cmucl
henrik.hjelte at poboxes.com**20060109113602] 
[changed CASE to SWITCH and made CASE more like Lisp.
henrik.hjelte at poboxes.com**20051227190529] 
[New function gen-js-name-string
Marco Baringer <mb at bese.it>**20051219160435
 This allows you to get a unique javascript name as a string and not
 just as a symbol.
] 
[bugfix slot-value
henrik.hjelte at poboxes.com**20051219131901] 
[bug in dwim-join
henrik.hjelte at poboxes.com**20051218171724] 
[css-inline generator
henrik.hjelte at poboxes.com**20051218111426] 
[cleaned reference
henrik.hjelte at poboxes.com**20051217095257] 
[tests from the reference
henrik.hjelte at poboxes.com**20051216180844] 
[quotes in introduction
henrik.hjelte at poboxes.com**20051216153949] 
[Added defgenerics for all the defmethods
Alan-Shields at omrf.ouhsc.edu**20051201191709
 Ze style warnings! Zey drive me craaaazy.
] 
[enable #+parenscript
Alan-Shields at omrf.ouhsc.edu**20051115235351
 To integrate Parenscript with Araneida without requiring Parenscript,
 I had to do some compile conditionals. This would make it much easier.
 
 Marco, eventually I am going to add this to every last one of your projects.
 ;-p
] 
[need a function for css-inlining
Alan-Shields at omrf.ouhsc.edu**20051115235233
 If you have code that needs to inline CSS across an array, it's difficult
 to use the current macro.
 Having a function helps - mapping the macro to the function only completes
 things.
] 
[Proper concatenation of inline CSS
Alan-Shields at omrf.ouhsc.edu**20051115234812
 CSS-INLINE does a simple concatenation of the results of CSS directives.
 This looks like:
 	color:blacksize:200%
 Unfortunately, it should look like this:
 	color:black;size:200%
 
 It now does.
] 
[added COPYING file
Luca Capello <luca at pca.it>**20051107123047] 
[Escape { and } chars in boring regexps
Marco Baringer <mb at bese.it>**20051107102118] 
[Need to escape #\' in javascript strings
Marco Baringer <mb at bese.it>**20051005090942] 
[Fix buf in JS-INLINE causing infinite macro expansion
Marco Baringer <mb at bese.it>**20051005082900] 
[Add in checks to deal with functions/macros whose names aren't symbols
Marco Baringer <mb at bese.it>**20050912081700] 
[Use strings, and not symbols, to name javascript functions/macros
Marco Baringer <mb at bese.it>**20050905082735
 
 This effectivly flattens the namespace of javascript code. While this
 change makes js similar to javascript, and removes the need to export
 symbols from the JS package, it may break previous code which depended
 on, for expample, js:and not being equivalent to js:and.
 
] 
[Added support for literal objects ( "{ ... }" syntax)
Marco Baringer <mb at bese.it>**20050905081702] 
[Export cen-js-names and with-unique-js-names
Marco Baringer <mb at bese.it>**20050831115820] 
[Added docstrings to previous patch
Marco Baringer <mb at bese.it>**20050815135128] 
[Added GEN-JS-NAME and WITH-UNIQUE-JS-NAMES
Marco Baringer <mb at bese.it>**20050815134940] 
[dotimes-dolist-fix
Ivan Toshkov <itoshkov at gmail.com>**20050815080906
 
 Fixes the infinite loop problems of `dotimes' and `dolist'.
] 
[Parenscript, documentation not withstandanding, does not depend on htmlgen
Marco Baringer <mb at bese.it>**20050815080053] 
[Attempt to improve the conversion of (js ((lambda ...) ...))
Marco Baringer <mb at bese.it>**20050815074902] 
[Introduce the JS-LAMBDA class. Make JS-DEFUN a subclass of JS-LAMBDA
Marco Baringer <mb at bese.it>**20050815074836] 
[Implement JS and JS-INLINE in terms of JS* and JS-INLINE*
Marco Baringer <mb at bese.it>**20050815063921] 
[Symbols starting with #\: are left as is, no case conversion or other mangling
Marco Baringer <mb at bese.it>**20050814141629] 
[Added JS* and JS-INLINE*. 
Marco Baringer <mb at bese.it>**20050814134534] 
[Javascript strings need to be quated with ' and not " to avoid interfering with the surrounding HTML.
Marco Baringer <mb at bese.it>**20050814134344] 
[Ugly hack to support ((lambda ...) ...)
Marco Baringer <mb at bese.it>**20050813142023] 
[Mention that I'm maintaining this version of parenscript
Marco Baringer <mb at bese.it>**20050813135238] 
[Rename the system/package in the system definition, just renaming the file doesn't cut it :(.
Marco Baringer <mb at bese.it>**20050813135107] 
[Added images used in documentation
Marco Baringer <mb at bese.it>**20050813134441] 
[Added the pbook.py file used to generate the documentation
Marco Baringer <mb at bese.it>**20050813133732] 
[Added declare ignore forms for unused function arguments
Marco Baringer <mb at bese.it>**20050808154843] 
[Rename system def
Marco Baringer <mb at bese.it>**20050808154836] 
[Setup boringfile
Marco Baringer <mb at bese.it>**20050726100549] 
[Added files from parenscript 0.1.0 as distributed by Manuel Odendahl
Marco Baringer <mb at bese.it>**20050726100416] 
Patch bundle hash:
6c7d141cb31eedb1ceb568961e082718ec71d381


More information about the bese-devel mailing list