Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Reading in File from another DSL in Generator
Reading in File from another DSL in Generator [message #1705757] Tue, 18 August 2015 20:34 Go to next message
Bine LuFriend
Messages: 3
Registered: August 2015
Junior Member
Hi everyone
I got a problem using two different DSLs and I can only find how to include the grammatik of another DSL into one DSL.

I have two grammatiks difined and need to read in a file from another DSL in my generator. That looks something like that:

DSL1-Definitions :
generate dsl1DSL "http://www.dsl1DSL.dsl1"
DSL1:
   somecontent=STRING
   (otherDSLs+=OtherDSL)*;
OtherDSL:
   "OtherDSL" name=ID path=STRING;


DSL-Definition 2:
generate dsl2DSL "http://www.dsl2DSL.dsl2"
DSL2:
   somecontent=STRING
   (methodcalls+=MethodCall)*;
MethodCall:
   "methos" returnValue=ID methodName=ID  params=STRING;


Now I need to check for the DSL2 in my DSL1 generator.
Something like this:
for (otherDSL : DSL1.otherDSLs) {
   Resource resource = new Resource(otherDSL.path);
   val dsl2 = resource.allContents.filter(typeof(DSL2)).head;
   for (methodcall : dsl2.methodCalls) {
     //use content here
   }
}


Any ideas how I can do that? Is there a way of creating a "Resource" or something similiar od an other DSL?
Re: Reading in File from another DSL in Generator [message #1705868 is a reply to message #1705757] Wed, 19 August 2015 15:58 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hi Bine,

sounds like you are looking for CrossReferences. Have a look at the documentation for that: https://www.eclipse.org/Xtext/documentation/301_grammarlanguage.html#cross-references

A more realistic example would help, too.

Cheers,
Stefan
Re: Reading in File from another DSL in Generator [message #1705888 is a reply to message #1705868] Wed, 19 August 2015 20:14 Go to previous messageGo to next message
Bine LuFriend
Messages: 3
Registered: August 2015
Junior Member
Thanks for the answer but I think it is not what I need or I do not understand it fully.
I'm trying to write a statemachine and need informations from our events which are declared in another dsl. I need to know the event function deklaration and do not want to write in the my statemachine dsl when needed.
So everything looks something like that:

Statemachine DSL:
Statemachine:
	(name=Name)
	(states+=State)*
	(eventgroups+=EventGroups)*,
EventGroups:
	"EventGroup" name=ID file=STRING;
State:
   "state" name=ID;


My event-DSL is shortend like this
Event:
	(interface+=Interface)	;

Interface:
	"interface" name=ID "{"
	(functions+=Function)*
	"}";

Function:
	returnVal=STRING methodName=STRING "(" params=STRING ")"";"
;

Both DSL are in different projects.

A DSL file for a statemachine looks like this:
name "myStatemachine"

state "state1"

EventGroup event1 "../NeededEvents.event"


I've got a generator for my events and my statemachine generator works fine as well. Only the informations I need from the event file are missing.
In my statemachine DSL I now want to get the informations from the file "../NeededEvents.event".
So my naive way would be something like this:
for (eventdsl : statemachine.eventGroups) {
   Resource resource = new Resource(eventdsl.file);
   val eventGroup = resource.allContents.filter(typeof(Event)).head;
   for (function : eventGroup.interface.functions) {
       //use content here
   }
}


Is this what you posted and I'm just not getting it or do I have to use something different?
Re: Reading in File from another DSL in Generator [message #1705897 is a reply to message #1705888] Wed, 19 August 2015 21:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The quedtion is: why do you want to refer to the events by a string only if you can have a real link (cross reference) https://christiandietrich.wordpress.com/2012/08/07/xtext-referencing-elements-of-one-dsl-from-another-dsl/

Ofcourse you can try to to build a target resource uri from your
Source resources uri and the string and then load the Ressource with
That uri but thats rather complicated and error prone


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Reading in File from another DSL in Generator [message #1705924 is a reply to message #1705897] Thu, 20 August 2015 07:43 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

import 'uri of your event dsl' as events

Statemachine:
	(name=Name)
	(states+=State)*
	('event' events+=[events:Event])*;

Should do the trick.

Cheers,
Stefan
Re: Reading in File from another DSL in Generator [message #1706170 is a reply to message #1705924] Mon, 24 August 2015 11:33 Go to previous message
Bine LuFriend
Messages: 3
Registered: August 2015
Junior Member
Thanks a lot, I'll try that! I understood it the wrong way I guess. I will get back to you if it didn't work Wink
Previous Topic:Cannot inject IHyperlinkHelper in junit
Next Topic:Which ANTLR version does Xtext currently use?
Goto Forum:
  


Current Time: Fri Apr 26 11:04:40 GMT 2024

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

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

Back to the top