APM: parsing javascript

Sam Foster austin.pm at sam-i-am.com
Wed Oct 25 20:25:05 PDT 2006


quick update on this, apologies in advance as this became off topic as I 
researched it and found better non-perl solutions.
I found the code I needed - written in javascript and run via Rhino - it 
was already written and working in the dojo toolkit build system. (the 
same system I was trying to extend in the first place. doh)
http://archive.dojotoolkit.org/nightly/buildscripts/buildUtil.js

For a more general case, Narcissus seemed like what I would need:
http://lxr.mozilla.org/mozilla/source/js/narcissus/
Its a javascript parser (lexer) written in javascript - but I never got 
to trying it out.

Rhino and the javascript shell ( http://www.mozilla.org/rhino/shell.html 
) turn out to provide a preeety nice combo. I get all the good bits of 
java when I need them - I can just create a java class instance any time 
using e.g:
var al = new java.util.ArrayList()
.. but a dynamic language (that I happen to know pretty well already) 
for all the glue. This could spell trouble for the perl career I've not 
had yet.

Had I wanted to pursue the perl angle, I would probably have ported 
Narcissus over (its written by the same guy that wrote 
javascript/ecmascript.. so I figure he knows what he's doing), and maybe 
used the HOP::Lexer module (discussed/demonstrated in this article:  
http://www.perl.com/pub/a/2006/01/05/parsing.html?page=1) to simplify 
things a little.

Sam
--
Sam Foster wrote:

>hi all,
>I'm looking for a way to parse - but not execute - some javascript.
>I'm building up a dependency chain - my javascripts use a pair of 
>functions "provides" and "requires" to ensure pre-requisites are loaded 
>(these is using the dojo toolkit fwiw). I want to have perl follow this 
>chain, and in this case build a custom js library that concatenates all 
>the right files in the right order.
>I'm looking at the JavaScript.pm module, which I think uses the 
>SpiderMonkey interpreter. Mark I think mentioned a way to use jars from 
>within a perl program - that might let me use the Rhino interpreter - 
>what was that Mark?
>
>As I'm not trying to parse all possible javascript  but just a couple 
>statements, I could just do this myself I suppose. Does this kind of 
>thing exist elsewhere though. Seems like it might.
>
>thanks,
>Sam
>


More information about the Austin mailing list