[Pydev-code] Fwd: Viewing ASTs in PyDev
Brought to you by:
fabioz
|
From: Neil <nei...@ut...> - 2007-05-03 23:24:23
|
Hi Fabio, I'm following along with the mailing list advice stated here: http://www.nabble.com/PyDev-Extension-Points-Quick-Fix-%28copied-from-pydev-forum%29-tf503666.html#a1365501 where you advise extending from pydev_builder to walk the AST. However, I'm new to Eclipse plugin programming so I wonder if you could be a bit more specific. Currently my plugin does something like: public class PyGoal extends PyDevBuilderVisitor { SourceModule sm = (SourceModule) getSourceModule(resource, document, nature); SimpleNode sn = sm.getAst(); EasyASTIteratorVisitor vis = new EasyASTIteratorVisitor(); try{ sn.accept(vis); } catch(Exception e) {} } What I'd like to do is create a simplified syntax tree structure that just stores functions, variables, control structures, and calls. I'd then do various specific things to that tree for my own plugin. Can you illustrate how I would visit a particular document's AST, putting the elements of interest in my own data structure? How do I tell the PyDevBuilderVisitor what document/resource I'm working with? thanks neil ernst On 4/25/07, Neil Ernst <ne...@cs...> wrote: > I think it would look something like the JDT AST viewer plugin: > http://www.eclipse.org/articles/Article-JavaCodeManipulation_AST/index.html > > I think I should probably create a separate plugin project that calls > on PyDev to do the actual AST generation, then load that into my > plugin. > > thanks for the advice > neil > > On 4/25/07, Ueli Kistler <uki...@hs...> wrote: > > Hi, > > > > i would not recommend using JGraph as I did... it would make more sense > > to extend the current outline view or provide a new "outline"-like view > > (i think there can be only one "true" outline view actually because its > > bound to an editor implementation? Not sure about this..) > > > > This could of course be done in a separate project... it would require > > similiar dependencies from PyDev as PEPTIC. > > > > Cheers, > > Ueli > > > > -- > > > > > > > > > > > > Fabio Zadrozny wrote: > > > > My first challenge is to view the ASTs for the entire project (I'm > > > > looking at the Trac source code). I notice in your code you have a > > > > class for viewing the AST using JGraph. Would you be able to point me > > > > to a way to have this done in PyDev? I've been exploring the Jython > > > > scripting elements of PyDev but I can't get your viewer to start that > > > > way. > > > > > > The viewer that uses JGraph is not bundled in the pydev distribution > > > and thus cannot be accessed with the scripting... If you have the > > > source code, you can change those files from the 'contrib' source > > > folder to the actual 'src' source folder so that they can be accessed > > > (and add the related jars as dependencies for the plugin... or maybe a > > > better idea would be creating another plugin to hold those things, > > > which you can use and extend with your own code). > > > > > > Also, I think I would need more info on what you actually want to > > > access to help you better... > > > > > > Cheers, > > > > > > Fabio > > > > > -- Neil A. Ernst Ph.D. Candidate University of Toronto http://neilernst.net |