问题
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.
- 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.
- 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