| Problem while cross-referencing. Solution review [message #976818] |
Thu, 08 November 2012 16:54  |
Neeraj Bhusare Messages: 84 Registered: July 2009 Location: India |
Member |
|
|
Hi,
In the following DSL, while cross-referencing an Entity/Component attribute [0], I see the error - "Couldn't resolve reference to AbstractAttribute entity_attribute".
Adding rule [1] in the Entity DSL and then referencing the same in the Function DSL [2] fixed the above issue. However, I am not sure if the solution is correct. Could someone please review the same. Also, please recommend if there is a better solution.
[0]
def MyFunction(param1:MyEntity) {
param1.entity_attribute // error - couldn't resolve reference to
// AbstractAttribute entity_attribute
}
[1]
AbstractAttributes:
EntityAttribute | ComponentAttribute
;
[2]
AttributeReference:
'.' attribute=[entity::AbstractAttributes]
;
---------------------------Entity DSL -------------------------------
grammar org.example.xtext.entity.dsl.EntityDSL with org.eclipse.xtext.common.Terminals
generate entityDSL "http://www.example.org/xtext/entity/dsl/EntityDSL"
Model:
//...namespace and import
entities+=AbstractEntity*
;
//...QName, QNameWithWildcard and Import rules...
AbstractEntity:
Entity | Component
;
Entity:
'entity' name=ID '{'
attributes+=EntityAttribute*
'}'
;
EntityAttribute:
'attribute' name=ID
;
Component:
'component' name=ID '{'
attributes+=ComponentAttribute*
'}'
;
ComponentAttribute:
'component-attribute' name=ID
;
-----------------------Function DSL -------------------------------
grammar org.example.xtext.function.dsl.FunctionDSL with org.eclipse.xtext.common.Terminals
generate functionDSL "http://www.example.org/xtext/function/dsl/FunctionDSL"
import "http://www.example.org/xtext/entity/dsl/EntityDSL" as entity
Model:
//...namespace and import
functions+=Function*;
//...QName, QNameWithWildcard and Import rules...
Function:
'func' name=ID '('parameters+=Parameter (',' parameters+=Parameter)* ')' '{'
body += Body (';' body += Body)*
'}'
;
Body:
object=[Parameter] tail=AttributeReference?
;
Parameter:
name=ID ':' type=[entity::AbstractEntity]
;
AttributeReference:
'.' attribute=[AbstractAttribute]
;
AbstractAttribute:
EAttribute | CAttribute
;
EAttribute:
eattribute=[entity::EntityAttribute]
;
CAttribute:
cattribute=[entity::ComponentAttribute]
;
Best regards, Neeraj
|
|
|
|
|
| Re: Problem while cross-referencing. Solution review [message #989431 is a reply to message #976818] |
Thu, 06 December 2012 03:26   |
Neeraj Bhusare Messages: 84 Registered: July 2009 Location: India |
Member |
|
|
The above grammar was a simplified version of the original DSL that unfortunately I couldn't publish. The solution worked well in the above DSL, however after trying a similar solution in the original DSL, I see the error - There may not be two features named 'name'. In the rules that represent the attributes (XAttributeElements below), "name=ID and name=UPPER_CASE_ID" gets highlighted with error. Even the common rule "AbstractAttributeRef" shows the same error. I don't think I have seen this error before. I looked through the forum, but didn't find much help. Any idea what might be going wrong ?
I can't publish the complete DSL, however I am sharing a snippet if it helps.
AttributeElement:
attribute='attribute' name=ID (isArray?=Array)? ':'(attributeDataType=DataType | referencedEntity=[Entity]) attributeFeatures=AttributeFeatures
;
ComponentAttributeElement:
attribute='attribute' name=ID (isArray?=Array)? ':'(attributeDataType=DataType | referencedComponent=[ComponentEntity]) attributeFeatures=AttributeFeatures
;
EnumAttributeElement:
attribute='attribute' name=ID (isArray?=Array)? ':'(attributeDataType=DataType | referencedEnum=[EnumEntity]) attributeFeatures=AttributeFeatures
;
EnumValueElement:
'enum-value' name=UPPER_CASE_ID '(' (enumValues+=EnumAttributeElementValue)? (',' enumValues+=EnumAttributeElementValue)* ')';
/* New Rule added to the original DSL */
AbstractAttributeRef:
AttributeElement | EnumAttributeElement | EnumValueElement | ComponentAttributeElement
;
Thanks in advance.
Best regards, Neeraj
|
|
|
|
|
| Re: Problem while cross-referencing. Need a bit of help [message #989675 is a reply to message #989647] |
Fri, 07 December 2012 04:44   |
Neeraj Bhusare Messages: 84 Registered: July 2009 Location: India |
Member |
|
|
Changing the UPPER_CASE_ID to ID didn't help. Please find below the terminal rule for UPPER_CASE_ID. I understand that the below rule shadows the terminal rule ID in some cases. Now sure if this could be causing the error.
terminal UPPER_CASE_ID : '^'?('A'..'Z'|'_') ('A'..'Z'|'_'|'0'..'9')*;
Best regards, Neeraj
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01951 seconds