[metaas-dev] parse tree manipulation

David Holroyd dave at badgers-in-foil.co.uk
Sun Aug 19 23:49:30 UTC 2007


Hey Leo,

Do you still need a proper dupTree() implementation?


On Wed, Jul 25, 2007 at 10:33:49AM -0700, Leo Meyerovich wrote:
> >I'm not familiar with CPS transforms; what are they good for?  Are you
> >adding tail-call optimisation to AS3 or something like that?
> 
> 
> Yes, or user-level threading, etc (see narrative js).
> 
> FYI, I did make a start at exposing expression-level stuff in the
> >hand-crafted DOM interfaces (there should be some of this in Subversion)
> >but lately I've been spending most of my hack-time on projects built on
> >top of metaas, rather than on metaas itself.
> 
> 
> Any tips at what to look at? My basic, exact scenario is that I want to add
> some function applications throughout expressions, like
> 
> a * b + 3 => f(plus, f(time, a, b), 3)
> 
> I would have done it at the antlr level, but I want to do some optimizations
> and deal with shadowed variables etc in special ways.
> 
> 
> >Yep.  Support for this is simply not implemented yet.  LinkedListTree
> >probably needs to supply its own implementation of dupTree() to
> >duplicate all the subclass-specific state.  The fiddly bit will be
> >duplicating the relevant sub-segment of the token-linked-list, and then
> >assigning the correct start/stop tokens in the duplicate tree nodes.
> 
> 
> Yeah, as I've slowly realized what's going on underneath :)
> 
> In the cases where the manipulation doesn't fail, does the code look
> >'sane' when serialised back to text again?  If you're using dupTree() I
> >would expect it to be quite broken.
> 
> 
> Most of the time (if I encounter them again, I'll let you know).
> 
> So, it would be really helpful if you could send some simplified
> >unit tests that demonstrate these problems.  I can then work to make the
> >tests pass.
> 
> 
> When I encounter more, I'll try.
> 
> For anyone else on the list, what I ended up doing for particularly hairy
> bits of my visitor so far is writing a function astToString, and writing the
> ast I wanted the subtree to be transformed into as a string with the
> original subtree being transformed using that function. I'd then run the
> string through the fragment parser and return the generated ast for
> reinsertion (which needs lots of testing). The main trick is writing
> astToString (reuse the tree printer internals, except you need to
> temporarily disconnect a subtree from a parent if it is connected to get the
> tokens right, and swap it back in after - I checked if the parent =
> parent.parent, and swapped in a dummy node temporarily if so in order to not
> disturb tokens).
> 
> - Leo

> _______________________________________________
> metaas-dev mailing list
> metaas-dev at lists.badgers-in-foil.co.uk
> http://lists.badgers-in-foil.co.uk/mailman/listinfo/metaas-dev


-- 
http://david.holroyd.me.uk/



More information about the metaas-dev mailing list