[Bese-devel] Some patches for parenscript

Henrik Hjelte henrik.hjelte at poboxes.com
Mon Dec 19 14:26:01 UTC 2005


Here are some patches for ParenScript:

In order to make it less scary to change stuff, 
I have made a function to make testcases of all the
code which is in the reference. So the file reference-tests.lisp
is autogenerated.

Then I cleaned the reference.lisp file from small typos and errors.

The css generator that is in the parenscript project is lisp
server-side, so I made a corresponding little css generator that makes
it possible to generate style tags in parenscript.

A bug in the function dwim-join (see the testcase in test.lisp) was
solved. The dwim-join function is not easy to understand, I hope I have
not created any new problems, but the reference tests run OK.   

Finally, what I consider a bug in the parenscript slot-value function
was solved. See the testcases in test.lisp.

The pdf reference really ought to be updated, but I don't know latex so
I couldn't get the pbook script to work, I think there are some styles
missing.

Merry christmas everyone,

/Henrik Hjelte
-------------- next part --------------

New patches:

[quotes in introduction
henrik.hjelte at poboxes.com**20051216153949] {
hunk ./introduction.lisp 1
+(in-package :js)
hunk ./introduction.lisp 22
-
+"
hunk ./introduction.lisp 26
-
+"
hunk ./introduction.lisp 56
-
+"
hunk ./introduction.lisp 58
-  alert("i is " + i + " and j is " + j);
+  alert('i is ' + i + ' and j is ' + j);
hunk ./introduction.lisp 60
-
+"
hunk ./introduction.lisp 80
-
-{ foo : "foo", 
-  bla : "bla" }
-
+"
+{ foo : 'foo', 
+  bla : 'bla' }
+"
hunk ./introduction.lisp 98
-
+"
hunk ./introduction.lisp 100
-  document.write("<div id=\"" + name + "\">The link is: <a href=\""
-                                + href + "\">"
-                                + linkText + "</a></div>");
+  document.write('<div id=\"' + name + '\">The link is: <a href=\"'
+                                + href + '\">'
+                                + linkText + '</a></div>');
hunk ./introduction.lisp 104
-
+"
}

