Not sure where a good place to start is. They're no different than ASTs for
any other language. uglify-js dumps out a big nested array which is a
pretty good start if you want to see about what is going on.

I got started in meta-programming with Bison which is a C parser and Flex
which is a C scanner. (I mean, they don't parse and scan C, they are
general purpose parsers which happen to be written in C). Basically you
just take a source file and run it through a scanner which turns it into a
bunch of "tokens" which are just one step up from raw source (parse
something like "var hello = 1" into [t_VAR', 'hello', t_EQ, 1]), and then
the parser takes those tokens and turns them into a meaningful tree.

On Thu, Aug 30, 2012 at 2:23 PM, Dan Milon <danmi...@gmail.com> wrote:

> Out of topic, but you gave me the clues.
> Do you know where i can read up about AST trees for javascript?
>
> Thanks a ton,
> danmilon.
>
>
> On 08/30/2012 12:27 AM, Marcel Laverdet wrote:
>
>> Just curious why you need the comments in the AST at all? If you've got
>> the start position & length of every token in the AST (much easier to do)
>> you implicitly have the comments as well. The "fiber" engine in Streamline (
>> https://github.com/Sage/**streamlinejs/blob/master/lib/**
>> fibers/transform.js<https://github.com/Sage/streamlinejs/blob/master/lib/fibers/transform.js>)
>> does this with really good results.
>>
>> On Wed, Aug 29, 2012 at 8:37 AM, Mihai Călin Bazon 
>> <mihai.ba...@gmail.com<mailto:
>> mihai.ba...@gmail.com>**> wrote:
>>
>>     Well, the code generator doesn't yet have an option to keep comments,
>>     but I can add it easily; the harder part was having them in the AST,
>>     and that's done.
>>
>>     What exactly are you trying to achieve?  My understanding is that you
>>     compile Lisp to JS (cool!), do you want to be able to do the reverse
>>     transform?  If so, perhaps a better idea is to generate a source map.
>>     (not sure what you need to do though, just guessing)
>>
>>     Cheers,
>>     -Mihai
>>
>>     On Wed, Aug 29, 2012 at 1:52 PM, Scott Taylor
>>     <sc...@railsnewbie.com <mailto:sc...@railsnewbie.com>**> wrote:
>>     > Wonderful!  I've been working on a project that is sort of like
>>     parenscript
>>     > - but much more of a straight javascript in lisp/scheme clothes
>>     with a
>>     > define-syntax macro system.
>>     >
>>     > 
>> https://github.com/**smtlaissezfaire/loop<https://github.com/smtlaissezfaire/loop>
>>     >
>>     > I've been hacking on the 1x source of uglify to translate
>>     javascript into a
>>     > lispy type system (and back) - but inline comments have been a
>>     cause of
>>     > concern.  Where is the 2.x source at this point?
>>     >
>>     > Cheers,
>>     >
>>     > Scott
>>     >
>>     > On Aug 28, 2012, at 12:56 PM, Mihai Călin Bazon wrote:
>>     >
>>     > On Tue, Aug 28, 2012 at 5:33 AM, Scott Taylor
>>     <sc...@railsnewbie.com <mailto:sc...@railsnewbie.com>**> wrote:
>>     >
>>     > Very cool.  What comments in the AST are you going to preserve?
>>     >
>>     >
>>     > The new AST is able to store all comments, and the compressor
>>     and code
>>     > generator will be able to keep most of them.  However, I suspect
>>     that
>>     > in general people will only need to store copyright notices, and
>>     those
>>     > usually start with some special marker like "/*!".  It'll be easy to
>>     > add a configuration option to keep such comments, as long as they're
>>     > not in code that's going to be dropped (for example dead code, like,
>>     > code that follows a return, throw, break or continue statement).
>>     >
>>     > Cheers,
>>     > --
>>     > Mihai Bazon,
>>     > http://mihai.bazon.net/blog
>>     >
>>     > --
>>     > Job Board: http://jobs.nodejs.org/
>>     > Posting guidelines:
>>     > https://github.com/joyent/**node/wiki/Mailing-List-**
>> Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines>
>>     > You received this message because you are subscribed to the Google
>>     > Groups "nodejs" group.
>>     > To post to this group, send email to nodejs@googlegroups.com
>>     <mailto:nodejs@googlegroups.**com <nodejs@googlegroups.com>>
>>
>>     > To unsubscribe from this group, send email to
>>     > 
>> nodejs+unsubscribe@**googlegroups.com<nodejs%2bunsubscr...@googlegroups.com>
>>     
>> <mailto:nodejs%2Bunsubscribe@**googlegroups.com<nodejs%252bunsubscr...@googlegroups.com>
>> >
>>
>>     > For more options, visit this group at
>>     > 
>> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>>     >
>>     >
>>     > --
>>     > Job Board: http://jobs.nodejs.org/
>>     > Posting guidelines:
>>     > https://github.com/joyent/**node/wiki/Mailing-List-**
>> Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines>
>>     > You received this message because you are subscribed to the Google
>>     > Groups "nodejs" group.
>>     > To post to this group, send email to nodejs@googlegroups.com
>>     <mailto:nodejs@googlegroups.**com <nodejs@googlegroups.com>>
>>
>>     > To unsubscribe from this group, send email to
>>     > 
>> nodejs+unsubscribe@**googlegroups.com<nodejs%2bunsubscr...@googlegroups.com>
>>     
>> <mailto:nodejs%2Bunsubscribe@**googlegroups.com<nodejs%252bunsubscr...@googlegroups.com>
>> >
>>
>>     > For more options, visit this group at
>>     > 
>> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>>
>>
>>
>>     --
>>     Mihai Bazon,
>>     http://mihai.bazon.net/blog
>>
>>     --
>>     Job Board: http://jobs.nodejs.org/
>>     Posting guidelines:
>>     https://github.com/joyent/**node/wiki/Mailing-List-**
>> Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines>
>>     You received this message because you are subscribed to the Google
>>     Groups "nodejs" group.
>>     To post to this group, send email to nodejs@googlegroups.com
>>     <mailto:nodejs@googlegroups.**com <nodejs@googlegroups.com>>
>>
>>     To unsubscribe from this group, send email to
>>     
>> nodejs+unsubscribe@**googlegroups.com<nodejs%2bunsubscr...@googlegroups.com>
>>     
>> <mailto:nodejs%2Bunsubscribe@**googlegroups.com<nodejs%252bunsubscr...@googlegroups.com>
>> >
>>
>>     For more options, visit this group at
>>     
>> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>>
>>
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines: https://github.com/joyent/**node/wiki/Mailing-List-**
>> Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines>
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to nodejs@googlegroups.com
>> To unsubscribe from this group, send email to
>> nodejs+unsubscribe@**googlegroups.com<nodejs%2bunsubscr...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/**node/wiki/Mailing-List-**
> Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines>
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscribe@**googlegroups.com<nodejs%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to