Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Trigger new rule after creating cross reference
Trigger new rule after creating cross reference [message #1407030] Mon, 11 August 2014 18:02 Go to next message
Rodrigo Lins de Oliveira is currently offline Rodrigo Lins de OliveiraFriend
Messages: 6
Registered: August 2014
Junior Member
I'm new with Xtext, and I've been working in a small DSL that uses an ecore model.
In my DSL, I have a RoleType with attributes and operations like this.

RoleType returns crom::RoleType:
    {crom::RoleType}
    'role' name=EString (Extends tr_extends=[crom::RoleType])?
    '{'
        (attributes+=Attribute | operations+=Operation)*
    '}';


When I define a new role I have to do something like this:

compartment myCompartment {
	rolemodel:
	role A {
		
	}
	role B {
		
	}
	constraints:
	total A -> B;
	
}


And later on I can create contraints between roles

Constraint returns crom::Constraint:
	(RoleConstraint | RelationshipConstraints | ComplexConstraint) ';'?;
RoleConstraint returns crom::RoleConstraint:
	RoleImplication | RoleEquivalence | RoleProhibition;


RoleImplication returns crom::RoleImplication:
	(first=[crom::RoleType|QualifiedName] ('implies' | '->' | '>') second=[crom::RoleType|QualifiedName] |
	second=[crom::RoleType|QualifiedName] ('<-' | '<') first=[crom::RoleType|QualifiedName]) ';';


But the thing is, when I create a new Role and define a new Constraint I should create a RoleTypeInheritance rule.

RoleTypeInheritance returns crom::RoleInheritance:
	{crom::RoleInheritance}
	super=[crom::RoleType|QualifiedName] sub=[crom::RoleType|QualifiedName];


I'm not sure if I made myself clear. In conclusion I want to create an instance of RoleTypeInheritance when I create a new Constraint.

Thanks in advance,
Rodrigo.
Re: Trigger new rule after creating cross reference [message #1407064 is a reply to message #1407030] Mon, 11 August 2014 20:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
Hi,

i did not get your actual problem. can you please elaborate ...


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trigger new rule after creating cross reference [message #1407067 is a reply to message #1407064] Mon, 11 August 2014 20:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
if you want to write one thing and derive implcitely other things have a look at IDerivedStateComputer
http://xtextcasts.org/episodes/18-model-optimization


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trigger new rule after creating cross reference [message #1407071 is a reply to message #1407064] Mon, 11 August 2014 20:24 Go to previous messageGo to next message
Rodrigo Lins de Oliveira is currently offline Rodrigo Lins de OliveiraFriend
Messages: 6
Registered: August 2014
Junior Member
OK, sorry, I will try to reformulate my question.

When I define a contraint using my DSL I am using the role I created called RoleImplication. But I want to use underneath the role RoleTypeInheritance. Because we have different types of Contraints like RoleImplication, RoleEquivalence, RoleProhibition, but in the end all contraints are RoleTypeInheritance from two differents RoleType in my Constraint.

Try in a different way.

Here I define my roles using the rule RoleType.

        rolemodel:
        role A {
		
	}
	role B {
		
	}


And latter on I use the rules that I created to define contraints between them.
The rule is called constraint and it uses the RoleTypes I defined before.
Since I have different types of constraints I should declare a rule for each type.
(RoleImplication, RoleEquivalence, RoleProhibition)

        constraints:
	A -> B;


But, the a constraint, in my case, define a relationship between two roles and this relationship is represented by RoleTypeInheritance.

My question is, having a constraint A->B (RoleImplication) how can I link them using the role RoleTypeInheritance? I think it should be done probably at the linking phase, but I don't know how. Any Ideas?

Thanks.
Re: Trigger new rule after creating cross reference [message #1407079 is a reply to message #1407071] Mon, 11 August 2014 20:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
Hi,

i still do not understand where the problem is. you simply want to introduce a common supertype.

simply write a rule that you do no call

Parent: Child1 | ... | ChildN;


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trigger new rule after creating cross reference [message #1407323 is a reply to message #1407079] Tue, 12 August 2014 10:27 Go to previous messageGo to next message
Rodrigo Lins de Oliveira is currently offline Rodrigo Lins de OliveiraFriend
Messages: 6
Registered: August 2014
Junior Member
It doesn't fulfill my needs.
Because, I can have different types: DataType, NaturalType, CompartmentType, RoleType and so on.
And I have different Constraints: RoleImplication, RoleEquivalence, RoleProhibition and so on.
If I have just types without constraints they are only types. But if I define a constraint between them (e.g. A -> B), so they become members of CompartmentTypeInheritance, only if I define the constraint. Got it?

I was trying to manipulate the resource class in my generator, but I don't know if this is a valid approach.

Thanks for your help.
Re: Trigger new rule after creating cross reference [message #1407335 is a reply to message #1407323] Tue, 12 August 2014 11:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
No

can you please pseudocode the ast you want and the ast you get (maybe as java classes)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trigger new rule after creating cross reference [message #1407367 is a reply to message #1407335] Tue, 12 August 2014 12:55 Go to previous messageGo to next message
Rodrigo Lins de Oliveira is currently offline Rodrigo Lins de OliveiraFriend
Messages: 6
Registered: August 2014
Junior Member
This is my grammar

//Main model element
Model returns crom::Model:
	{crom::Model}
	(elements+=ModelElement | relations+=ModelRelations)*;

ModelRelations returns crom::Relation:
	Fulfillment ';'?;

ModelElement returns crom::ModelElement:
	Group | RigidType;

	//Basic terminals
enum Direction returns crom::Direction:
	Undirected='--' | FirstToSecond='-->' | SecondToFirst='<--';

EString returns ecore::EString:
	STRING | ID;

QualifiedName:
	ID ('.' ID)*;

Extends:
	'extends' | ':';

Fills:
	'fills' | 'can play' | '-|>';

	//Definition of basic model element properties
Attribute returns crom::Attribute:
	name=ID ':' type=[crom::RigidType|EString] ';'; //TODO: Replace ESTRING with QualifiedName

Parameter returns crom::Parameter:
	{crom::Parameter}
	name=ID ':' type=[crom::RigidType|EString]; //TODO: Replace ESTRING with QualifiedName

Operation returns crom::Operation:
	name=ID
	'(' (params+=Parameter ("," params+=Parameter)*)? ')' ':' type=[crom::RigidType|EString] //TODO: Replace ESTRING with QualifiedName
	'{'
	operation=EString
	'}';

	//Definition of basic model elements
RigidType returns crom::RigidType:
	DataType | NaturalType | CompartmentType;

Group returns crom::Group:
	{crom::Group}
	'group' name=EString
	'{'
	(elements+=ModelElement)*
	('relations:'
	(relations+=ModelRelations)*)?
	'}';

DataType returns crom::DataType:
	{crom::DataType}
	(serializable?='serializable')?
	'data' name=EString (Extends tr_extends=[crom::DataType])? //TODO: Replace ESTRING with QualifiedName
	'{'
	(attributes+=Attribute | operations+=Operation)*
	'}';

NaturalType returns crom::NaturalType:
	{crom::NaturalType}
	'natural' name=EString (Extends tr_extends=[crom::NaturalType])? //TODO: Replace ESTRING with QualifiedName
	'{'
	(attributes+=Attribute | operations+=Operation)*
	'}';

	//Definition of Compartments
CompartmentType returns crom::CompartmentType:
	{crom::CompartmentType}
	'compartment' name=EString (Extends tr_extends=[crom::CompartmentType])? //TODO: Replace ESTRING with QualifiedName
	'{'
	('interface:' (attributes+=Attribute | operations+=Operation)*)?
	('rolemodel:' (parts+=Part | relationships+=Relationship)*)?
	('constraints:' (constraints+=(Constraint))*)?
	'}';

CompartmentTypeInheritance returns crom::CompartmentInheritance:
	{crom::CompartmentInheritance}
	super=[crom::CompartmentType|QualifiedName] sub=[crom::CompartmentType|QualifiedName];

Part returns crom::Part:
	('[' lower=INT '..' upper=INT ']' |
	'[' lower=INT '..' '*' ']' |
	//	  '[' lower=PInt ']' | //TODO: find out how this might work
	'[*]')?
	role=AbstractRole;

AbstractRole returns crom::AbstractRole:
	RoleType | RoleGroup;

RoleType returns crom::RoleType:
	{crom::RoleType}
	'role' name=EString (Extends tr_extends=[crom::RoleType])?
	'{'
	(attributes+=Attribute | operations+=Operation)*
	'}';

RoleTypeInheritance returns crom::RoleInheritance:
	{crom::RoleInheritance}
	super=[crom::RoleType|QualifiedName] sub=[crom::RoleType|QualifiedName];

RoleGroup returns crom::RoleGroup:
	'rolegroup' name=EString
	(('#' | 'selecting') lower=INT ('..' | 'upto') upper=INT |
	('#' | 'selecting') lower=INT ('..' | 'upto') '*' |
	('#' | 'selecting') '*')?
	'{'
	(elements+=RoleGroupElement (elements+=RoleGroupElement)*)?
	'}';

RoleGroupElement returns crom::RoleGroupElement:
	RoleType | RoleGroup | AbstractRoleReference;

AbstractRoleReference returns crom::AbstractRoleRef:
	ref=[crom::AbstractRole|QualifiedName] (';')?;

Relationship returns crom::Relationship:
	name=ID '(' first=Place direction=Direction second=Place ')'
	(':' tr_constraints+=IntraRelationshipConstraint (',' tr_constraints+=IntraRelationshipConstraint)*)?;

Place returns crom::Place:
	holder=[crom::RoleType|QualifiedName]
	('[' lower=INT '..' upper=INT ']' |
	'[' lower=INT '..' '*' ']' |
	'[*]')?;

	//Definition of Constraints
Constraint returns crom::Constraint:
	(RoleConstraint | RelationshipConstraints | ComplexConstraint) ';'?;

RoleConstraint returns crom::RoleConstraint:
	RoleImplication | RoleEquivalence | RoleProhibition;

RoleImplication returns crom::RoleImplication:
	(first=[crom::RoleType|QualifiedName] ('implies' | '->' | '>') second=[crom::RoleType|QualifiedName] |
	second=[crom::RoleType|QualifiedName] ('<-' | '<') first=[crom::RoleType|QualifiedName]) ';';

RoleEquivalence returns crom::RoleEquivalence:
	first=[crom::RoleType|QualifiedName] ('equals' | '<->' | '<>') second=[crom::RoleType|QualifiedName] ';';

RoleProhibition returns crom::RoleProhibition:
	first=[crom::RoleType|QualifiedName] ('prohibits' | '><' | '>-<') second=[crom::RoleType|QualifiedName] ';';

RelationshipConstraints returns crom::RelationshipConstraint:
	IntraRelationshipConstraint | InterRelationshipConstraint;

IntraRelationshipConstraint returns crom::IntraRelationshipConstraint:
	({crom::Total} 'total' |
	{crom::Cyclic} 'cyclic' |
	{crom::Irreflexive} 'irreflexive' |
	{crom::ParthoodConstraint} kind=Parthood);

InterRelationshipConstraint returns crom::InterRelationshipConstraint: //TODO: Replace ESTRING with QualifiedName
	{crom::RelationshipImplication}
	(first=[crom::Relationship|EString] ('subset of' | '==>') second=[crom::Relationship|EString] |
	second=[crom::Relationship|EString] ('superset of' | '<==') first=[crom::Relationship|EString]);

enum Parthood returns crom::Parthood:
	ExclusivePart='exclusivepart' | SharablePart='sharablepart' | EssentialPart='essentialpart' |
	MandatoryPart='mandatorypart' | InseparablePart='inseparablepart';

	//Definition of Fulfillment 
Fulfillment returns crom::Fulfillment:
	filler=[crom::RigidType] Fills filled=[crom::AbstractRole|QualifiedName];

	//continue the definition
ComplexConstraint returns crom::ComplexConstraint:
	'invariant' 'using' targets+=[crom::AbstractRole|QualifiedName] ("," targets+=[crom::AbstractRole|QualifiedName])*
	'ensure' expression=EString;


And this is a language generated with my grammar

compartment myCompartment {
	rolemodel:
	role A {
		
	}
	role B extends A {
		
	}
	role C {
		
	}
	
	role D {
		
	}
	
	[*] role E {
		
	}
	[0..10] role F {
		
	}
	constraints:
	total A -> B;
	B -> C;
}


When I create a contraint between two roles I should create a RoleTypeInheritance as well because, now, they have a relationship.
Got it?
Re: Trigger new rule after creating cross reference [message #1407386 is a reply to message #1407367] Tue, 12 August 2014 13:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
so B -> C actually creates 2 objects?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trigger new rule after creating cross reference [message #1407391 is a reply to message #1407386] Tue, 12 August 2014 13:50 Go to previous messageGo to next message
Rodrigo Lins de Oliveira is currently offline Rodrigo Lins de OliveiraFriend
Messages: 6
Registered: August 2014
Junior Member
Yeap. Exactly.
Re: Trigger new rule after creating cross reference [message #1407393 is a reply to message #1407391] Tue, 12 August 2014 13:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
this is why i proposed you an iderivedstatecomputer in the first place

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trigger new rule after creating cross reference [message #1407399 is a reply to message #1407393] Tue, 12 August 2014 13:58 Go to previous message
Rodrigo Lins de Oliveira is currently offline Rodrigo Lins de OliveiraFriend
Messages: 6
Registered: August 2014
Junior Member
Ok. Thanks I will get a better look on it.
Previous Topic:Cross-file references as in 15-min tutorial not working
Next Topic:Xtext editor does not reflect changes in linked resources
Goto Forum:
  


Current Time: Sun Dec 08 05:45:23 GMT 2019

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

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

Back to the top