Unparsing Ruby/Python/Whatever [message #1222445] |
Fri, 20 December 2013 12:44 |
Alexandre Torres Messages: 139 Registered: July 2009 |
Senior Member |
|
|
Hi,
I´m wondering if the DLTK plugin has an unparser already implemented for each module (dltk.ruby, dltk.python, ...). What I mean is, if I change some ASTnode, for instance aiming refactoring code, how can I regenerate my code?
Using JDT, a simple toString() call will yield the Node's Java representation, with correct syntax. But using DLTK, the toString will deliver just a list of elements.
I suppose there may be some ASTVisitor implementation that rebuilds the code.
Example
ISourceModule im = (ISourceModule) DLTKCore.create(file);
ModuleDeclaration moddecl = SourceParserUtil.getModuleDeclaration(im);
for (TypeDeclaration type:moddecl.getTypes()) {
type.setName(capitalize(type.getName()));
}
System.out.println("code:"+moddecl); // This will produce garbage
System.out.println("code2:"+im.getSource()); // This will produce the original code
the result of toString will be something like:
Module[0..67]:{
Type[0..67][6..10]:Unit([ColonExpression[13..31]:{
ActiveRecord([13..25]) Base
}] ){
...
using JDT I could do the same thing and have my code back:
CompilationUnit unit = ...
// do the capitalization stuff ...
System.out.println("code:"+unit); // nice code
And JDT also has a nice CodeFormatter if I want to make the code readble.
What about DLTK ruby/python?
Do I have to implement my own visitor to unparse the AST?
Sorry if this question was already answered somewhere (I did not find it).
Thanks.
EDIT: Just found out the formatter... IScriptFormatterFactory formatterFactory = ScriptFormatterManager.getSelected(project);
Some documentation would help a lot!
[Updated on: Fri, 20 December 2013 13:34] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.65945 seconds