Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping problem
icon5.gif  Scoping problem [message #754586] Thu, 03 November 2011 12:14 Go to next message
Joacim  is currently offline Joacim Friend
Messages: 1
Registered: November 2011
Junior Member
Hi, we have some problems with scoping in our DSL.
Here is our full grammar:
Configuration:
	(namespace = Namespace)
	//('import' Imports)*
	(elements += Element)*
;

Namespace:
	name = ID
;
/*
Imports:
	'import' ImportsDef (',' ImportsDef)* // Doesn't work!?
;

ImportsDef:
	imports += [Namespace]
;
*/	
Element:
	attributeDefinitions += AttributeDefinition
	| objectDefinitions += ObjectDefinition
;

AttributeDefinition:
	'*' name = ID '(' type = AttributeType ')'
	(translation += Translation)*
	(possibleValues += PossibleValues
	| defaultValue += DefaultValue
	| (internalProperties += InternalProperty)
	| ('-' (externalProperty += ExternalProperty)))*
;

AttributeReference:
	'*' name = [AttributeDefinition|ID]
	(attrTranslation += AttributeTranslation)*
	((overloadedProperties += InternalProperty)
	| ('-' (externalProperty += ExternalProperty)))*
;

PossibleValues:
	'=' (possibleValuesDefaultValue = [PossibleValuesValue|Type])? '(' values += PossibleValuesValue (',' values += PossibleValuesValue)* ')'
;
DefaultValue:
	'=' value = Type
;

PossibleValuesValue:
	name = Type
;

ObjectDefinition:
	'[' name = ID ']' (translation += Translation)*
	(('-' (externalProperty += ExternalProperty)+)
	//| (linkedAttributeDefinition += AttributeDefinition)
	| (referencedAttribute += AttributeReference))*
;

ExternalProperty:
	// AttributeInternalPropertyValue and ObjectAttributeInternalPropertyValue required otherwise we cant have external properties like 'required', 'readOnly' etc
	name = ExternalPropertyName ('=' value = Type)? // Not complete, need more information
;
ExternalPropertyName:
	(ID | InternalPropertyValue | AttributeInternalPropertyValue) ('.' LANGCODE)?
;

Translation:
	name = LANGCODE ':' value = STRING
;
AttributeTranslation:
	name = LANGCODE ':' value = STRING
;

/*
ExternalPropertyValue:
	
;
*/
InternalProperty:
	name = (AttributeInternalPropertyValue | InternalPropertyValue) ('=' value = Boolean)? 
;

InternalPropertyValue:
	'logged'
	| 'readOnly'
	| 'required'
	| 'indexed'
;

AttributeInternalPropertyValue:
	'multiValued'
	| 'protected'
;

Boolean:
	'true' 
	| 'false'
;

Type:
	STRING
	| '-'? INT
	| Boolean
;

AttributeType:
	'string'
	| 'double'
	| 'date'
	| 'long'
	| 'boolean'
	| 'objref'
;

terminal LANGCODE	: ('a'..'z')('a'..'z');


This is the code we are trying to run in our DSL:
demo

* valuta (double) sv:"valuta" en:"currency"
	required indexed readOnly
	= "fredag" ("måndag", "tisdag","onsdag", "torsdag", "fredag", "lördag" , "söndag")

* day (string) sv:"Dag" en:"Day"
	= "fredag" ("måndag", "tisdag","onsdag", "torsdag", "fredag", "lördag" , "söndag")

* name (string) sv:"Förnamn" en:"First name"
	required
	- fieldLength=14
	= 0

* attribute (long)
	= 1 (2, 4, 1, -2)

[object] // <----- ObjectDefinition
	- mailFromAddress="a_mail@adress.se"
	* valuta sv:"hej"  // <----- AttributeRefrence 
		logged // <----- This one....
	* day // <------ AttributeRefrence 
		logged // <----- collides with this one (error: Duplicate InternalProperty logged)
	* name
		required=false logged
	* attribute

[testObj] sv:"Ett test" en:"A test"
	- extAttr='någonting'
	- aTrueExtAttr
	* valuta sv:"PENGAR" en:"Money"


We think it's beacause all the AttributeRefrences shares the same scope (the scope of the ObjectDefinition).
How do we create a new scope for each AttributeReference?
Re: Scoping problem [message #754658 is a reply to message #754586] Thu, 03 November 2011 19:07 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

this is not so much a scoping but a naming problem (see e.g. the outline tree). The fully qualified names of both "logged" are identical. This is because the AttributeReference does not have a name.
You will say: "but it has a name-feature". True, but one that will not be used by default for naming, as it is a reference and not a "string"-datatype (hence not a good name for the feature).

You will have to adapt the qualified name provider. But beware, it is not a good idea to return the name of the referenced Attribute (by navigating there). This is because for navigating to the Attribute you will have to resolve the reference. Resolving references requires linking which is based on scoping which needs the names to be known already.
In your use case it might suffice to look up the ID used for referencing in the node model. NodeModelUtils.findNodesForFeature and LinkingHelper.getCrossRefNodeAsString might be useful.

Alex
Previous Topic:xtext-utils - where to put integration test data files?
Next Topic:left recursion problem
Goto Forum:
  


Current Time: Thu Apr 25 05:11:07 GMT 2024

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

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

Back to the top