On 27 September 2011 13:23, Tarek Ziadé <[email protected]> wrote:
> On Tue, Sep 27, 2011 at 2:18 PM, David Beazley <[email protected]> wrote: > > I think you just do a depth-first traversal of the parse tree. For > example something sort of like this (shown for a node representing a binary > operator): > > > > class BinaryOperator(object): > > def __init__(self, operator, left, right): > > self.operator = operator > > self.left = left > > self.right = right > > def collapse(self): > > return self.left.collapse() + self.operator + > self.right.collapse() > > > > Note: You'll need to careful about too much recursion depending on the > depth of your parse tree. > > Thanks, that's useful > You may want your grammar to preserve whitespace in the tokens (rather than discarding) - unless you're happy to lose / change whitespace when round tripping. Michael > > Cheers > Tarek > -- > Tarek Ziadé | http://ziade.org > > -- > You received this message because you are subscribed to the Google Groups > "ply-hack" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/ply-hack?hl=en. > > -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html -- You received this message because you are subscribed to the Google Groups "ply-hack" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/ply-hack?hl=en.
