Scope provider adaption [message #1835078] |
Tue, 24 November 2020 12:07  |
Alexandra Tritean 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 #1835084 is a reply to message #1835080] |
Tue, 24 November 2020 13:24   |
Alexandra Tritean 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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02468 seconds