Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » XtendParser([Xtend] how to get an AST by parsing an .ext file)
XtendParser [message #540542] Wed, 16 June 2010 09:25 Go to next message
Macca1892 is currently offline Macca1892
Messages: 14
Registered: May 2010
Junior Member
There could be a larger oAW community here

Anyone knows how we can get an AST by parsing an .ext file by using XtendFacade? I can only see that we could get an ExtensionFile object. I have tried to parse an .ext file to get an ExtensionFile object but not successful yet

ExtensionFile f = ParseFacade.file(new StringReader(expression), fileName);

expression is a string but I don't understand what should I assign for it

Please help!
Re: XtendParser [message #540559 is a reply to message #540542] Wed, 16 June 2010 10:17 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

Use the XtendFacade, passing the path to the .ext file relative to the classpath.

If you have the ExtensionFile instance that's actually the AST.

You should consider looking into the Xtend test plugin for some sources.
CVS coordinates:
- dev.eclipse.org
- /cvsroot/modeling
- org.eclipse.m2t/org.eclipse.xpand/plugins/org.eclipse.xtend. tests

~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: XtendParser [message #540653 is a reply to message #540559] Wed, 16 June 2010 16:36 Go to previous messageGo to next message
Macca1892 is currently offline Macca1892
Messages: 14
Registered: May 2010
Junior Member
Thank you so much!

I have looked into org.eclipse.m2t/org.eclipse.xpand/plugins/org.eclipse.xtend. tests and there are many examples there

I tried one of them but now I have another problem with java.lang.NullPointerException at this point:
ec = (ExecutionContextImpl) ec.cloneWithResource(file);

I am quite sure that parse function works well because I can read some information from the instance of ExtensionFile. Thus I don't understand why NullPointerException is there Confused

Here is the test code:
ec = new ExecutionContextImpl();
ec.registerMetaModel(new JavaMetaModel("JavaMetaModel", new JavaBeansStrategy()));

final ExtensionFile file = parse(
"foo(String str) : 'String';" +
"foo(Integer int) : 'Int';" +
"foo(Void void) : 'void';");
ec = (ExecutionContextImpl) ec.cloneWithResource(file);
XtendFacade facade = XtendFacade.create(ec);
assertEquals("String",facade.call("foo", "String"));
assertEquals("Int",facade.call("foo", new Long(42)));
assertEquals("void",facade.call("foo", (Object) null));
Re: XtendParser [message #540727 is a reply to message #540542] Thu, 17 June 2010 04:06 Go to previous message
Macca1892 is currently offline Macca1892
Messages: 14
Registered: May 2010
Junior Member
sorry, my fault!
This code works well Smile
Previous Topic:[Acceleo] Syntax problems
Next Topic:[Acceleo] No common supertype error
Goto Forum:
  


Current Time: Thu Jul 31 09:33:33 EDT 2014

Powered by FUDForum. Page generated in 0.01639 seconds