Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Some questions about scoping and imports
Some questions about scoping and imports [message #805182] Thu, 23 February 2012 12:51 Go to next message
Jorn Hertsig is currently offline Jorn HertsigFriend
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) 

model second
item 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 #805221 is a reply to message #805182] Thu, 23 February 2012 14:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi how does your workflow look like?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Some questions about scoping and imports [message #805259 is a reply to message #805182] Thu, 23 February 2012 14:56 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

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
Previous Topic:EclipseCon is XtextCon!
Next Topic:Using Xtend without Xtext
Goto Forum:
  


Current Time: Fri Apr 19 16:28:31 GMT 2024

Powered by FUDForum. Page generated in 0.01791 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top