Correct usage of 'import'/'include' of files [message #1761051] |
Fri, 05 May 2017 13:13  |
Eclipse User |
|
|
|
Hi,
I am trying to implement a grammar used for some configuration files in generic Eclipse projects. It means that the search mechanisms like classpath and/or package dependency are not relevant. It is desirable to avoid using of Xtext project nature as well.
The configuration files may use other files located inside the same generic project or be provided as a "library" which is supplied together with Xtext support plugin. Files that exist, but, are not mentioned in the main script, should not be considered.
The following grammar implements 'use' keyword. (I intentionally trying to avoid 'import' or 'include' words for the purpose of explaining its desired behavior later).
Model:
(greetings+=Greeting | users+=User | uses+=Use)*;
Use:
'use' importedNamespace=ID;
Greeting:
'Hello' name=[User] '!';
User:
'user' name=ID ('age' '=' age=INT)?;
When the 'use' keyword is used, the corresponding file name (ID) is supposed to be decorated with appropriate file extension and looked in: 1. The same project location where the main script is located; 2. Library location within Xtext plugin resource.
I have two questions:
- As 'importUri' is discouraged or even deprecated, is it possible to implement the desired behavior by using 'importedNamespace'? If so, is there an example around?
- Should I use double parsing of the main script? the first pass will figure out the used 'use' keywords, add corresponding files to the global index and will build the correct EMF model at the second parse
|
|
|
|
Re: Correct usage of 'import'/'include' of files [message #1763591 is a reply to message #1763590] |
Wed, 17 May 2017 13:05  |
Eclipse User |
|
|
|
well the basic problem is: import uri and import namespace use the index. you dont want to use the index => we are out.
if you dare to use the index.
adapt the nameprovider of the dsl to encode the files uri inside resource resources names
e.g.
Use:
'use' model=[Model|FQN];
and
QualifiedName qualifiedName(Model model) {
val uri = model.eResource.getURI()
....
return QualifiedName.create(part1, ...., partn)
}
|
|
|
Powered by
FUDForum. Page generated in 0.02950 seconds