importURI and importNamespace [message #818907] |
Mon, 12 March 2012 09:09 |
Stefano Zanotti 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 |
|
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
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 |
Stefano Zanotti 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01798 seconds