[parenscript-devel] Parlez-vous ActionScript?

Red Daly reddaly at gmail.com
Mon Jun 25 19:07:23 UTC 2007

The process of adding new compiler macros to the current Parenscript to
support Javascript 2.0 is very easy.  See the example later in the email.
However, the tricky design issue is how to disallow Javascript
2.0generation when you only want ECMAScript 2 syntax.  As the compiler
more sophisticated, this option flag may have more ramifications (because of
semantic analysis).  I do not foresee any grave problems, however, and am in
favor of adding support for Javascript 2 so long as it can be disabled.

On 6/24/07, John Pallister <john at synchromesh.com> wrote:
> ...
The point is, ECMAScript 4 has a variety of new features (optional static
> typing, classes, interfaces, packages, generators, list comprehensions
> etc. -
> there's a nice overview at [3]) which aren't currently supported by
> ParenScript.
> Given that the adoption of ECMAScript 4/JavaScript 2 is a case of when
> rather
> than if [4], it would be great if any overhaul of ParenScript could be
> done with
> an eye to incorporating some or all of these features in the near future
> (hopefully by other interested parties such as myself).

While a adoption of new technology is inevitable, it is not instantaneous.
For most people, it will be a few years before they can fully embrace the
new version of Javascript.

The "add a compiler" POV vs. the "keep it simple" perspective echoes the two
> sides of the JavaScript 2 debate. Since these new language features will
> be
> added (and I'm already using them in ActionScript 3), it would be great if
> they
> could be added to ParenScript without causing too much inconvenience to
> those
> who like it the way it is now.
> I would like to help out with this task; I might have some time to spend
> on it
> later in the year.

I will provide some instruction for those who want to modify the behavior of
the Parenscript compiler in a basic way.  Here is an example of how to add a
macro `(js-literal string)' for including Javascript literals directly in
Parenscript.  It should elucidate the process of basic modification of the
Parenscript compiler:

;;; Define the AST node
(defjsclass js-literal-statement (statement)
  ((text :accessor js-literal-text :initarg :text))
  (:documentation "An opaque Javascript literal"))

;;; Define the macro to include such a kludge in your code
(define-js-compiler-macro js-literal (js-string)
  (make-instance 'js-literal-statement
      :text js-string))

;;; Define the translation function for compiling to javascript
(defmethod js-to-strings ((statement js-literal-statement) start-pos)
  (declare (ignore start-pos)
           (inline lisp-special-char-to-js))
  (list (js-literal-text statement)))

If I'm not mistaken, you can now include Javascript with the Parenscript
form (js-literal "...").  so (js-literal "class Greeter { var saying =
'hello, world'; }") emits "class Greater ..." in the Javascript source

> John :^P


[3] http://developer.mozilla.org/presentations/xtech2006/javascript/
> [4] http://www.mozilla.org/projects/tamarin/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20070625/abb478d5/attachment.html>

More information about the parenscript-devel mailing list