Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » 2 DSLs and 1 Ecore-Model(Can 2 DSLs contribute into a single model)
2 DSLs and 1 Ecore-Model [message #1759099] Thu, 06 April 2017 10:46 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Hello everyone

I am currently working on a little DSL which should replace some pretty tedious configuration XML and HTML.
The DSLs should each have their own concern, one being a description of data and the other the ui.

So I defined a Ecore-Model (with Xcore) which looks like this
Model
	Document (n)
		Data
			Field (n)
		UI
			define UI with references to Fields


Of course I can define everything in one DSL, but then the file gets pretty big and ugly.
I already have two DSLs (within one project) working nicely. Unfortunately each DSL has its own model-instance (within Document I expect that Data and UI have references, but one is always null depending on the file edited). Is is possible that 2 DSL work on the same model-instance? Or what is the correct way to achieve this

I assume that my Parser is wrong because I define the complete hierarchy and just switch data/ui in Documents. In my first attempt the parser started at Data or UI but then the eContainer-fields where null.

Data-Parser
Model returns Model: 
	documents+=Document 
;
Document returns Document :
	data=Data
;
Data returns Data: 
	("Fields" "{"
		(fields+=Field)+
	"}")*
	(groups+=Group)+
;
....some more stuff


UI-Parser
Model returns Model: 
	documents+=Document 
;
Document returns Document :
	ui=UI
;
UI returns UI: 
	...
;
....some more stuff


I have no idea if what I am trying to achieve is possible at all. So any help is appreciated, even if I have to go a completely other way (scoping?).
Re: 2 DSLs and 1 Ecore-Model [message #1759100 is a reply to message #1759099] Thu, 06 April 2017 10:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
no this is not possible. (well you could create a own editor that uses 2 embedded xtext editors, but i doubt that is what you want)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: 2 DSLs and 1 Ecore-Model [message #1759101 is a reply to message #1759100] Thu, 06 April 2017 10:56 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Thanks for the quick reply

So each Ecore model should be completely covered by one DSL? And the best practise would be to define those two models and use scoping to have the correct cross-references?
Re: 2 DSLs and 1 Ecore-Model [message #1759102 is a reply to message #1759101] Thu, 06 April 2017 10:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
yes that works out of the box, you can even use the same ecore, but you need cross references

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: 2 DSLs and 1 Ecore-Model [message #1759110 is a reply to message #1759102] Thu, 06 April 2017 14:20 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Hmmm, the cross-reference isnt working when using a single ecore-model.

Usualy each DSL generates its own model which can be imported. In my case I only import the single ecore in both DSLs and I can define a cross-reference. The editor is not showing any proposals for cross-references to other files. AFAK the default scope provider is presenting all elements from all files...

Or do I already have to write my own Scope?

Just to clarify, I my test I have two files (one for each DSL), the model in DSL A is valid (code-gen works) but DSL B is not showing any elements from A.
Re: 2 DSLs and 1 Ecore-Model [message #1759112 is a reply to message #1759110] Thu, 06 April 2017 14:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
no this works out of the box.

i dont know what you did in your code, maybe you can share something reproducible to look at


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: 2 DSLs and 1 Ecore-Model [message #1759123 is a reply to message #1759112] Thu, 06 April 2017 15:42 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Unfortunately I cannot put anything on Github so I will put something here

grammar de.xxx.tooling.DataDsl with org.eclipse.xtext.common.Terminals

import "http://www.xxx.de/tooling/model/DslEcore"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore


DataRule returns Data: 
	("Fields" "{"
		(fields+=FieldRule)+
	"}")*
	(groups+=GroupRule)+
;


GroupRule returns Group:
	...skipped
;

FieldRule returns Field:
	...skipped...
;


grammar de.xxx.tooling.UiDsl with org.eclipse.xtext.common.Terminals

import "http://www.xxx.de/tooling/model/DslEcore"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore


UIRegel returns UI:
	felder+=(FeldRefRegel)*
;

FieldRefRegel returns FieldRef:
	HorizontalFieldRule | VerticalFieldRule
;

HorizontalFieldRule returns HorizontalFieldRef:
	"horizontal" "(" horizontaleFields+=[Field] ")" 
; 

VerticalFieldRule returns VerticalFieldRef:
	"field" field=[Field] 
;


And the Xcore...maybe the reference is not modelled correct
@Ecore(nsURI="http://www.xxx.de/tooling/model/DslEcore")
@GenModel(
	modelDirectory="/de.xxx.tooling/emf-gen", 
	modelName="DslEcore",
	forceOverwrite="true", 
	updateClasspath="false", 
	complianceLevel="8.0"
)
package de.sdvrz.tooling.model

// 
// Data
// 

class Data {
	derived String name get {
		//Paths.get(this.eResource.URI.toFileString).parent.fileName.toString
		this.eResource().getURI().segment(3)
	}
	contains Field [] fields
	contains Group [] groups
}


class Group {
	...skipped
}

class Feld {
	...skipped
}

//
// UI
//

class UI {
	derived String name get {
		//Paths.get(this.eResource.URI.toFileString).parent.fileName.toString
		this.eResource().getURI().segment(3)
	}
	contains FieldRef [] fields
}

interface FieldRef {

}

class VerticalFieldRef extends FieldRef{
	refers Field field
}

class HorizontalFieldRef extends FieldRef {
	refers Field[] horizontalFields
}

[Updated on: Thu, 06 April 2017 19:15]

Report message to a moderator

Re: 2 DSLs and 1 Ecore-Model [message #1759126 is a reply to message #1759123] Thu, 06 April 2017 16:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Ähhm which are the refs you are talking about

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: 2 DSLs and 1 Ecore-Model [message #1759132 is a reply to message #1759126] Thu, 06 April 2017 18:11 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Sorry, I missed that. In the Xcore file it´s the Field reference which conntects Restdaten with Datenversorgung

In the second DSL it´s about the following Rules
HorizontalFieldRule returns HorizontalFieldRef:
	"horizontal" "(" horizontalFields+=[Field] ")" 
; 


VerticaleFieldRule returns VerticalFieldRef:
	"field" field=[Field] 
;


So it should be able to write the following
field <fieldref_1>
horizontal (<fieldref_2> <fieldref_3>)
field <fieldref_4>
...

[Updated on: Thu, 06 April 2017 19:15]

Report message to a moderator

Re: 2 DSLs and 1 Ecore-Model [message #1759134 is a reply to message #1759132] Thu, 06 April 2017 18:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi,

this is a Naming Conventions vs. Grammar vs magic getName functions in Xcore Thing

either in Grammar:

FQN: ID ("." ID)*;

...
"feld" feld=[Feld|FQN]
...


the |FQN means parse a FQN (the default is |ID which does not allow a .)

our you change in the runtime module of the first dsl:

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	
	override bindIQualifiedNameProvider() {
		SimpleNameProvider
	}
	
}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: 2 DSLs and 1 Ecore-Model [message #1759136 is a reply to message #1759134] Thu, 06 April 2017 19:02 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
FQN solves it in the way I need it. Thank you very much.

I remember that I used that approach in my last DSL project as well, but that was two years ago Smile

[Updated on: Thu, 06 April 2017 19:16]

Report message to a moderator

Re: 2 DSLs and 1 Ecore-Model [message #1759154 is a reply to message #1759136] Thu, 06 April 2017 22:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
Hi

Returning to the original problem, you can solve it with a pair of intermediate models.

UItext <=> UImodel
DataText <=> DataModel
UImodel + DataModel <=> FullModel

Xtext can do the first as two grammars, resolving references to the FullModel.
Writing a custom merger/splitter for the FullModel looks easy. Integrating the merger/splitter into the Xtext processing may be harder. For OCL, I override LazyLinker.afterModelLinked for a Text <=> CS <=> AS concatenation.

Regards

Ed Willink
Re: 2 DSLs and 1 Ecore-Model [message #1759155 is a reply to message #1759154] Fri, 07 April 2017 06:16 Go to previous message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Thanks for the idea.
Previous Topic:UI locks up when XtextReconciler and Hover run concurrently
Next Topic:Import issues regarding qualified names
Goto Forum:
  


Current Time: Fri Jan 03 00:20:57 GMT 2025

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

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

Back to the top