Added William Halliburton <whalliburton@gmail.com>'s tracing macro to extras folder.
[clinton/parenscript.git] / src / compilation-interface.lisp
1 (in-package :parenscript)
2
3 (defun compile-script (ps-form &key (output-stream nil))
4 "Compiles the Parenscript form PS-FORM into Javascript.
5 If OUTPUT-STREAM is NIL, then the result is a string; otherwise code
6 is output to the OUTPUT-STREAM stream."
7 (parenscript-print (compile-parenscript-form ps-form :expecting :statement) output-stream))
8
9 (defmacro ps (&body body)
10 "Given Parenscript forms (an implicit progn), expands to code which
11 compiles those forms to a JavaScript string."
12 `(ps* '(progn ,@body)))
13
14 (defmacro ps-doc (&body body)
15 "Expands Parenscript forms in a clean environment."
16 `(let ((*ps-gensym-counter* 0)
17 (*ps-special-variables* nil))
18 (ps ,@body)))
19
20 (defun ps* (&rest body)
21 "Compiles BODY to a JavaScript string.
22 Body is evaluated."
23 (compile-script `(progn ,@body)))
24
25 (defvar *js-inline-string-delimiter* #\"
26 "Controls the string delimiter char used when compiling Parenscript in ps-inline.")
27
28 (defun ps-inline* (form &optional (*js-string-delimiter* *js-inline-string-delimiter*))
29 (concatenate 'string
30 "javascript:"
31 (parenscript-print (compile-parenscript-form form :expecting :statement))))
32
33 (defmacro ps-inline (form &optional (string-delimiter '*js-inline-string-delimiter*))
34 `(ps-inline* ',form ,string-delimiter))