Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 21:54 Go to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior 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]
;


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Problem while cross-referencing. Solution review [message #976883 is a reply to message #976818] Thu, 08 November 2012 22:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem while cross-referencing. Solution review [message #977664 is a reply to message #976883] Fri, 09 November 2012 13:21 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Thanks.

Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Problem while cross-referencing. Solution review [message #989431 is a reply to message #976818] Thu, 06 December 2012 08:26 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior 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.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Problem while cross-referencing. Need a bit of help [message #989643 is a reply to message #976818] Fri, 07 December 2012 07:48 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Any thoughts ?

Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Problem while cross-referencing. Need a bit of help [message #989647 is a reply to message #989643] Fri, 07 December 2012 08:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem while cross-referencing. Need a bit of help [message #989675 is a reply to message #989647] Fri, 07 December 2012 09:44 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior 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')*;



Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Problem while cross-referencing. Need a bit of help [message #989681 is a reply to message #989675] Fri, 07 December 2012 09:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem while cross-referencing. Need a bit of help [message #989683 is a reply to message #989681] Fri, 07 December 2012 09:59 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Sure.

Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj

[Updated on: Fri, 07 December 2012 10:05]

Report message to a moderator

Re: Problem while cross-referencing. Need a bit of help [message #989697 is a reply to message #989683] Fri, 07 December 2012 10:44 Go to previous message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Please check - https://bugs.eclipse.org/bugs/show_bug.cgi?id=396030

Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Previous Topic:Bug parsing Xtext file
Next Topic:CharSequence inside while
Goto Forum:
  


Current Time: Tue Apr 16 17:10:08 GMT 2024

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

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

Back to the top