Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » Unparsing Ruby/Python/Whatever(Something like toString() on JDT)
Unparsing Ruby/Python/Whatever [message #1222445] Fri, 20 December 2013 12:44
Alexandre Torres is currently offline Alexandre TorresFriend
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

Previous Topic:DLTKCore and the AST of expressions and statements
Next Topic:Java/Javascript Debugging in DLTK1.0?
Goto Forum:
  


Current Time: Mon Dec 22 02:13:46 GMT 2014

Powered by FUDForum. Page generated in 0.01349 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software