Right way to call the parser [message #722500] |
Tue, 06 September 2011 01:27 |
Paulo Messages: 3 Registered: August 2011 |
Junior Member |
|
|
Hi All,
I have a RAP application that needs to parse some DSL files at startup. So, I'm at an equinox environment, but don't want all that editor stuff in this package. My question is: How is the proper way to get a parser reference and do the parsing?
I'm currently doing as following:
Injector doSetup = TerraStandaloneSetup.doSetup();
IParser instance = doSetup.getInstance(IParser.class);
IParseResult parse = instance.parse(new InputStreamReader(is));
EObject rootASTElement = parse.getRootASTElement();
for(INode n : parse.getSyntaxErrors()){
log.error(n.getSyntaxErrorMessage().getMessage());
}
[Updated on: Tue, 06 September 2011 01:33] Report message to a moderator
|
|
|
|
Re: Right way to call the parser [message #722573 is a reply to message #722500] |
Tue, 06 September 2011 08:06 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
The standalone setup is for the non-Equinox context only. It populates
the singleton registries of EMF. In Equinox this is done by means of
extension points. It is important you don't mess these up.
Furthermore, it is important you don't instantiate two different
versions of the Guice Injector. In an Equinox environment, you can
access the DI injector via the Activator of your languages UI plug-in.
Injector injector = Activator.getInstance().getInjector("yourlanguagename");
The same instance is used by the generated executable extension factory
of your language.
Usually, you don't just want the parser, but the linked EMF model . If
everything is registered in the right way, you should not need the
injector at all, but use plain EMF techniques, e.g.
ResourceSet.getResource(URI, true). This is well explained in the docs.
Am 06.09.11 03:27, schrieb Paulo:
> Hi All,
>
> I have a RAP application that needs to parse some DSL files at startup.
> So, I'm at an equinox environment, but don't want all that editor stuff
> in this package. My question is: How is the proper way to get a parser
> reference and do the parsing?
>
> I'm currently doing as following:
> Injector doSetup = TerraStandaloneSetup.doSetup();
> IParser instance = doSetup.getInstance(IParser.class);
> IParseResult parse = instance.parse(new InputStreamReader(is));
> EObject rootASTElement = parse.getRootASTElement();
> for(INode n : parse.getSyntaxErrors()){
> log.error(n.getSyntaxErrorMessage().getMessage());
> }
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
|
Re: Right way to call the parser [message #724788 is a reply to message #724724] |
Tue, 13 September 2011 06:50 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Am 13.09.11 02:52, schrieb Paulo:
> What do you mean by "Linked EMF Model"?
After parsing, the cross-references in the model are established. That
is called linking.
> I've been reading the documentation and section "8.2. Setup within
> Eclipse-Equinox (OSGi)" explains this topic quite superficially. I was
> unable to use ExecutableExtensionFactory, it throws a
> NoClassDefFoundError, so I exported that package and imported in my
> second plugin. This way I got a NoClassDefFoundError on my second plugin
> class that was thrown from ExecutableExtensionFactory. I thought it
> would generate a cyclic dependency. As the documentation says:
>
> "The only thing you have to do in order to use this factory is to prefix
> the class with the factory MyDslExecutableExtensionFactory name followed
> by a colon."
I guess something is wrong with your plug-in setup. Easiest solution is
to put everything you want the EEF to instantiate into the ui plug-in of
your language.
> While I could not get this working, I'm doing:
>
> Injector injector =
> br.com.maisha.wind.terra.ui.internal.TerraActivator.getInstance().getInjector("br.com.maisha.wind.terra.Terra");
>
> parser = injector.getInstance(IParser.class);
> IParseResult parse = parser.parse(sr);
> DomainObject rootASTElement = (DomainObject) parse.getRootASTElement();
As stated before, this will give you the model in its plain containment
structure, i.e. without cross-references.
> Is this a bad thing?
No, it's not necessarily bad, but you are using low-level hooks while
the high-level hooks are more convenient, comply to the EMF API and have
richer functionality, e.g. cross-references, on-demand loading of
referred external model etc.
The recommended way to load models is via a resource set as described in
the docs. As the resource factory is registered via extension points in
an equinox environment, there is nothing special you have to take care of.
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Powered by
FUDForum. Page generated in 0.04268 seconds