C-like multiple declaration [message #1793679] |
Tue, 14 August 2018 00:29  |
Eclipse User |
|
|
|
Hi,
I'm trying to allow multiple declarations of the same type, a bit like in C or Java. However, I can't find a clean way to do it directly in the grammar. At the moment I have the "usual" way (snippet):
Declaration returns Declaration:
'var' name=ID ':' type = [Type];
So, when declaring stuff, considering that I declared a type Integer, I write:
var anInteger : Integer
var another : Integer
The idea is to simply have
var anInteger, another : Integer
But I'd like to instantiate as many Declaration EObjects as I declare elements, i.e, I do not want to have a list of names for one Declaration (using the usual parameter-like pattern below), but triggering the creation of multiple Declaration from the grammar.
Declaration returns Declaration:
'var' name+=ID (',' name+=ID)* ':' type = [Type];
Is there a way to do so directly from the grammar ? Or, if not possible, where do I have the hand to transform my list of names into a list of EObjects?
Thanks,
Fabian
|
|
|
|
|
|
|
|
|
|
Re: C-like multiple declaration [message #1793799 is a reply to message #1793756] |
Wed, 15 August 2018 22:27  |
Eclipse User |
|
|
|
Thanks working like a charm, now. For further reference, if needed:
def Class<? extends IDerivedStateComputer> bindIDerivedStateComputer() {
return IoTDSLDerivedState
}
override Class<? extends XtextResource> bindXtextResource() {
return DerivedStateAwareResource;
}
def Class<? extends IResourceDescription.Manager> bindIResourceDescriptionManager() {
return DerivedStateAwareResourceDescriptionManager;
}
Also, even if I didn't need it at the end, I think the new generator to override is org.eclipse.xtext.xtext.generator.XtextGenerator (the post you mentioned is using a deprecated generator, but I'm still unsure since doc in the class discourages from extending it).
public class IoTDSLExtendedGenerator extends XtextGenerator {
public IoTDSLExtendedGenerator() {
new XtextStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(new XtextRuntimeModule() {
@Override
public void configureIXtext2EcorePostProcessor(Binder binder) {
try {
Class.forName("org.eclipse.xtend.expression.ExecutionContext");
binder.bind(IXtext2EcorePostProcessor.class).to(IoTDSLPostProcessor.class);
} catch (ClassNotFoundException e) {
logger.error(e.getMessage(), e);
}
}
});
}
}.createInjectorAndDoEMFRegistration();
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.12915 seconds