Xtext cross referencing and scoping

廉价感情. 提交于 2020-01-02 19:13:06

问题


I have some problems with xtext cross referencing Here is a very simple grammer:

grammar org.xtext.example.mydsl1.Test with org.eclipse.xtext.common.Terminals
generate test "http://www.xtext.org/example/mydsl1/Test"
Model: block=Block? cs+=Company* ; 
Block:  '{' g=[Employee] '}';
Company: 'Company' name=ID
    '{' es+= Employee* '}';
Employee: 'Employee' name=ID ';' ;

and it is my dsl :

{ Pooyan }
Company Sony{
    Employee Pooyan;
    Employee John;
}

It always shown that "Couldn't resolve reference to Employee 'Pooyan'." Could anyone please help me? I have no idea...


回答1:


The fully qualified name of Pooyan is Sony.Pooyan. Since the cross reference 'g' in your block is defined in another contain, you have to do a minor customizing to put it onto the scope.

  1. If your language always uses a flat namespace, you could enable the SimpleNamesFragment in the language generator and remove the QualifiedNamesFragment. This should do the trick.
  2. Alternatively, you could customize the scoping for the concrete reference 'g' in your scope provider.



回答2:


Adding to Sebastians' answer to make it more precise: you need to change "fragment = exporting.QualifiedNamesFragment auto-inject {}" to "fragment = exporting.SimpleNamesFragment" in the corresponding .mwe2 file of your xtext project.

Hope this helps.



来源:https://stackoverflow.com/questions/11693120/xtext-cross-referencing-and-scoping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!