Use WITH-OUTPUT-TO-STRING instead of CONCATENATE, because the latter fails when there...
[clinton/parenscript.git] / src / compilation-interface.lisp
1 (in-package :parenscript)
2
3 (defmacro ps (&body body)
4 "Given Parenscript forms (an implicit progn), compiles those forms
5 to a JavaScript string at macro-expansion time."
6 `(concatenate 'string ,@(parenscript-print (compile-parenscript-form `(progn ,@body) :expecting :statement))))
7
8 (defmacro ps-doc (&body body)
9 "Expands Parenscript forms in a clean environment."
10 (let ((*ps-gensym-counter* 0)
11 (*ps-special-variables* nil))
12 (macroexpand-1 `(ps ,@body))))
13
14 (defun ps-doc* (ps-form)
15 (let ((*ps-gensym-counter* 0)
16 (*ps-special-variables* nil))
17 (ps1* ps-form)))
18
19 (defun ps1* (ps-form)
20 (with-output-to-string (s)
21 (mapc (lambda (x)
22 (princ (if (stringp x)
23 x
24 (eval x))
25 s))
26 (parenscript-print (compile-parenscript-form ps-form :expecting :statement)))))
27
28 (defun ps* (&rest body)
29 "Compiles BODY to a JavaScript string.
30 Body is evaluated."
31 (ps1* `(progn ,@body)))
32
33 (defvar *js-inline-string-delimiter* #\"
34 "Controls the string delimiter char used when compiling Parenscript in ps-inline.")
35
36 (defun ps-inline* (form &optional (*js-string-delimiter* *js-inline-string-delimiter*))
37 (concatenate 'string "javascript:" (ps1* form)))
38
39 (defmacro/ps ps-inline (form &optional (string-delimiter *js-inline-string-delimiter*))
40 `(concatenate 'string "javascript:"
41 ,@(let ((*js-string-delimiter* string-delimiter))
42 (parenscript-print (compile-parenscript-form form :expecting :statement)))))