More refactorings to the printer, exported symbols that control printer behavior.
[clinton/parenscript.git] / src / compilation-interface.lisp
1 (in-package :parenscript)
2
3 (defun compile-script (script-form &key (output-stream nil))
4 "Compiles the Parenscript form SCRIPT-FORM into Javascript.
5 Non-null PRETTY-PRINT values result in a pretty-printed output code.
6 If OUTPUT-STREAM is NIL, then the result is a string; otherwise code
7 is output to the OUTPUT-STREAM stream."
8 (parenscript-print (compile-parenscript-form script-form :expecting :statement) output-stream))
9
10 (defmacro ps (&body body)
11 "Given Parenscript forms (an implicit progn), expands to code which
12 compiles those forms to a JavaScript string."
13 `(ps* '(progn ,@body)))
14
15 (defun ps* (&rest body)
16 "Compiles BODY to a JavaScript string.
17 Body is evaluated."
18 (compile-script `(progn ,@body)))
19
20 (defvar *js-inline-string-delimiter* #\"
21 "Controls the string delimiter char used when compiling Parenscript in ps-inline.")
22
23 (defun ps-inline* (form &optional (*js-string-delimiter* *js-inline-string-delimiter*))
24 (concatenate 'string
25 "javascript:"
26 (parenscript-print (compile-parenscript-form form :expecting :statement))))
27
28 (defmacro ps-inline (form &optional (string-delimiter '*js-inline-string-delimiter*))
29 `(ps-inline* ',form ,string-delimiter))