Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » XtendParser(XtendParser)
XtendParser [message #540538] Wed, 16 June 2010 13:19 Go to next message
Macca1892 is currently offline Macca1892Friend
Messages: 14
Registered: May 2010
Junior Member
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 #540602 is a reply to message #540538] Wed, 16 June 2010 16:03 Go to previous messageGo to next message
Erhard Weinell is currently offline Erhard WeinellFriend
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member
Am 16.06.2010 15:19, schrieb Macca1892:

> ExtensionFile f = ParseFacade.file(new StringReader(expression), fileName);
>
> expression is a string but I don't understand what should I assign for it

You are using a java.io.StringReader, which means you need to supply the
Xtend document. Or you could use a FileReader to load a file - which is
bad as it uses the "default charset". Best go for something like:

new InputStreamReader(new FileInputStream(file), "your_charset")

where your_charset is either UTF-8, ISO8859-1, or whatever your
Xtend-file is encoded in.

The fileName parameter of ParseFacade.file is just for adding location
informations to the resulting AST.


Best regards,
Erhard Weinell

--
Meet us online!
w http://www.yatta.de
tw @YattaSolutions
fb http://www.facebook.com/pages/Yatta-Solutions-GmbH/933852562 69
Re: XtendParser [message #540652 is a reply to message #540602] Wed, 16 June 2010 20:32 Go to previous messageGo to next message
Macca1892 is currently offline Macca1892Friend
Messages: 14
Registered: May 2010
Junior Member
Thank you very much, Erhard Weinell !

Yeah, the string expression actually is the content of .ext file.
I used to "hardcode" directly the content of .ext file but it is much nicer to use InputStreamReader as you suggested

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 #540726 is a reply to message #540538] Thu, 17 June 2010 08:05 Go to previous message
Macca1892 is currently offline Macca1892Friend
Messages: 14
Registered: May 2010
Junior Member
sorry, my fault!
This code works well Smile
Previous Topic:[ATL] transformation one element in two elements and their arrangement
Next Topic:[ATL]How to transform XML-Model (conformed to XSD-Metamodel) in ecore
Goto Forum:
  


Current Time: Tue Dec 03 08:30:35 GMT 2024

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

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

Back to the top