I am happy with my DSL, I can yacc.parse() it it and create an AST in memory.
I am now trying to add a feature where, for a given AST, I can
generate the corresponding portion of DSL.
The AST I've created in memory is a simple tuple for every expression
I am visiting, and I was wondering what is the best way to do the
revert operation.
The problem I am facing is that I don't want to maintain on one side a
grammar to parse my DSL, and on the other side a function to parse the
AST and do the revert operation.
I was wondering how this is usually solved, or if PLY provides some
helpers for this
Thanks
Tarek
--
Tarek Ziadé | http://ziade.org
Thanks
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 ply-...@googlegroups.com.
To unsubscribe from this group, send email to ply-hack+u...@googlegroups.com.
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
That sounds like the best idea. I'll try this.
Do you happen to have a public example ?
Cheers
--
Tarek Ziadé | http://ziade.org
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.
Cheers,
Dave
Thanks, that's useful
Cheers
Cheers
--
You received this message because you are subscribed to the Google Groups "ply-hack" group.
To post to this group, send email to ply-...@googlegroups.com.
To unsubscribe from this group, send email to ply-hack+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ply-hack?hl=en.
Yeah ideally I'd like the round trip to look similar, including the
level indentation.
The use case is a web editor where you can change pieces of an already
loaded AST, and have the DSL rendered back and forth.
If the first sync changes the initial text after the first
tokenization, it's fine I guess.
--
Tarek Ziadé | http://ziade.org