Xtext DSL Context Setting

I know that there is a simple solution for this , but I have no idea how to implement it.

I am looking for how to implement an answer, not what I need to do. Half the answer is already on this page: Cross-references and the Xtext scope

My problem is with the grammar below:

DomainModel: "DOMAINMODEL" name=ID "{" "ENTITYS" "{" (Entitys+=Entity)* "}" "ENTITY_RELATIONSHIP" "{" (Relationships+=Relationship)* "}" "}"; Entity: name=ID "{" (Attributes+=Attribute)* "}"; Attribute: StringAttribute | NumberAttribute | ImageAttribute; StringAttribute: "STRING" name=ID; NumberAttribute: "NUMBER" name=ID; ImageAttribute: "IMAGE" name=ID; // Relationship = [new table name] : [shared key name] -> ref_table(ref_id) Relationship: name=ID ":" newEntityName=ID "->" refEntityName=[Entity|ID]"("refName=[Attribute|ID]")"; // <- Problem here 

When I write a model, I cannot get "refName = [Attribute | ID]" to refer to attributes inside the object. In the code below

 DOMAINMODEL auctionHouse{ ENTITYS { lots{ NUMBER id0 NUMBER lotNo STRING name STRING priceEstimate STRING description } auctions{ NUMBER id1 NUMBER date STRING description } auction_lots{ NUMBER id2 STRING lot_id NUMBER auction_id } } ENTITY_RELATIONSHIP { auction_lots : lot_id -> lots(id0) // <- Will not find 'id0' auction_lots : auction_id -> auctions(id1) // <- Will not find 'id1' } } 

How can I expand the scope? How can I distinguish two attributes with the same name, but in different areas?

+4
source share
1 answer

The problem with links is that they simply cannot be found in this area, what you can do is enter a qualified name and use this in your cross-reference and change your grammar accordingly, i.e.: -

 QualifiedName: ID ('.' ID)*; Relationship: name=ID ":" newEntityName=ID "->" refName=[Attribute|QualifiedName]; 

Now you need to be able to refer using a qualified identifier:

 ENTITY_RELATIONSHIP { auction_lots : lot_id -> auctionHouse.lots.id0 auction_lots : auction_id -> auctionHouse.auctions.id1 } 

If you cannot change the grammar like this to use the default method that Xtext processes names, then you will need to look for your own qualified names in yourself, a great article for this: Articles with qualifying names

+5
source

All Articles