-(in-package :parenscript)
-
-(defun compile-script (script-form &key (output-stream nil))
- "Compiles the Parenscript form SCRIPT-FORM into Javascript.
-Non-null PRETTY-PRINT values result in a pretty-printed output code.
-If OUTPUT-STREAM is NIL, then the result is a string; otherwise code
-is output to the OUTPUT-STREAM stream."
- (parenscript-print (compile-parenscript-form script-form) output-stream))
-
-(defmacro ps (&body body)
- "A macro that returns a Javascript string of the supplied Parenscript forms."
- `(ps* '(progn ,@body)))
-
-(defun ps* (&rest body)
- "Return the javascript string representing BODY.
-Body is evaluated."
- (compile-script `(progn ,@body)))
-
-(defun ps-inline* (form)
- (concatenate 'string
- "javascript:"
- (remove #\Newline
- (parenscript-print (compile-parenscript-form form :expecting :statement))
- :from-end t)))
-
-(defmacro ps-inline (&body body)
- `(ps-inline* '(progn ,@body)))
+(in-package :parenscript)
+
+(defmacro ps (&body body)
+ "Given Parenscript forms (an implicit progn), compiles those forms
+to a JavaScript string at macro-expansion time."
+ `(concatenate 'string ,@(parenscript-print (compile-parenscript-form `(progn ,@body) :expecting :statement))))
+
+(defmacro ps-doc (&body body)
+ "Expands Parenscript forms in a clean environment."
+ (let ((*ps-gensym-counter* 0)
+ (*ps-special-variables* nil))
+ (macroexpand-1 `(ps ,@body))))
+
+(defun ps-doc* (ps-form)
+ (let ((*ps-gensym-counter* 0)
+ (*ps-special-variables* nil))
+ (ps1* ps-form)))
+
+(defun ps1* (ps-form)
+ (with-output-to-string (s)
+ (mapc (lambda (x)
+ (princ (if (stringp x)
+ x
+ (eval x))
+ s))
+ (parenscript-print (compile-parenscript-form ps-form :expecting :statement)))))
+
+(defun ps* (&rest body)
+ "Compiles BODY to a JavaScript string.
+Body is evaluated."
+ (ps1* `(progn ,@body)))
+
+(defvar *js-inline-string-delimiter* #\"
+ "Controls the string delimiter char used when compiling Parenscript in ps-inline.")
+
+(defun ps-inline* (form &optional (*js-string-delimiter* *js-inline-string-delimiter*))
+ (concatenate 'string "javascript:" (ps1* form)))
+
+(defmacro/ps ps-inline (form &optional (string-delimiter *js-inline-string-delimiter*))
+ `(concatenate 'string "javascript:"
+ ,@(let ((*js-string-delimiter* string-delimiter))
+ (parenscript-print (compile-parenscript-form form :expecting :statement)))))