Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scope provider adaption
Scope provider adaption [message #1835078] Tue, 24 November 2020 12:07 Go to next message
Alexandra Tritean is currently offline Alexandra TriteanFriend
Messages: 37
Registered: March 2020
Member
Hello,

I have the following DSL grammar. Please ignore the parts that are not defined in this snippet because they are not relevant in this context.

Context:
	(documentation=ML_DOC_COMMENT)? 
	'context' name=CTXT_FQN ('extends' parentContext=[Context|CTXT_FQN] )? ('countryCode' countryCode=STRING )? '{' 
	('data-dictionary' '{'
	attributes+=(Attribute)*
	'}')?
	('entity-catalog' '{'
	entities+=Entity*
	'}')?
	('list-values' '{'
	listValues+=ListValue*
	'}')?
	'}';

Attribute:
	AttributeSimpleType | AttributeEntityType 
;

AttributeEntityType:
	(documentation=ML_DOC_COMMENT)? 
	name=ID (type=[Entity|GENERAL_FQN]|type=[Entity|ID]) funcName=STRING (desc=STRING)? (labels = Labels)? (deprecated?='deprecated')? ';';

Entity:
	(documentation=ML_DOC_COMMENT)? 
	type=('business' | 'static' | 'system' | 'lookup')? name=ID funcName=STRING (desc=STRING)? (labels = Labels)? ('extends' parentEntity=[Entity|GENERAL_FQN])? (deprecated?='deprecated')? '{'
	features+=(Feature)*
	('data' '{'
	data+=DataValue ( "," data+=DataValue)* 
	'}'
	)?
	'}';

Feature:
	(documentation=ML_DOC_COMMENT)? 
	(type=FeatureAttributeType | type=FeatureEntityType)
	;

FeatureAttributeType:
	(type=[AttributeSimpleType|ID]|type=[AttributeSimpleType|GENERAL_FQN]) ('constrained' (lookup=[ListValue|ID]|lookup=[ListValue|GENERAL_FQN]) | 'references' refType=[Entity])?;

	
ListValue:
	(documentation=ML_DOC_COMMENT)?
	name=ID funcName=STRING (desc=STRING)? (deprecated?='deprecated')? type=(ListValueInt | ListValueString | ListValueFloat) 
;

terminal VERSION:
    INT '.' INT '.' INT ;

terminal CTXT_FQN:
    ID '-' VERSION ;

terminal GENERAL_FQN:
	CTXT_FQN'.'ID;


And the following snippet of the scope provider.

if (reference == ePackage.entity_ParentEntity && context instanceof Entity){
    val entity=context as Entity;
    return scopeForParentEntity(entity,context,reference)
}	
if(reference == ePackage.attributeEntityType_Type && context instanceof Context){
    return scopeForAttributeParentEntity(context,reference)
}
if( (reference == ePackage.featureAttributeType_Type || reference == ePackage.featureEntityType_Attribute) && context instanceof Entity){
    return scopeForFeature(context,reference)
}
if (reference == ePackage.featureAttributeType_Lookup && context instanceof FeatureAttributeType){
    return scopeForLookup(context,reference)
}

def protected IScope scopeForParentEntity(Entity entity,EObject context, EReference reference){
	val container=entity.eContainer as Context;
	val List<Entity> entities=newArrayList;
	setEntities(container, entities);
	return Scopes::scopeFor(entities.filter[e | e.type.nullOrEmpty || e.type.equals("business")], [QualifiedName.create((it.eContainer as Context).name.split("\\.")).append(it.name)],IScope.NULLSCOPE);
}

def protected IScope scopeForAttributeParentEntity(EObject context, EReference reference){
	val List<Entity> entities=newArrayList;
	val container = context as Context
	setEntities(container, entities);
	return Scopes::scopeFor(entities, [QualifiedName.create((it.eContainer as Context).name.split("\\.")).append(it.name)],IScope.NULLSCOPE)
}

def protected void setEntities(Context context, List<Entity> entities){
	entities.addAll(context.entities);
	if(context.parentContext !== null && !context.getName.equals(context.parentContext.getName)){
		setEntities(context.parentContext,entities);
}
}
	
def protected IScope scopeForFeature(EObject context, EReference reference){
	val List<Attribute> attributes=newArrayList;
	val container = context.eContainer as Context
	setFeatures(container, attributes);
	return Scopes::scopeFor(attributes, [QualifiedName.create((it.eContainer as Context).name.split("\\.")).append(it.name)],IScope.NULLSCOPE);
}
	
def protected void setFeatures(Context context, List<Attribute> attributes){
	attributes.addAll(context.attributes);
	if(context.parentContext !== null && !context.getName.equals(context.parentContext.getName)){
		setFeatures(context.parentContext,attributes);
	}
}
	
def protected IScope scopeForLookup(EObject context, EReference reference){
	val List<ListValue> listsOfValues=newArrayList;
	val container = context.eContainer.eContainer.eContainer as Context
	setListsOfValues(container, listsOfValues);
	return Scopes::scopeFor(listsOfValues, [QualifiedName.create((it.eContainer as Context).name.split("\\.")).append(it.name)],IScope.NULLSCOPE);
}
	
def protected void setListsOfValues(Context context, List<ListValue> listsOfValues){
	listsOfValues.addAll(context.listValues);
	if(context.parentContext !== null && !context.getName.equals(context.parentContext.getName)){
		setListsOfValues(context.parentContext,listsOfValues);
	}
}


All good until now. Everything works like expected.

Now, I want to update my grammar to allow until 4 digits in the version (the fourth one will be optional).
Therefore, I updated my grammar with
terminal VERSION:
INT '.' INT '.' INT ('.' INT)?;

The problem is that since this change in the version, the scope provider works as expected when using a version with 4 digits, but it doesn't work anymore when using a version with 3 digits.
The error that I'm getting everywhere is
'required (...)+ loop did not match anything at character ...'.

I don't understand why this change has an impact in the scope provider and how I can correct the behavior. Any suggestions?

Thank you!

Kind regards,
Alexandra
Re: Scope provider adaption [message #1835080 is a reply to message #1835078] Tue, 24 November 2020 12:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The error that I'm getting everywhere is
'required (...)+ loop did not match anything at character ...'.

is not a scope provider problem. its a grammar problem.

in this case you should debug
the lexers

nexttoken

to find out what is actually logged

also check workflows log for warnings/errors


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 24 November 2020 12:25]

Report message to a moderator

Re: Scope provider adaption [message #1835084 is a reply to message #1835080] Tue, 24 November 2020 13:24 Go to previous messageGo to next message
Alexandra Tritean is currently offline Alexandra TriteanFriend
Messages: 37
Registered: March 2020
Member
Hello,

Thank you for the hint. I think I understand now what is going on.

Having the following:

context Base_Context-1.0.0 {

data-dictionary {
identifierAtrr integer 'identifierAtrr' "Description";
}

entity-catalog {

Party 'Party' {
identifierAtrr constrained Base_Context-1.0.0.ProductCode;
}
}


list-values {

ProductCode 'ProductCode' integer values {
( 1 , 'Value1' , 'Value1' ) ,
( 2 , 'Value2' , 'Value2' )
}

}
}

When it gets to Base_Context-1.0.0.ProductCode , I think it interprets 'ProductCode' as being the 4th possible digit of the version. Can this be avoided somehow?

Thank you!

Kind Regards,

Alexandra

[Updated on: Tue, 24 November 2020 13:34]

Report message to a moderator

Re: Scope provider adaption [message #1835090 is a reply to message #1835084] Tue, 24 November 2020 15:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you please provide a minimal complete hello world grammar and unit test showing the problem?

please also check about the concept of datatype rules.
the stuff you have as terminal

terminal CTXT_FQN:
ID '-' VERSION ;

terminal GENERAL_FQN:
CTXT_FQN'.'ID;

is ususally done as datatype rule

CTXT_FQN hidden():
ID '-' VERSION ;

GENERAL_FQN hidden():
CTXT_FQN'.'ID;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope provider adaption [message #1835117 is a reply to message #1835090] Wed, 25 November 2020 05:17 Go to previous messageGo to next message
Alexandra Tritean is currently offline Alexandra TriteanFriend
Messages: 37
Registered: March 2020
Member
I attached a minimal example. I hope it will be clear for you.

Thank you for the help.

Kind Regards,

Alexandra
Re: Scope provider adaption [message #1835119 is a reply to message #1835117] Wed, 25 November 2020 07:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
antlr lexers are greedy. i dont have time to debug if you somehow can circumvent it.
as stated before. using datatype rules solves the problem

VERSION hidden():
INT '.' INT '.' INT ('.' INT)?
;

CTXT_FQN hidden():
ID '-' VERSION ;

GENERAL_FQN hidden():
CTXT_FQN'.'ID;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope provider adaption [message #1835125 is a reply to message #1835119] Wed, 25 November 2020 08:37 Go to previous message
Alexandra Tritean is currently offline Alexandra TriteanFriend
Messages: 37
Registered: March 2020
Member
That indeed works. I had to use datatype rules also in other places (I had a FLOAT terminal). Nice advice. :)

Thank you very much for your time and help!

Kind Regards,

Alexandra
Previous Topic:Defining long in xtext and expecting rule_long error
Next Topic:HOTs in Xtend
Goto Forum:
  


Current Time: Wed Apr 24 16:55:28 GMT 2024

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

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

Back to the top