[tests from the reference
henrik.hjelte at poboxes.com**20051216180844] {
addfile ./parenscript-test.asd
hunk ./parenscript-test.asd 1
+;;;; -*- lisp -*-
+
+(in-package :cl-user)
+
+(defpackage #:parenscript-test.system
+  (:use :cl :asdf))
+
+(in-package #:parenscript-test.system)
+
+(defsystem #:parenscript-test
+    :depends-on (:parenscript :fiveam)
+    :components ((:file "test-package")
+                 (:file "test" :depends-on ("test-package"))
+                 (:file "ref2test" :depends-on ("test"))
+		 (:file "reference-tests" :depends-on ("test"))))
addfile ./ref2test.lisp
hunk ./ref2test.lisp 1
+(in-package :js-test) 
+;;Generates automatic tests from the reference
+
+(defparameter +reference-file+ (make-pathname :name "reference"
+                                              :type "lisp"
+                                              :defaults *load-truename*))
+(defparameter +generate-file+ (make-pathname :name "reference-tests"
+                                              :type "lisp"
+                                              :defaults *load-truename*))
+
+(defparameter +head+ "(in-package :js-test)
+;; Tests of everything in the reference.
+;; File is generated automatically from the text in reference.lisp by
+;; the function make-reference-tests-dot-lisp in ref2test.lisp
+;; so do not edit this file.
+(def-suite ref-tests)
+(in-suite ref-tests)~%~%") ; a double-quote for emacs: "
+  
+(defun make-reference-tests-dot-lisp()
+  (let ((built "")
+        heading
+        heading-count)
+    (with-open-file (out-stream +generate-file+
+                                :direction :output
+                                :if-exists :supersede)
+      (labels 
+          ((empty-p (str)
+             (zerop (length str)))
+           (trim-whitespace (str)
+             (string-trim '(#\Space #\Tab #\Newline) str))
+           (left (str count)
+             (subseq str 0 (min count (length str))))
+           (lispify-heading (heading)
+             (remove-if (lambda (ch) (or (char= ch #\`)(char= ch #\')))
+                        (substitute  #\- #\Space (string-downcase (trim-whitespace heading))
+                                     :test #'char=)))
+           (clean-quotes (str)
+             (substitute  #\' #\"  str :test #'char=))
+           (strip-indentation (str indentation)
+             (if indentation
+                 (js::string-join (mapcar #'(lambda (str)
+                                          (if (> (length str) indentation)
+                                              (subseq str indentation)
+                                              str))
+                                      (js::string-split str (list #\Newline)))
+                              (string #\Newline))
+                 str))
+
+           (make-test ()
+             (let* ((sep-pos (search "=>" built))
+                    (cr-before-sep  (when sep-pos
+                                      (or (position #\Newline
+                                                    (left built sep-pos)
+                                                    :from-end t
+                                                    :test #'char=)
+                                          0)))
+                    (js-indent-width (when cr-before-sep
+                                       (+ 2 (- sep-pos cr-before-sep))))
+                    (lisp-part (and sep-pos (left built sep-pos)))
+                    (javascript-part (when cr-before-sep
+                                       (subseq built (+ 1 cr-before-sep)))))
+               (cond
+                 ((null sep-pos)
+                  (print "Warning, separator not found"))
+                 ((search "=>" (subseq built (+ 1 sep-pos)))
+                  (print "Error , two separators found"))
+                 ((and (string= heading "regular-expression-literals")
+                       (= 2 heading-count)) ;requires cl-interpol reader
+                  (print "Skipping regex-test two"))
+                 ((and lisp-part javascript-part)
+                  (format out-stream "(test-ps-js ~a-~a ~%  ~a ~%  ~S)~%~%"
+                          heading heading-count
+                          (trim-whitespace lisp-part)
+                          (clean-quotes (strip-indentation javascript-part js-indent-width))))
+                 (t (print "Error, should not be here"))))))
+        (format out-stream +head+)
+        (with-open-file (stream +reference-file+ :direction :input)
+          (loop for line = (read-line stream nil nil)
+                with is-collecting
+                while line do
+                (cond
+                  ((string= (left line 4) ";;;#")
+                   (setf heading (lispify-heading (subseq line 5)))
+                   (setf heading-count 0)
+                   (when (string= (trim-whitespace heading)
+                                  "the-parenscript-compiler")
+                     (return)))
+                  ((string= (left line 1) ";") 'skip-comment)
+                  ((empty-p (trim-whitespace line))
+                   (when is-collecting
+                     (setf is-collecting nil)
+                     (incf heading-count)
+                     (make-test)
+                     (setf built "")))
+                  (t
+                   (setf is-collecting t
+                         built (concatenate 'string built
+                                            (when (not (empty-p built))
+                                              (list #\Newline))
+                                            line))))))
+        (format out-stream "~%(run! 'ref-tests)~%")))))
addfile ./reference-tests.lisp
hunk ./reference-tests.lisp 1
+(in-package :js-test)
+;; Tests of everything in the reference.
+;; File is generated automatically from the text in reference.lisp by
+;; the function make-reference-tests-dot-lisp in ref2test.lisp
+;; so do not edit this file.
+(def-suite ref-tests)
+(in-suite ref-tests)
+
+(test-ps-js statements-and-expressions-1 
+  (+ i (if 1 2 3)) 
+  "i + (1 ? 2 : 3)")
+
+(test-ps-js statements-and-expressions-2 
+  (if 1 2 3) 
+  "if (1) {
+  2;
+} else {
+  3;
+}")
+
+(test-ps-js symbol-conversion-1 
+  !?#$@% 
+  "bangwhathashdollaratpercent")
+
+(test-ps-js symbol-conversion-2 
+  bla-foo-bar 
+  "blaFooBar")
+
+(test-ps-js symbol-conversion-3 
+  *array 
+  "Array")
+
+(test-ps-js symbol-conversion-6 
+  *global-array* 
+  "GLOBALARRAY")
+
+(test-ps-js symbol-conversion-7 
+  *global-array*.length 
+  "GLOBALARRAY.length")
+
+(test-ps-js number-literals-1 
+  1 
+  "1")
+
+(test-ps-js number-literals-2 
+  123.123 
+  "123.123")
+
+(test-ps-js number-literals-3 
+  #x10 
+  "16")
+
+(test-ps-js array-literals-1 
+  (array) 
+  "[ ]")
+
+(test-ps-js array-literals-2 
+  (array 1 2 3) 
+  "[ 1, 2, 3 ]")
+
+(test-ps-js array-literals-3 
+  (array (array 2 3)
+       (array "foobar" "bratzel bub")) 
+  "[ [ 2, 3 ], [ 'foobar', 'bratzel bub' ] ]")
+
+(test-ps-js array-literals-4 
+  (make-array) 
+  "new Array()")
+
+(test-ps-js array-literals-5 
+  (make-array 1 2 3) 
+  "new Array(1, 2, 3)")
+
+(test-ps-js array-literals-6 
+  (make-array
+ (make-array 2 3)
+ (make-array "foobar" "bratzel bub")) 
+  "new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'))")
+
+(test-ps-js object-literals-1 
+  (create :foo "bar" :blorg 1) 
+  "{ foo : 'bar', 
+  blorg : 1 }")
+
+(test-ps-js object-literals-2 
+  (create :foo "hihi"
+        :blorg (array 1 2 3)
+        :another-object (create :schtrunz 1)) 
+  "{ foo : 'hihi', 
+  blorg : [ 1, 2, 3 ], 
+  anotherObject : { schtrunz : 1 } }")
+
+(test-ps-js object-literals-3 
+  (slot-value an-object 'foo) 
+  "anObject.foo")
+
+(test-ps-js object-literals-4 
+  an-object.foo 
+  "anObject.foo")
+
+(test-ps-js object-literals-5 
+  (with-slots (a b c) this
+  (+ a b c)) 
+  "this.a + this.b + this.c")
+
+(test-ps-js regular-expression-literals-1 
+  (regex "/foobar/i") 
+  "/foobar/i")
+
+(test-ps-js literal-symbols-2 
+  NIL 
+  "null")
+
+(test-ps-js literal-symbols-3 
+  UNDEFINED 
+  "undefined")
+
+(test-ps-js literal-symbols-4 
+  THIS 
+  "this")
+
+(test-ps-js variables-1 
+  variable 
+  "variable")
+
+(test-ps-js variables-2 
+  a-variable 
+  "aVariable")
+
+(test-ps-js variables-3 
+  *math 
+  "Math")
+
+(test-ps-js variables-4 
+  *math.floor 
+  "Math.floor")
+
+(test-ps-js function-calls-and-method-calls-1 
+  (blorg 1 2) 
+  "blorg(1, 2)")
+
+(test-ps-js function-calls-and-method-calls-2 
+  (foobar (blorg 1 2) (blabla 3 4) (array 2 3 4)) 
+  "foobar(blorg(1, 2), blabla(3, 4), [ 2, 3, 4 ])")
+
+(test-ps-js function-calls-and-method-calls-3 
+  ((aref foo i) 1 2) 
+  "foo[i](1, 2)")
+
+(test-ps-js function-calls-and-method-calls-4 
+  (.blorg this 1 2) 
+  "this.blorg(1, 2)")
+
+(test-ps-js function-calls-and-method-calls-5 
+  (this.blorg 1 2) 
+  "this.blorg(1, 2)")
+
+(test-ps-js function-calls-and-method-calls-6 
+  (.blorg (aref foobar 1) NIL T) 
+  "foobar[1].blorg(null, true)")
+
+(test-ps-js operator-expressions-1 
+  (* 1 2) 
+  "1 * 2")
+
+(test-ps-js operator-expressions-2 
+  (= 1 2) 
+  "1 == 2")
+
+(test-ps-js operator-expressions-3 
+  (eql 1 2) 
+  "1 == 2")
+
+(test-ps-js operator-expressions-5 
+  (* 1 (+ 2 3 4) 4 (/ 6 7)) 
+  "1 * (2 + 3 + 4) * 4 * (6 / 7)")
+
+(test-ps-js operator-expressions-6 
+  (++ i) 
+  "i++")
+
+(test-ps-js operator-expressions-7 
+  (-- i) 
+  "i--")
+
+(test-ps-js operator-expressions-8 
+  (incf i) 
+  "++i")
+
+(test-ps-js operator-expressions-9 
+  (decf i) 
+  "--i")
+
+(test-ps-js operator-expressions-10 
+  (1- i) 
+  "i - 1")
+
+(test-ps-js operator-expressions-11 
+  (1+ i) 
+  "i + 1")
+
+(test-ps-js operator-expressions-12 
+  (not (< i 2)) 
+  "i >= 2")
+
+(test-ps-js operator-expressions-13 
+  (not (eql i 2)) 
+  "i != 2")
+
+(test-ps-js body-forms-1 
+  (progn (blorg i) (blafoo i)) 
+  "blorg(i);
+blafoo(i);")
+
+(test-ps-js body-forms-2 
+  (+ i (progn (blorg i) (blafoo i))) 
+  "i + (blorg(i), blafoo(i))")
+
+(test-ps-js function-definition-1 
+  (defun a-function (a b)
+  (return (+ a b))) 
+  "function aFunction(a, b) {
+  return a + b;
+}")
+
+(test-ps-js function-definition-2 
+  (lambda (a b) (return (+ a b))) 
+  "function (a, b) {
+  return a + b;
+}")
+
+(test-ps-js assignment-1 
+  (setf a 1) 
+  "a = 1")
+
+(test-ps-js assignment-2 
+  (setf a 2 b 3 c 4 x (+ a b c)) 
+  "a = 2;
+b = 3;
+c = 4;
+x = a + b + c;")
+
+(test-ps-js assignment-3 
+  (setf a (1+ a)) 
+  "a++")
+
+(test-ps-js assignment-4 
+  (setf a (* 2 3 4 a 4 a)) 
+  "a *= 2 * 3 * 4 * 4 * a")
+
+(test-ps-js assignment-5 
+  (setf a (- 1 a)) 
+  "a = 1 - a")
+
+(test-ps-js single-argument-statements-1 
+  (return 1) 
+  "return 1")
+
+(test-ps-js single-argument-statements-2 
+  (throw "foobar") 
+  "throw 'foobar'")
+
+(test-ps-js single-argument-expression-1 
+  (delete (new (*foobar 2 3 4))) 
+  "delete new Foobar(2, 3, 4)")
+
+(test-ps-js single-argument-expression-2 
+  (if (= (typeof blorg) *string)
+    (alert (+ "blorg is a string: " blorg))
+    (alert "blorg is not a string")) 
+  "if (typeof blorg == String) {
+  alert('blorg is a string: ' + blorg);
+} else {
+  alert('blorg is not a string');
+}")
+
+(test-ps-js conditional-statements-1 
+  (if (blorg.is-correct)
+    (progn (carry-on) (return i))
+    (alert "blorg is not correct!")) 
+  "if (blorg.isCorrect()) {
+  carryOn();
+  return i;
+} else {
+  alert('blorg is not correct!');
+}")
+
+(test-ps-js conditional-statements-2 
+  (+ i (if (blorg.add-one) 1 2)) 
+  "i + (blorg.addOne() ? 1 : 2)")
+
+(test-ps-js conditional-statements-3 
+  (when (blorg.is-correct)
+  (carry-on)
+  (return i)) 
+  "if (blorg.isCorrect()) {
+  carryOn();
+  return i;
+}")
+
+(test-ps-js conditional-statements-4 
+  (unless (blorg.is-correct)
+  (alert "blorg is not correct!")) 
+  "if (!blorg.isCorrect()) {
+  alert('blorg is not correct!');
+}")
+
+(test-ps-js variable-declaration-1 
+  (defvar *a* (array 1 2 3)) 
+  "var A = [ 1, 2, 3 ]")
+
+(test-ps-js variable-declaration-2 
+  (if (= i 1)
+    (progn (defvar blorg "hallo")
+           (alert blorg))
+    (progn (defvar blorg "blitzel")
+           (alert blorg))) 
+  "if (i == 1) {
+  var blorg = 'hallo';
+  alert(blorg);
+} else {
+  var blorg = 'blitzel';
+  alert(blorg);
+}")
+
+(test-ps-js variable-declaration-3 
+  (if (= i 1)
+    (let ((blorg "hallo"))
+      (alert blorg))
+    (let ((blorg "blitzel"))
+      (alert blorg))) 
+  "if (i == 1) {
+  var blorg = 'hallo';
+  alert(blorg);
+} else {
+  var blorg = 'blitzel';
+  alert(blorg);
+}")
+
+(test-ps-js iteration-constructs-1 
+  (do ((i 0 (1+ i))
+     (l (aref blorg i) (aref blorg i)))
+    ((or (= i blorg.length)
+         (eql l "Fumitastic")))
+  (document.write (+ "L is " l))) 
+  "for (var i = 0, l = blorg[i];
+i == blorg.length || l == 'Fumitastic');
+     i = i + 1, l = blorg[i]) {
+  document.write('L is ' + l);
+}")
+
+(test-ps-js iteration-constructs-2 
+  (dotimes (i blorg.length)
+  (document.write (+ "L is " (aref blorg i)))) 
+  "for (var i = 0; i != blorg.length; i = i++) {
+  document.write('L is ' + blorg[i]);
+}")
+
+(test-ps-js iteration-constructs-3 
+  (dolist (l blorg)
+  (document.write (+ "L is " l))) 
+  "var tmpArr1 = blorg;
+for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
+pI2 = tmpI2++) {
+  var l = tmpArr1[tmpI2];
+  document.write('L is ' + l);
+}")
+
+(test-ps-js iteration-constructs-4 
+  (doeach (i object)
+   (document.write (+ i " is " (aref object i)))) 
+  "for (var i in object) {
+  document.write(i + ' is ' + object[i]);
+}")
+
+(test-ps-js iteration-constructs-5 
+  (while (film.is-not-finished)
+  (this.eat (new *popcorn))) 
+  "while (film.isNotFinished()) {
+  this.eat(new Popcorn);
+}")
+
+(test-ps-js the-case-statement-1 
+  (case (aref blorg i)
+  (1 (alert "one"))
+  (2 (alert "two"))
+  (default (alert "default clause"))) 
+  "switch (blorg[i]) {
+  case 1:   alert('one');
+  case 2:   alert('two');
+  default:   alert('default clause');
+}")
+
+(test-ps-js the-with-statement-1 
+  (with ((create :foo "foo" :i "i"))
+  (alert (+ "i is now intermediary scoped: " i))) 
+  "with ({ foo : 'foo', 
+        i : 'i' }) {
+  alert('i is now intermediary scoped: ' + i);
+}")
+
+(test-ps-js the-try-statement-1 
+  (try (throw "i") 
+ (:catch (error)
+   (alert (+ "an error happened: " error)))
+ (:finally
+   (alert "Leaving the try form"))) 
+  "try {
+  throw 'i';
+} catch (error) {
+  alert('an error happened: ' + error);
+} finally {
+  alert('Leaving the try form');
+}")
+
+(test-ps-js the-html-generator-1 
+  (html ((:a :href "foobar") "blorg")) 
+  "'<a href=\\'foobar\\'>blorg</a>'")
+
+(test-ps-js the-html-generator-2 
+  (html ((:a :href (generate-a-link)) "blorg")) 
+  "'<a href=\\'' + generateALink() + '\\'>blorg</a>'")
+
+(test-ps-js the-html-generator-3 
+  (document.write
+ (html ((:a :href "#"
+            :onclick (js-inline (transport))) "link"))) 
+  "document.write('<a href=\\'#\\' onclick=\\''
+               + 'javascript:transport();'
+               + '\\'>link</a>')")
+
+
+(run! 'ref-tests)
addfile ./test-package.lisp
hunk ./test-package.lisp 1
+(in-package :cl-user)
+
+(defpackage :js-test
+  (:use :common-lisp :js :5am)
+  (:shadowing-import-from :js :!)
+  (:export #:run-tests
+           #:make-reference-tests-dot-lisp))
addfile ./test.lisp
hunk ./test.lisp 1
+(in-package :js-test)
+;; Testcases for parenscript
+
+(defun trim-whitespace(str)
+  (string-trim '(#\Space #\Tab #\Newline) str))
+
+(defmacro test-ps-js (testname parenscript javascript)
+  `(test ,testname ()
+    (is (string= (trim-whitespace (js-to-string ',parenscript))
+                 (trim-whitespace ,javascript)))))
+
+(defun run-tests()
+  (run! 'ref-tests))
}

[cleaned reference
henrik.hjelte at poboxes.com**20051217095257] {
hunk ./parenscript-test.asd 11
-    :depends-on (:parenscript :fiveam)
+    :depends-on (:parenscript :fiveam :cl-ppcre)
hunk ./ref2test.lisp 37
-           (clean-quotes (str)
-             (substitute  #\' #\"  str :test #'char=))
hunk ./ref2test.lisp 62
-                  (print "Warning, separator not found"))
+                  (format t "Ignoring:~a...~%" (left built 40)))
hunk ./ref2test.lisp 64
-                  (print "Error , two separators found"))
+                  (format t "Error , two separators found~%"))
hunk ./ref2test.lisp 67
-                  (print "Skipping regex-test two"))
+                  (format t "Skipping regex-test two~&"))
hunk ./ref2test.lisp 69
-                  (format out-stream "(test-ps-js ~a-~a ~%  ~a ~%  ~S)~%~%"
+                  (format out-stream "(test-ps-js ~a-~a ~%  ~a ~%  \"~a\")~%~%"
hunk ./ref2test.lisp 72
-                          (clean-quotes (strip-indentation javascript-part js-indent-width))))
-                 (t (print "Error, should not be here"))))))
+                          (strip-indentation javascript-part js-indent-width)))
+                 (t (format t "Error, should not be here~%"))))))
hunk ./reference-tests.lisp 53
+(test-ps-js string-literals-1 
+  "foobar" 
+  "'foobar'")
+
+(test-ps-js string-literals-2 
+  "bratzel bub" 
+  "'bratzel bub'")
+
hunk ./reference-tests.lisp 63
-  "[ ]")
+  "[  ]")
hunk ./reference-tests.lisp 112
-  "this.a + this.b + this.c")
+  "this.a + this.b + this.c;")
hunk ./reference-tests.lisp 118
+(test-ps-js literal-symbols-1 
+  T 
+  "true")
+
hunk ./reference-tests.lisp 123
+  FALSE 
+  "false")
+
+(test-ps-js literal-symbols-3 
hunk ./reference-tests.lisp 130
-(test-ps-js literal-symbols-3 
+(test-ps-js literal-symbols-4 
hunk ./reference-tests.lisp 134
-(test-ps-js literal-symbols-4 
+(test-ps-js literal-symbols-5 
hunk ./reference-tests.lisp 326
-  "var A = [ 1, 2, 3 ]")
+  "var A = [ 1, 2, 3 ];")
hunk ./reference-tests.lisp 362
-  "for (var i = 0, l = blorg[i];
-i == blorg.length || l == 'Fumitastic');
+  "for (var i = 0, l = blorg[i]; 
+     !(i == blorg.length || l == 'Fumitastic');
hunk ./reference-tests.lisp 371
-  "for (var i = 0; i != blorg.length; i = i++) {
+  "for (var i = 0; i < blorg.length; i = i + 1) {
hunk ./reference-tests.lisp 378
-  "var tmpArr1 = blorg;
-for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
-pI2 = tmpI2++) {
-  var l = tmpArr1[tmpI2];
-  document.write('L is ' + l);
+  "{
+  var tmpArr1 = blorg;
+  for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
+    tmpI2 = tmpI2 + 1) {
+    var l = tmpArr1[tmpI2];
+    document.write('L is ' + l);
+  }
hunk ./reference-tests.lisp 436
-  "'<a href=\\'foobar\\'>blorg</a>'")
+  "'<a href=\"foobar\">blorg</a>'")
hunk ./reference-tests.lisp 440
-  "'<a href=\\'' + generateALink() + '\\'>blorg</a>'")
+  "'<a href=\"' + generateALink() + '\">blorg</a>'")
hunk ./reference-tests.lisp 444
- (html ((:a :href "#"
+  (html ((:a :href "#"
hunk ./reference-tests.lisp 446
-  "document.write('<a href=\\'#\\' onclick=\\''
-               + 'javascript:transport();'
-               + '\\'>link</a>')")
+  "document.write
+('<a href=\"#\" onclick=\"' + 'javascript:transport();' + '\">link</a>')")
hunk ./reference.lisp 123
-"foobar"      => "foobar"
-"bratzel bub" => "bratzel bub"
+"foobar"      => 'foobar'
+
+"bratzel bub" => 'bratzel bub'
hunk ./reference.lisp 148
-(array)       => [ ]
+(array)       => [  ]
hunk ./reference.lisp 154
-   => [ [ 2, 3 ], [ "foobar", "bratzel bub" ] ]
+   => [ [ 2, 3 ], [ 'foobar', 'bratzel bub' ] ]
hunk ./reference.lisp 167
-  => new Array(new Array(2, 3), new Array("foobar", "bratzel bub"))
+  => new Array(new Array(2, 3), new Array('foobar', 'bratzel bub'))
hunk ./reference.lisp 200
-   => { foo : "bar", 
+   => { foo : 'bar', 
hunk ./reference.lisp 206
-   => { foo : "hihi", 
+   => { foo : 'hihi', 
hunk ./reference.lisp 225
-    => this.a + this.b + this.c
+    => this.a + this.b + this.c;
hunk ./reference.lisp 262
+
hunk ./reference.lisp 526
-(throw "foobar") => throw "foobar"
+(throw "foobar") => throw 'foobar'
hunk ./reference.lisp 558
-       alert("blorg is a string: " + blorg);
+       alert('blorg is a string: ' + blorg);
hunk ./reference.lisp 560
-       alert("blorg is not a string");
+       alert('blorg is not a string');
hunk ./reference.lisp 593
-        alert("blorg is not correct!");
+        alert('blorg is not correct!');
hunk ./reference.lisp 613
-         alert("blorg is not correct!");
+         alert('blorg is not correct!');
hunk ./reference.lisp 636
-(defvar *a* (array 1 2 3)) => var A = [ 1, 2, 3 ]
+(defvar *a* (array 1 2 3)) => var A = [ 1, 2, 3 ];
hunk ./reference.lisp 644
-        var blorg = "hallo";
+        var blorg = 'hallo';
hunk ./reference.lisp 647
-        var blorg = "blitzel";
+        var blorg = 'blitzel';
hunk ./reference.lisp 660
-        var blorg = "hallo";
+        var blorg = 'hallo';
hunk ./reference.lisp 663
-        var blorg = "blitzel";
+        var blorg = 'blitzel';
hunk ./reference.lisp 709
-   => for (var i = 0, l = blorg[i];
-	   !(i == blorg.length || l == "Fumitastic");
+   => for (var i = 0, l = blorg[i]; 
+           !(i == blorg.length || l == 'Fumitastic');
hunk ./reference.lisp 712
-        document.write("L is " + l);
+        document.write('L is ' + l);
hunk ./reference.lisp 720
-   => for (var i = 0; i != blorg.length; i = i++) {
-        document.write("L is " + blorg[i]);
+   => for (var i = 0; i < blorg.length; i = i + 1) {
+        document.write('L is ' + blorg[i]);
hunk ./reference.lisp 730
-   => var tmpArr1 = blorg;
-      for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
-	   tmpI2 = tmpI2++) {
-        var l = tmpArr1[tmpI2];
-        document.write("L is " + l);
+   => {
+        var tmpArr1 = blorg;
+        for (var tmpI2 = 0; tmpI2 < tmpArr1.length;
+          tmpI2 = tmpI2 + 1) {
+          var l = tmpArr1[tmpI2];
+          document.write('L is ' + l);
+        }
hunk ./reference.lisp 738
+
hunk ./reference.lisp 747
-        document.write(i + " is " + object[i]);
+        document.write(i + ' is ' + object[i]);
hunk ./reference.lisp 780
-         case 1:   alert("one");
-         case 2:   alert("two");
-         default:   alert("default clause");
+         case 1:   alert('one');
+         case 2:   alert('two');
+         default:   alert('default clause');
hunk ./reference.lisp 803
-   => with ({ foo : "foo", 
-              i : "i" }) {
-        alert("i is now intermediary scoped: " + i);
+   => with ({ foo : 'foo', 
+              i : 'i' }) {
+        alert('i is now intermediary scoped: ' + i);
hunk ./reference.lisp 832
-        throw "i";
+        throw 'i';
hunk ./reference.lisp 834
-        alert("an error happened: " + error);
+        alert('an error happened: ' + error);
hunk ./reference.lisp 836
-        alert("Leaving the try form");
+        alert('Leaving the try form');
hunk ./reference.lisp 852
-  => "<a href=\"foobar\">blorg</a>"
+  => '<a href=\"foobar\">blorg</a>'
hunk ./reference.lisp 855
-  => "<a href=\"" + generateALink() + "\">blorg</a>"
+  => '<a href=\"' + generateALink() + '\">blorg</a>'
hunk ./reference.lisp 860
- (html ((:a :href "#"
+  (html ((:a :href "#"
hunk ./reference.lisp 862
-  => document.write("<a href=\"#\" onclick=\""
-                    + "javascript:transport();"
-                    + "\">link</a>")
+  => document.write
+     ('<a href=\"#\" onclick=\"' + 'javascript:transport();' + '\">link</a>')
hunk ./test.lisp 7
+(defun same-space-between-statements(code)
+  (cl-ppcre:regex-replace-all "\\s*;\\s*" code (concatenate 'string (list #\; #\Newline))))
+
+(defun no-indentation(code)
+  (cl-ppcre:regex-replace-all (cl-ppcre:create-scanner "^\\s*" :multi-line-mode t) code ""))
+
+(defun no-trailing-spaces(code)
+  (cl-ppcre:regex-replace-all (cl-ppcre:create-scanner "\\s*$" :multi-line-mode t) code ""))
+
+(defun normalize-js-code(str)
+  (trim-whitespace (no-indentation (no-trailing-spaces (same-space-between-statements str)))))
+
hunk ./test.lisp 21
-    (is (string= (trim-whitespace (js-to-string ',parenscript))
-                 (trim-whitespace ,javascript)))))
+    (setf js::*var-counter* 0)
+    ;; is-macro expands its argument again when reporting failures, so
+    ;; the reported temporary js-variables get wrong if we don't evalute first.
+    (let ((generated-code (js-to-string ',parenscript))
+          (js-code ,javascript))
+      (is (string= (normalize-js-code generated-code)
+                   (normalize-js-code js-code)))))) 
}

[css-inline generator
henrik.hjelte at poboxes.com**20051218111426] {
hunk ./js-html.lisp 62
+(defun process-css-forms(proplist)
+  (optimize-string-list (butlast
+                         (loop for propval on proplist by #'cddr appending
+                              (list (string-downcase ( symbol-name (first propval)))
+                                    ":"
+                                    (second propval)
+                                    ";")))))
+
+
+(define-js-compiler-macro css-inline (&rest forms)
+  (js-compile-to-expression (cons '+ (process-css-forms forms))))
+
hunk ./reference-tests.lisp 449
+(test-ps-js the-html-generator-4 
+  (css-inline :color "red"
+            :font-size "x-small") 
+  "'color:red;font-size:x-small'")
+
+(test-ps-js the-html-generator-5 
+  (defun make-color-div(color-name)
+    (return (html ((:div :style (css-inline :color color-name))
+                   color-name " looks like this.")))) 
+  "function makeColorDiv(colorName) {
+  return '<div style=\"' + ('color:' + colorName) + '\">' + colorName
+    + ' looks like this.</div>';
+}")
+
hunk ./reference.lisp 842
+;;;t \index{CSS}
+;;;t \index{CSS generation}
+
hunk ./reference.lisp 867
+
+; (CSS-INLINE css-expression)
+
+;;; Stylesheets can also be created in ParenScript.
+
+(css-inline :color "red"
+            :font-size "x-small")
+  => 'color:red;font-size:x-small'
+
+(defun make-color-div(color-name)
+    (return (html ((:div :style (css-inline :color color-name))
+                   color-name " looks like this."))))
+  => function makeColorDiv(colorName) {
+       return '<div style=\"' + ('color:' + colorName) + '\">' + colorName
+         + ' looks like this.</div>';
+     }
}

[bug in dwim-join
henrik.hjelte at poboxes.com**20051218171724] {
hunk ./js.lisp 122
-		  &key start end
-		       join-before join-after
-		  white-space (separator " ")
+		  &key (start "")
+                       end
+		       (join-before "")
+                       join-after
+		       (white-space (make-string (length start) :initial-element #\Space))
+                       (separator " ")
hunk ./js.lisp 133
-    (unless start
-      (setf start ""))
-
-    (unless join-before
-      (setf join-before ""))
-
hunk ./js.lisp 138
+          (is-first t nil)
hunk ./js.lisp 140
-	  (white-space (or white-space (make-string (length start) :initial-element #\Space)))
hunk ./js.lisp 151
-
hunk ./js.lisp 172
-				   (if cur-empty "" (concatenate 'string separator join-before))
+				   (if (or is-first (and cur-empty (string= join-before "")))
+                                        "" (concatenate 'string separator join-before))
hunk ./js.lisp 189
-						 cur-elt (if (null res)
-							     "" join-before)
+						 cur-elt
+                                                 (if (null res)
+						     "" join-before)
hunk ./js.lisp 194
-					    (cdr string-list)))) res))
+					    (cdr string-list))))
+                             res))
hunk ./js.lisp 481
-    (dwim-join value-string-lists max-length :join-before op-string)))
+    (dwim-join value-string-lists max-length :join-before op-string)    
+    ))
hunk ./ref2test.lisp 99
-        (format out-stream "~%(run! 'ref-tests)~%")))))
+        (format out-stream "~%(run-tests)~%")))))
hunk ./reference-tests.lisp 464
-(run! 'ref-tests)
+(run-tests)
hunk ./test.lisp 2
+
hunk ./test.lisp 31
-  (run! 'ref-tests))
+  (format t "Running reference tests:~&")
+  (run! 'ref-tests)
+  (format t "Running other tests:~&")
+  (run! 'ps-tests))
+
+;;---------------------------------------------------------------------------
+(def-suite ps-tests)
+(in-suite ps-tests)
+
+;; A problem with long nested operator, when the statement spanned several rows
+;; the rows would not be joined together correctly.
+(test-ps-js bug-dwim-join
+   (alert (html ((:div :id 777
+                       :style (css-inline :border "1pxsssssssssss"
+                                          :font-size "x-small"
+                                          :height (* 2 200)
+                                          :width (* 2 300))))))
+   "alert
+('<div id=\"777\" style=\"'
+ + ('border:1pxsssssssssss;font-size:x-small;height:' + 2 * 200 + ';width:'
+ + 2 * 300)
+ + '\"></div>')") ;";This line should start with a plus character.
}

[bugfix slot-value
henrik.hjelte at poboxes.com**20051219131901] {
hunk ./js.lisp 730
-		 :slot (js-compile-to-symbol slot)))
+   		   :slot (js-compile slot)))
hunk ./js.lisp 734
-		  (format nil ".~A" (symbol-to-js (sv-slot sv)))))
+                  (if (symbolp (sv-slot sv))
+		      (format nil ".~A" (symbol-to-js (sv-slot sv)))
+                      (format nil "[~A]" (first (js-to-strings (sv-slot sv) 0))))))
hunk ./js.lisp 1376
-
hunk ./test.lisp 54
+
+(test-ps-js simple-slot-value 
+  (let ((foo (create :a 1)))
+   (alert (slot-value foo 'a)))
+  "{
+    var foo = { a : 1 };
+    alert(foo.a);
+   }")
+
+(test-ps-js buggy-slot-value 
+   (let ((foo (create :a 1))
+        (slot-name "a"))
+    (alert (slot-value foo slot-name)))
+  "{
+    var foo = { a : 1 };
+    var slotName = 'a';
+    alert(foo[slotName]);
+   }"); Last line was alert(foo.slotName) before bug-fix.
+
+(test-ps-js buggy-slot-value-two
+  (slot-value foo (get-slot-name))
+  "foo[getSlotName()]")
+
}

Context:

[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:
629c8b00ea6e22bbeaf2b1622c4265a92521dfe3


More information about the bese-devel mailing list