Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Crossreference & lazy loading pb ?
Crossreference & lazy loading pb ? [message #59393] Thu, 16 July 2009 08:20 Go to next message
lucas bigeardel is currently offline lucas bigeardelFriend
Messages: 155
Registered: July 2009
Senior Member
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 08:37 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
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();
> }
> }
>
>
Re: Crossreference & lazy loading pb ? [message #59496 is a reply to message #59472] Thu, 16 July 2009 09:09 Go to previous messageGo to next message
lucas bigeardel is currently offline lucas bigeardelFriend
Messages: 155
Registered: July 2009
Senior Member
Just testing around ...

here is my test grammar :

grammar net.sf.xqz.engine.script.Orchestror with
org.eclipse.xtext.common.Terminals

generate orchestror "http://www.sf.net/xqz/engine/script/Orchestror"

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]+ '}' ';'
;

the sysout was just a old school non nullity test ^^
Re: Crossreference & lazy loading pb ? [message #59521 is a reply to message #59496] Thu, 16 July 2009 09:22 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Lucas,

where does the getID() come from? I cannot see an ID attribute in the
Furthermore the code in your OrchetrorUtil does not seem to be
compilable. I'ld guess that getModel2(..) is never called. Where does
the class "Orchestror" come from. You see, it is rather difficult to
answer your question with the snippets that you provided.

I'ld expect the code to load a model to look similar to this one:

XtextResourceSet set = injector.getInstance(XtextResourceSet.class);
set.setClasspathURIContext(getClass());
set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = set.getResource(URI.createURI(uri), true);
return (DSLOrchestror) resource.getContents().get(0);

Hope that helps,
Sebastian


Am 16.07.2009 11:09 Uhr, schrieb lucas bigeardel:
> Just testing around ...
>
> here is my test grammar :
>
> grammar net.sf.xqz.engine.script.Orchestror with
> org.eclipse.xtext.common.Terminals
>
> generate orchestror "http://www.sf.net/xqz/engine/script/Orchestror"
>
> 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]+ '}' ';'
> ;
>
> the sysout was just a old school non nullity test ^^
>
>
Re: Crossreference & lazy loading pb ? [message #59545 is a reply to message #59521] Thu, 16 July 2009 09:35 Go to previous message
lucas bigeardel is currently offline lucas bigeardelFriend
Messages: 155
Registered: July 2009
Senior Member
The snippet did the trick !

my lary refs are resolved now.

you rock

thx
Previous Topic:Using xtext for comprehensive languages
Next Topic:Generation oddity with imported grammar
Goto Forum:
  


Current Time: Tue Aug 27 22:53:01 GMT 2024

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

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

Back to the top