1
votes

I am making a very simple DSL with xtext. A project will contain files that either define a message name, or reference to one. I have included a simplified example:

Grammar:

Model:
    statements+=(MessageDefinition | MessageUsage)*;
MessageDefinition:
    '[MESSAGE_DEF]' name=ID;
MessageUsage:
    '[MESSAGE_USAGE]' usage=[MessageDefinition];

File1.ex:

[MESSAGE_DEF] EXAMPLE_1
[MESSAGE_DEF] EXAMPLE_2
[MESSAGE_USAGE] EXAMPLE_1

File2.ex:

[MESSAGE_USAGE] EXAMPLE_2

In this example the cross-reference from EXAMPLE_1 works such that "Open Declaration" on the usage takes me to the definition. However, the cross-reference on EXAMPLE_2 does not work. I think the default scoping rules prevents different files from sharing references.

What do i need to add so that all the files in a project share the same global scope for cross-references?

Additional information:

  • The option "Build Automatically" is enabled in the runtime project.
  • The .project file includes a buildCommand for xtextBuilder and a nature for xtextNature.
  • I am only attempting to use the IDE cross-referencing functionality, there is no generation of code.
  • All of the files in the runtime project exist in the same folder.

The project was created using "Xtext Project" in the standard wizard, I have only edited the grammar from the pre-generated code, everything else is as-per the defaults. I thought I would need to add some custom scoping behaviour/rules to load all files into the global scope, but I am not sure how this is supposed to be done?

1
Where do you specify the scoping/name resolution rules, that allow Xtext to know that the identifier EXAMPLE_2 in file2 refers to the definition of EXAMPLE_2 in file1? In general, languages have arbitrary scoping rules (witness C++, with 600 pages in the reference manual devoted partly to this). A grammar tells you NOTHING about scoping rules. - Ira Baxter
Ira I understand your point and agree. I have not modified the scoping rules from the xtext defaults. What I do not understand is how to configure xtext so that every definition in every file in the project is automatically in the same scope. - Owen

1 Answers

2
votes

it will work fine with your grammar and scoping if you

  1. have build automatically enabled in your runtime workspace
  2. the project you model in has xtext nature and xtext builder enabled (right-click -> configure -> ...)
  3. if it is a java project model files have to reside in a source folder or a package within the source folder