XtendParser [message #540538] |
Wed, 16 June 2010 09:19  |
Eclipse User |
|
|
|
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 #540652 is a reply to message #540602] |
Wed, 16 June 2010 16:32   |
Eclipse User |
|
|
|
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
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));
|
|
|
|
Powered by
FUDForum. Page generated in 0.33968 seconds