Strawman of DSL support for JS

4 views
Skip to first unread message

Mike Samuel

unread,
Dec 14, 2009, 5:50:27 PM12/14/09
to Flapjax
There's a strawman proposal for DSL support in EcmaScript at
http://wiki.ecmascript.org/lib/exe/fetch.php?id=strawman%3Aquasis&cache=cache&media=strawman:quasi-strawman.html

I'd love to get thoughts from Flapjaxers since I'm sure many of you
have thought a lot about DSLs in Javascript and how to generate and
manipulate content in other languages from JS.

cheers,
mike

Arjun Guha

unread,
Dec 15, 2009, 11:34:24 AM12/15/09
to fla...@googlegroups.com
It would be nice if we could write the Flapjax compiler as a DSL in
JavaScript. That would eliminate the external compilation step.
However, I don't think this would help.

The Flapjax compiler performs rewrites on JavaScript abstract syntax.
It does not do string manipulation, which is what this proposal is
about. I suppose it could manipulate strings of source-code and
eval---but we are not going to admit eval.

It would be nice to have a motivating example for JavaScript DSLs, but
the Flapjax compiler is too involved. I think finite-state machines
are the simplest, silliest example of DSLs. Here's how they're done
in Scheme:

http://www.cs.brown.edu/~sk/Publications/Papers/Published/sk-automata-macros/

It should be possible to account for that.

Arjun

Mike Samuel

unread,
Dec 15, 2009, 2:23:32 PM12/15/09
to fla...@googlegroups.com
2009/12/15 Arjun Guha <arjun...@gmail.com>:
> It would be nice if we could write the Flapjax compiler as a DSL in
> JavaScript.  That would eliminate the external compilation step.
> However, I don't think this would help.
>
> The Flapjax compiler performs rewrites on JavaScript abstract syntax.
> It does not do string manipulation, which is what this proposal is
> about.  I suppose it could manipulate strings of source-code and
> eval---but we are not going to admit eval.

This proposal uses content generation (the actual result is
string-like, not a string) as a motivating example but I think it is
more widely applicable.

There are separate discussions about a JSON format for representing JS
ASTs and possible a way to turn those into a function body.

Flapjax doesn't wouldn't benefit from extending JS syntax in ways that
this might enable?

> It would be nice to have a motivating example for JavaScript DSLs, but
> the Flapjax compiler is too involved.  I think finite-state machines
> are the simplest, silliest example of DSLs.  Here's how they're done
> in Scheme:
>
> http://www.cs.brown.edu/~sk/Publications/Papers/Published/sk-automata-macros/

I like the criteria laid out there. I think binding is a weakness
since, security constraints mean that we don't want to allow
introducing bindings not named, and left-hand-sides are not first
class in JS. There are proposals for multi assignment desugaring
though which could mitigate this somewhat.

> It should be possible to account for that.
>
> Arjun
>
> --
> Flapjax home page: www.flapjax-lang.org
> Flapjax list: groups.google.com/group/flapjax
> Post: fla...@googlegroups.com
> Unsubscribe: flapjax-u...@googlegroups.com

Arjun Guha

unread,
Dec 17, 2009, 11:34:07 AM12/17/09
to fla...@googlegroups.com
> There are separate discussions about a JSON format for representing JS
> ASTs and possible a way to turn those into a function body.
>
> Flapjax doesn't wouldn't benefit from extending JS syntax in ways that
> this might enable?

That would help. Once the AST is in place, the Flapjax compiler is
really lightweight. The core is about 500 lines of Haskell--mostly
dumb recursive cases that could be handled generically.

Arjun

Artyom Shalkhakov

unread,
Dec 19, 2009, 8:40:23 AM12/19/09
to fla...@googlegroups.com
Hello Arjun,

2009/12/17 Arjun Guha <arjun...@gmail.com>:

Could you show the code? Just curious.

Cheers,
Artyom Shalkhakov.

Arjun Guha

unread,
Dec 19, 2009, 9:50:27 AM12/19/09
to fla...@googlegroups.com
>> That would help.  Once the AST is in place, the Flapjax compiler is
>> really lightweight.  The core is about 500 lines of Haskell--mostly
>> dumb recursive cases that could be handled generically.
>
> Could you show the code? Just curious.

This is the compiler:

http://github.com/arjunguha/flapjax/blob/master/compiler/src/Flapjax/Compiler.hs

Arjun

Mike Samuel

unread,
Jan 10, 2010, 4:34:51 PM1/10/10
to fla...@googlegroups.com
There is an alternate semantics at
http://wiki.ecmascript.org/doku.php?id=strawman:quasis-alt that
attempts to repair the originals failure to extend to new flow control
constructs, allow for efficient compilation, and allow for
substitutions to be assigned to.


2009/12/15 Mike Samuel <mikes...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages