From: Albert C. <sap...@gm...> - 2020-12-02 16:34:54
|
Hi Jeff, Thank you, this is helpful, lots to study. What I am after is the ability to collect, for an arbitrary point in a jython text file, the list of available variables within scope (aka locals and globals), without executing the code. I had found the ParserFacade class in the jython jar which allowed me to do e.g. browse the body (a list) of the script, with Assign, FunctionDef and ImportFrom blocks, with the FunctionDef having another, nested body, and so on: https://github.com/acardona/scripts/blob/master/python/imagej/jython/parse_code.py The ultimate goal is to be able to provide autocompletions for variables within scope, and for functions of imported modules as well. So far, I implemented autocompletions for java classes and static methods, plus automatic insertions of the corresponding import statements for java classes, which is a start. (As part of Fiji's Script Editor https://github.com/scijava/script-editor/ ; there;s a video of its control+space expansions from an RSyntaxArea here: https://mobile.twitter.com/albertcardona/status/1333442919622127616 ). Best, Albert Missatge de Jeff Allen <ja...@fa...> del dia dt., 1 de des. 2020 a les 20:15: > > Hi Albert. > > Depends what you mean by "Jython code", but assuming it is Python source (with the few Jython quirks we need), then there's the ast module. There's a layer (_ast) generated by our ANTLR-based parser, and then the AST module sits on top to civilise it. It relies on the same classes we use in parsing to compile. > > The documentation from python.org is not that great (or wasn't at 2.7) for the ast module, and I found this useful: https://greentreesnakes.readthedocs.io/en/latest/ when I was playing with the AST. > > Jeff > > Jeff Allen > > On 30/11/2020 11:57, Albert Cardona wrote: > > Hi all, > I assume there must be classes in the repos for parsing Jython code into an AST or similar representation, from which I could get a list of local and global variables and their properties available at a specific code block or script line. > Would very much appreciate pointers. > Best, > Albert > > _______________________________________________ > Jython-dev mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-dev |