Some questions about scoping and imports [message #805182] |
Thu, 23 February 2012 12:51 |
Jorn Hertsig Messages: 3 Registered: February 2012 |
Junior Member |
|
|
I've got the following grammar:
Model:
'model' name = ID imports += Import* items += Item* rules += Rule*;
Import:
'import' importURI = STRING;
Rule:
'rule' name = ID '(' items += [Item]* ')';
Item:
'item' name = ID;
When opening the Xtext editor, all Item references in Rules are hilighted correctly if they are in the same file. However, that doesn't work if I try to import them from other files. For example:
model first
import "second.mydsl"
rule myRule (second)
Assuming these two files are in the same folder, it still won't find the 'second' reference from the imported file. It also doesn't work if I include the file extension for the imported file, or the full path.
How do I get Xtext to recognize the imported file?
[Updated on: Thu, 23 February 2012 12:51] Report message to a moderator
|
|
|
|
Re: Some questions about scoping and imports [message #805259 is a reply to message #805182] |
Thu, 23 February 2012 14:56 |
|
The Item has a qualified name computed from the containment hierarchy by default. Since your model has also a name, the name of an Item is prefixed by that.
mymodel.myitem
Now to reference an item from another model you need to be able to reference them by their qualified names. This is typically done by allow qualified names and/or use namespace imports.
This will make it work:
Model:
'model' name = ID imports += Import* items += Item* rules += Rule*;
Import:
'import' importURI = STRING;
Rule:
'rule' name = ID '(' items += [Item|QualifiedName]* ')';
Item:
'item' name = ID;
QualifiedName: ID ('.' ID)*;
model first
import "second.mydsl"
rule myRule second.second
Or you just drop the "name" attribute from the Model.
Regards,
~Karsten
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
|
|
|
Powered by
FUDForum. Page generated in 0.01791 seconds