The easiest way is to derive a new class from AstWalker or
AstWalkerNonRecursive, override the nodes you care about (or all of them, or
implement the interface on your own class), and then do the stmt.Walk(walker)
as you have. For example:
class MyWalker : AstWalker {
public override bool Walk(ExpressionStatement exprStmt) {
TreeNode node = new TreeNode();
node.Tag = exprStmt;
treeView.Nodes.Add(node);
return false;
}
}
Do that for every node type and you'll add all the top level nodes (the false
prevents us from walking the node further which would add lower level nodes
into the top-level). When the user expands a node you can walk the Tag and
then fill in the tree view (or you can return true and fill the entire tree
view at once by maintaining where you are in the hierarchy).
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christian Schmidt
Sent: Monday, August 14, 2006 6:32 AM
To: [email protected]
Subject: [IronPython] Usage of Parser.FromString
Hi,
I'm trying to fill a treeview with the statements found in a embedded python
script. How do I traverse through the tree of parsed statements?
using IronPython;
using IronPython.Compiler;
using IronPython.Compiler.Ast;
void doparse(string txt) {
SystemState ss = new SystemState(engineOptions);
CompilerContext cc = new CompilerContext();
Parser parser = Parser.FromString (ss, cc, txt);
Statement stmt = parser.ParseFileInput();
IAstWalker walker = MyWalker();
stmt.Walk(walker);
}
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com