Problem while cross-referencing. Solution review [message #976818] |
Thu, 08 November 2012 16:54  |
Eclipse User |
|
|
|
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]
;
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.20783 seconds