Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to limit options to scope entities
how to limit options to scope entities [message #1237418] Wed, 29 January 2014 17:15 Go to next message
Razvan C is currently offline Razvan CFriend
Messages: 2
Registered: January 2014
Junior Member
if i define structural entities, say for mapping

Feature:
name = ID (':' type = [Type])? ('=' value=Expr)?
;

Entity:
'entity' name = ID ('extends' superType = [Entity])? '{'
(features += Feature)*
'}'
;

Mapping:
'from' source=[Entity] '{'
(generated+=
target=[Entity] '{'
(mappings+=FeatureMap)*
'}')*
'}'
;

FeatureMap:
target=[Feature|ID] '=' value=[Feature|ID]
;

-------

the result would be

entity Student {
firstName:String
lastName:String
age:Int
}
entity Person {
name:String
}
from Student {
Person {
name = firstName // how to limit options to firstName and lastName
}
}

---------

the question is how to limit the mapping to firstName/lastName/age since the scope is Student?

thanks
Re: how to limit options to scope entities [message #1237469 is a reply to message #1237418] Wed, 29 January 2014 20:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

this should be 100% straight forward...

first your grammar makes no sense. i start with the following

Model:
entities+=Entity*
mappings+=Mapping*
;

Feature:
name = ID 
;

Entity:
'entity' name = ID ('extends' superType = [Entity])? '{'
(features += Feature)*
'}'
;

Mapping:
'from' source=[Entity] '{'
(generated+=EntityMapping
)*
'}'
;

EntityMapping:
	target=[Entity] '{'
(mappings+=FeatureMap)*
'}'
;

FeatureMap:
target=[Feature|ID] '=' value=[Feature|ID]
;



then the scopeprovider should look like
class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {

	def IScope scope_FeatureMap_target(EntityMapping ctx, EReference ref) {
		Scopes.scopeFor(ctx.target.features)
	}
	
	def IScope scope_FeatureMap_value(Mapping ctx, EReference ref) {
		Scopes.scopeFor(ctx.source.features)
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to limit options to scope entities [message #1237497 is a reply to message #1237469] Wed, 29 January 2014 21:34 Go to previous message
Razvan C is currently offline Razvan CFriend
Messages: 2
Registered: January 2014
Junior Member
cool - thank you, i will try that
Previous Topic:Grammar and Validation unit_testing
Next Topic:Problem with "package" in my DSL
Goto Forum:
  


Current Time: Fri Mar 29 10:14:25 GMT 2024

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

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

Back to the top