Logic transformations (and to && etc.)

4 views
Skip to first unread message

Juho Vepsäläinen

unread,
May 18, 2011, 3:51:44 AM5/18/11
to jssh...@googlegroups.com
Hi,

I'm currently trying to "Pythonify" JS a bit as you probably guessed from the op-overloading thinger. I would love to replace logic ops (&& and || for now) with plain ol' English. It reads better and it's nicer to write.

My first go at it went pretty much like op-overloading. I came by an issue, though. It seems Shaper.parseExpression accepts only ~valid~ JavaScript. This is kind of sensible since it uses Narcissus as backend...

Is there some simple way to work around this issue? I think providing support for custom transformations like this could be highly interesting!

--
Juho

Olov Lassus

unread,
May 18, 2011, 4:40:37 AM5/18/11
to jssh...@googlegroups.com
18 maj 2011 kl. 09.51 skrev Juho Vepsäläinen:

> My first go at it went pretty much like op-overloading. I came by an issue, though. It seems Shaper.parseExpression accepts only ~valid~ JavaScript. This is kind of sensible since it uses Narcissus as backend...

Shaper is an extensible framework for JavaScript syntax tree shaping, thus it requires well formed JavaScript. It is possible to add extra info to the syntax tree by annotations (as done in bitwiser) and it's also possible to change the semantics (as done in restricter), but you cannot change the syntax of the input language.

/Olov

Juho Vepsäläinen

unread,
May 18, 2011, 6:20:24 AM5/18/11
to jssh...@googlegroups.com
Hi,
I just tried stabbing Narcissus' jsdefs.js a bit by adding "and" and "or" defs there. Now my plugin seems to work as expected. :)

Do you think it would be feasible to make it possible to do this kind of stuff dynamically via JSShaper API? No idea if that's easy or anything... It just happens to be a really cool possibility even though you stated that the project's main goal is to provide JS to JS kind of transformations.
 
--
Juho

/Olov

Olov Lassus

unread,
May 18, 2011, 6:47:41 AM5/18/11
to jssh...@googlegroups.com
18 maj 2011 kl. 12.20 skrev Juho Vepsäläinen:

> Do you think it would be feasible to make it possible to do this kind of stuff dynamically via JSShaper API? No idea if that's easy or anything... It just happens to be a really cool possibility even though you stated that the project's main goal is to provide JS to JS kind of transformations.

It would bring in an awful lot of complexity and would require making the JS lexer and parser pluggable. I can see how it could be useful for some, but it's not a direction I plan to pursue with Shaper. If you want to create a compiler for a new language (targeting JS), starting out from scratch syntax-wise might be something to consider, like CoffeeScript did.

/Olov

Juho Vepsäläinen

unread,
May 18, 2011, 7:11:54 AM5/18/11
to jssh...@googlegroups.com
Gotcha! Thanks. :)

--
Juho 
Reply all
Reply to author
Forward
0 new messages