Crossreference & lazy loading pb ? [message #59393] |
Thu, 16 July 2009 04:20  |
Eclipse User |
|
|
|
Hi,
I Created a basic grammar dsl.xtext :
DSLOrchestror :
engines+=(DSLCommandEngine)+
clients+=(DSLEngineClient)+
timelines+=(DSLTimeLine)+
application=(DSLEngineApp)
;
DSLCommandEngine :
'engine' name=ID ';'
;
DSLEngineClient :
'client' name=ID '{' refCmdEngines+=[DSLCommandEngine]+ '}' ';'
;
DSLTimeLine :
'timeline' name=ID ':' cmdEngine=[DSLCommandEngine] ';'
;
DSLEngineApp :
'application' name=ID '{' refClients+=[DSLEngineClient]+ '}' ';'
;
My intent was to be able to take advantage of references in order to get
some valuations available to feed another Ecore model.
===================================
test.dsl
===================================
engine e1;
engine e2;
engine e3;
client c1 { e1 e2 e3 };
timeline t1 : e1;
timeline t2 : e2;
timeline t3 : e3;
application a1 { c1 };
===================================
I then created a Guice powered loader from generated "dslStandaloneSetup"
stuff (with option : XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE).
When loading test.dsl, cross references target for
"cmdEngine=[DSLCommandEngine]" loose name attribute value (null ...).
Should I modify my grammar ?
Should I customize some code somewhere somehow ?
regards,
PS : code of the loader atached
private XtextResourceFactory factory;
private OrchestrorStandaloneSetup orchestrorStandaloneSetup;
private Injector injector;
@Inject
public OrchestrorUtil(OrchestrorStandaloneSetup setup) {
orchestrorStandaloneSetup = setup;
injector =
orchestrorStandaloneSetup.createInjectorAndDoEMFRegistration ();
factory = (XtextResourceFactory)
injector.getInstance(IResourceFactory.class);
}
EObject getModel2(InputStream in) throws IOException {
XtextResource r = (XtextResource)
factory.createResource(URI.createFileURI("model.test"));
r.load(in, Collections.singletonMap(XtextResource.OPTION_RESOLVE_ALL,
Boolean.TRUE));
return r.getParseResult().getRootASTElement();
}
public Orchestror loadOrchestror(String pathname) {
try {
return loadOrchestror(new FileInputStream(new File(pathname)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
try {
Injector injector = Guice.createInjector(new OrchestrorUtilsModule());
OrchestrorUtil orchestrorUtil = (OrchestrorUtil)
injector.getInstance(IOrchestrorUtils.class);
FileInputStream in = new FileInputStream(new
File("data/test.orchestror").getCanonicalPath());
Orchestror orchestror = orchestrorUtil.loadOrchestror(in);
System.out.println("ID : " + orchestror.getId());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
|
|
|
Re: Crossreference & lazy loading pb ? [message #59472 is a reply to message #59393] |
Thu, 16 July 2009 04:37   |
Eclipse User |
|
|
|
Hi Lucas,
your grammar seems to be incomplete.
Can you please provide the header of the grammar, too. Do you use
metamodel generation or do you import an existing metamodel?
What do you expect from this line for your particular sample model:
System.out.println("ID : " + orchestror.getId());? Does it print what
you expect?
Furthermore, you wrote the assignments in a somewhat irritating way:
DSLOrchestror:
(engines+=DSLCommandEngine)+
(clients+=DSLEngineClient)+
// or even
timelines+=DSLTimeLine+
application=DSLEngineApp
;
There is no need for parenthesis around the right hand side of an
assignment.
In your special case there won't be any need for customization of the
linker or scope provider with the grammar that you provide if you use
meta model inference. The validator should be customized to highlight
duplicate names as an error because they will be unreachable in the
linking stage.
Regards,
Sebastian
Am 16.07.2009 10:20 Uhr, schrieb lucas:
> Hi,
>
> I Created a basic grammar dsl.xtext :
>
> DSLOrchestror :
> engines+=(DSLCommandEngine)+
> clients+=(DSLEngineClient)+
> timelines+=(DSLTimeLine)+
> application=(DSLEngineApp)
> ;
>
>
> DSLCommandEngine :
> 'engine' name=ID ';'
> ;
>
> DSLEngineClient :
> 'client' name=ID '{' refCmdEngines+=[DSLCommandEngine]+ '}' ';'
> ;
>
> DSLTimeLine :
> 'timeline' name=ID ':' cmdEngine=[DSLCommandEngine] ';'
> ;
>
> DSLEngineApp :
> 'application' name=ID '{' refClients+=[DSLEngineClient]+ '}' ';'
> ;
>
>
> My intent was to be able to take advantage of references in order to get
> some valuations available to feed another Ecore model.
>
> ===================================
> test.dsl
> ===================================
>
> engine e1; engine e2; engine e3;
>
> client c1 { e1 e2 e3 };
>
> timeline t1 : e1;
> timeline t2 : e2;
> timeline t3 : e3;
>
> application a1 { c1 };
>
>
> ===================================
>
> I then created a Guice powered loader from generated
> "dslStandaloneSetup" stuff (with option :
> XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE).
>
> When loading test.dsl, cross references target for
> "cmdEngine=[DSLCommandEngine]" loose name attribute value (null ...).
>
> Should I modify my grammar ?
>
> Should I customize some code somewhere somehow ?
>
> regards,
>
> PS : code of the loader atached
>
>
> private XtextResourceFactory factory;
> private OrchestrorStandaloneSetup orchestrorStandaloneSetup;
> private Injector injector;
>
> @Inject
> public OrchestrorUtil(OrchestrorStandaloneSetup setup) {
> orchestrorStandaloneSetup = setup;
> injector = orchestrorStandaloneSetup.createInjectorAndDoEMFRegistration ();
> factory = (XtextResourceFactory)
> injector.getInstance(IResourceFactory.class);
> }
>
> EObject getModel2(InputStream in) throws IOException {
> XtextResource r = (XtextResource)
> factory.createResource(URI.createFileURI("model.test"));
> r.load(in, Collections.singletonMap(XtextResource.OPTION_RESOLVE_ALL,
> Boolean.TRUE));
> return r.getParseResult().getRootASTElement();
> }
>
>
> public Orchestror loadOrchestror(String pathname) {
> try {
> return loadOrchestror(new FileInputStream(new File(pathname)));
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> }
> return null;
> }
>
> public static void main(String[] args) {
> try {
> Injector injector = Guice.createInjector(new OrchestrorUtilsModule());
> OrchestrorUtil orchestrorUtil = (OrchestrorUtil)
> injector.getInstance(IOrchestrorUtils.class);
>
> FileInputStream in = new FileInputStream(new
> File("data/test.orchestror").getCanonicalPath());
>
> Orchestror orchestror = orchestrorUtil.loadOrchestror(in);
> System.out.println("ID : " + orchestror.getId());
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04340 seconds