Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Problem while cross-referencing. Solution review(Need review for the soltion to corss-referencing issue.)
Problem while cross-referencing. Solution review [message #976818] Thu, 08 November 2012 16:54 Go to next message
Eclipse UserFriend
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]
;
Re: Problem while cross-referencing. Solution review [message #976883 is a reply to message #976818] Thu, 08 November 2012 17:59 Go to previous messageGo to next message
Eclipse UserFriend
AbstractAttribute:
EAttribute | CAttribute
;

EAttribute:
eattribute=[entity::EntityAttribute|ID]
;

CAttribute:
cattribute=[entity::ComponentAttribute|ID]
;

=> The Grammar is ambigous since in both cases an ID is parsed. since the linking is done after parsing you have to make the grammar unambigous.
the best way is in deed to introduce a common supertype (besides changing the grammar regarding the syntax and introducing keywords.)

~Christian
Re: Problem while cross-referencing. Solution review [message #977664 is a reply to message #976883] Fri, 09 November 2012 08:21 Go to previous messageGo to next message
Eclipse UserFriend
Thanks.
Re: Problem while cross-referencing. Solution review [message #989431 is a reply to message #976818] Thu, 06 December 2012 03:26 Go to previous messageGo to next message
Eclipse UserFriend
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.
Problem while cross-referencing. Need a bit of help [message #989643 is a reply to message #976818] Fri, 07 December 2012 02:48 Go to previous messageGo to next message
Eclipse UserFriend
Any thoughts ?
Re: Problem while cross-referencing. Need a bit of help [message #989647 is a reply to message #989643] Fri, 07 December 2012 03:03 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

how does UPPER_CASE_ID look like? Maybe you can change this to ID and add a check for the upper case thing.
could be a bug in Xtext

~Christian
Re: Problem while cross-referencing. Need a bit of help [message #989675 is a reply to message #989647] Fri, 07 December 2012 04:44 Go to previous messageGo to next message
Eclipse UserFriend
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')*;

Re: Problem while cross-referencing. Need a bit of help [message #989681 is a reply to message #989675] Fri, 07 December 2012 04:50 Go to previous messageGo to next message
Eclipse UserFriend
Please file a ticket

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Problem while cross-referencing. Need a bit of help [message #989683 is a reply to message #989681] Fri, 07 December 2012 04:59 Go to previous messageGo to next message
Eclipse UserFriend
Sure.

[Updated on: Fri, 07 December 2012 05:05] by Moderator

Re: Problem while cross-referencing. Need a bit of help [message #989697 is a reply to message #989683] Fri, 07 December 2012 05:44 Go to previous message
Eclipse UserFriend
Please check - https://bugs.eclipse.org/bugs/show_bug.cgi?id=396030
Previous Topic:Bug parsing Xtext file
Next Topic:CharSequence inside while
Goto Forum:
  


Current Time: Wed Jul 23 09:59:50 EDT 2025

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

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

Back to the top