Problem while cross-referencing. Solution review [message #976818] |
Thu, 08 November 2012 21:54 |
Neeraj Bhusare 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 |
|
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
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05307 seconds