javascript: A s-exp syntax for Javascript
_javascript: A s-exp syntax for Javascript_
============================
Jay McCarthy <jay.mccarthy@gmail.com>
Keywords: _dev_, _lang_, _web_
Introduction
=========
A nice way of constructing JavaScript ASTs and code in Scheme.
Uses dherman/javascript.plt for ASTs, parsing, and pretty-printing.
FILES
====
_javascript.ss_
-------------
Require it like this:
> (require (planet "javascript.ss" ("jaymccarthy" "javascript.plt" 1)))
It provides the follow identifiers:
> js : (syntax javascript-sexp?) -> (syntax string?)
> javascript : (syntax javascript-sexp?) -> (syntax javascript?)
> javascript-marshal : marshallable? -> javascript?
> javascript-unmarshal : javascript? -> marshallable?
> javascript->string : javascript? -> string?
> string->javascript : string? -> javascript?
The following things are _marshallable?_:
* (hash-table marshallable? marshallable?)
* (alist marshallable? marsallable?)
* (list marshallable?)
* (vector marshallable?)
* boolean?
* void?
* number?
* string?
Hash-tables and alists become JS objects. Vectors and lists become JS
arrays. Everything else becomes what it is.
The JavaScript S-exp AST:
I : identifier?
P = I
| STRING
| NUMBER
D = (define (I I ...) SE ...)
| (define I)
| (define I E)
| UNQUOTE
L = STRING
| NUMBER
| BOOLEAN
| VOID
| (regexp STRING BOOL BOOL)
| (regexp STRING)
| (array E ...)
| (object [P E] ...)
R = (this)
| X
| (dot E I ...)
E = L
| R
| (new E E ...)
| (E <postfix>)
| (<prefix> E)
| (<infix> E E)
| (if E E E)
| (<assignment> E E)
| (lambda (I ...) SE ...)
| (lambda I (I ...) SE ...)
| (E E ...)
| UNQUOTE
S = (begin S ...)
| (ignore E)
| (if E S)
| (if E S S)
| (do S while E)
| (while E S)
| (for E (and E ...) E S)
| (for (E in E) S)
| (continue)
| (continue I)
| (break)
| (break I)
| (return)
| (return E)
| (with E S)
| (switch E CASE ...)
| (I : S)
| (throw E)
| (try S CATCH ...)
| (try S CATCH ... (finally S))
| UNQUOTE
CASE = (case S ...)
| (case E S ...)
CATCH = (catch I S)
SE = S
| D
UNQUOTE = ,marshalable?
| #,javascript?
Example
======
(printf "~a~n"
(js
(ignore
((dot YAHOO util Connect asyncRequest)
"GET"
#,(make-StringLiteral #f "URL")
(make_callback ,"Activity" ,"Day")))))
==>
YAHOO.util.Connect.asyncRequest("GET", "URL", make_callback("Activity", "Day"));
History
======
June 23rd, 2006
* Initial