Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » importURI and importNamespace
importURI and importNamespace [message #818907] Mon, 12 March 2012 09:09 Go to next message
Stefano Zanotti is currently offline Stefano ZanottiFriend
Messages: 22
Registered: March 2012
Junior Member
I have to import an external file, to solve cross-references, but I can't get it working.
I tried both importURI and importNamespace, changing the relative fragments in the workflow but:
with importURI, I get 'imported resource could not be found'.
with importNamespace, I get no errors on my import statement, but I get 'couldn't resolve reference' on my references.

How to get them right?

And, what's the correct syntax for the imported resource and the references?
From what I understand, references needn't be qualified names.
For resources, they can/must be java-like package names, URIs (including "platform:/..."?), absolute/relative paths?
Re: importURI and importNamespace [message #819288 is a reply to message #818907] Mon, 12 March 2012 18:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13409
Registered: July 2009
Senior Member
Hi,

have no idea why this is not working for you. a example grammar + model file would have been helpful to give specific advice.

(1)

Model:
	imports+=Import*
	modules+=Module*;
	
Import:
	'import' importedNamespace=FQNWC
;	

FQNWC:
	FQN '.*'
;

FQN: ID ("." ID)*;
	
Module:
	'module' name=ID '{'
		element+=Element*
	'}';
	
	
Element:
	'element' name=ID ('refs' refs=[Element])?
;


      // scoping and exporting API
            // fragment = scoping.ImportURIScopingFragment {}
            // fragment = exporting.SimpleNamesFragment {}

            // scoping and exporting API
            fragment = scoping.ImportNamespacesScopingFragment {}
            fragment = exporting.QualifiedNamesFragment {}
            fragment = builder.BuilderIntegrationFragment {}


test.mydsl
import other.*
import third.*
module test {
	element A refs Other
	element B refs Third
}

other.mydsl
module other {
	element Other
}

third.mydsl
module third {
	element Third
}


(2)

Model:
	imports+=Import*
	modules+=Module*;
	
Import:
	'import' importURI=STRING
;	
	
Module:
	'module' name=ID '{'
		element+=Element*
	'}';
	
	
Element:
	'element' name=ID ('refs' refs=[Element])?
;


            // scoping and exporting API
             fragment = scoping.ImportURIScopingFragment {}
             fragment = exporting.SimpleNamesFragment {}

            // scoping and exporting API
//            fragment = scoping.ImportNamespacesScopingFragment {}
//            fragment = exporting.QualifiedNamesFragment {}
//            fragment = builder.BuilderIntegrationFragment {}
//fragment = types.TypesGeneratorFragment {}


test.mydsl
import "other.mydsl"
Hi,

have no idea why this is not working for you. a example grammar + model file would have been helpful to give specific advice.

(1)

[code]Model:
	imports+=Import*
	modules+=Module*;
	
Import:
	'import' importedNamespace=FQNWC
;	

FQNWC:
	FQN '.*'
;

FQN: ID ("." ID)*;
	
Module:
	'module' name=ID '{'
		element+=Element*
	'}';
	
	
Element:
	'element' name=ID ('refs' refs=[Element])?
;[/code]

[code]      // scoping and exporting API
            // fragment = scoping.ImportURIScopingFragment {}
            // fragment = exporting.SimpleNamesFragment {}

            // scoping and exporting API
            fragment = scoping.ImportNamespacesScopingFragment {}
            fragment = exporting.QualifiedNamesFragment {}
            fragment = builder.BuilderIntegrationFragment {}[/code]

test.mydsl			
[code]import other.*
import third.*
module test {
	element A refs Other
	element B refs Third
}[/code]
other.mydsl
[code]module other {
	element Other
}[/code]
third.mydsl
[code]module third {
	element Third
}[/code]

(2)

[code]
Model:
	imports+=Import*
	modules+=Module*;
	
Import:
	'import' importURI=STRING
;	
	
Module:
	'module' name=ID '{'
		element+=Element*
	'}';
	
	
Element:
	'element' name=ID ('refs' refs=[Element])?
;
[/code]

[code]            // scoping and exporting API
             fragment = scoping.ImportURIScopingFragment {}
             fragment = exporting.SimpleNamesFragment {}

            // scoping and exporting API
//            fragment = scoping.ImportNamespacesScopingFragment {}
//            fragment = exporting.QualifiedNamesFragment {}
//            fragment = builder.BuilderIntegrationFragment {}
//fragment = types.TypesGeneratorFragment {}
[/code]

test.mydsl			
[code]import "other.mydsl"
import "platform:/resource/lala/src/test/third.mydsl3"
module test {
	element A refs Other
	element B refs Third
}[/code]
other.mydsl
[code]module other {
	element Other
}[/code]
third.mydsl
[code]module third {
	element Third
}[/code]

~Christian
module test {
	element A refs Other
	element B refs Third
}

other.mydsl
module other {
	element Other
}

third.mydsl
module third {
	element Third
}


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI and importNamespace [message #819685 is a reply to message #819288] Tue, 13 March 2012 07:39 Go to previous messageGo to next message
Stefano Zanotti is currently offline Stefano ZanottiFriend
Messages: 22
Registered: March 2012
Junior Member
Hi Christian, I didn't post my own example because I'm still stuck with the understanding of how imports work, so I don't know if it's my grammar that's problematic or it's just me not knowing how to do what I need.

Your example works for me, too. Now I think there's something automagical in the imports, which I just can't get. For namespaces: by importing other.*, what am I importing? Does Xtext look for an element named 'other'? Must it be the axiom of the grammar or can it be anything? And with other.xxx, must 'xxx' be an EAttribute with name 'name', placed inside the entity named 'other'? Can 'xxx' be an entity indirectly reachable from 'other' (i.e. via numerous references/attributes)? What does Xtext look for with '*': anything with a 'name', or just some of these entities?

I'm trying to build upon your example, but such insights would be very useful.

Thanks

P.S. if I reference an entity using a qualified id, will the same automagic happen (e.g. using 'other.Other' there would be no more need of 'import other.*')?
Is there some constraint like "the filename must match the name of its main entity"?

[Updated on: Tue, 13 March 2012 07:42]

Report message to a moderator

Re: importURI and importNamespace [message #819691 is a reply to message #819685] Tue, 13 March 2012 07:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13409
Registered: July 2009
Senior Member
Hi it is all about name spaces (IQualifiedNameProvider) and importing
them (make element with a long Qualified name a.b.c.d available under
a shorter one e.g import a.b.* leads to c.d


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI and importNamespace [message #819815 is a reply to message #819691] Tue, 13 March 2012 10:57 Go to previous message
Stefano Zanotti is currently offline Stefano ZanottiFriend
Messages: 22
Registered: March 2012
Junior Member
The problem was that I hadn't performed a build on my project.
The build is not necessary when using the importURI version.

[Updated on: Tue, 13 March 2012 10:58]

Report message to a moderator

Previous Topic:SetExpressions: Lists and Ranges
Next Topic:problem with 2.0->2.1 update
Goto Forum:
  


Current Time: Sun Mar 29 13:18:34 GMT 2020

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

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

Back to the top