Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Correct usage of 'import'/'include' of files
Correct usage of 'import'/'include' of files [message #1761051] Fri, 05 May 2017 17:13 Go to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
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 #1763590 is a reply to message #1761051] Wed, 17 May 2017 16:57 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Hi,

I understand that the question is probably too wide.
I am attaching an example project that uses ImportURI mechanism. Would it be possible for you to advise on correct way to achieve the same functionality by using the recommended ImportedNamespace referencing?

The attachment consists of two files: mydsl.zip - slightly modified started project; test.zip - shows example usage of the grammar.

Thank you,
Serge
  • Attachment: mydsl.zip
    (Size: 1.65MB, Downloaded 74 times)
  • Attachment: test.zip
    (Size: 0.95KB, Downloaded 78 times)
Re: Correct usage of 'import'/'include' of files [message #1763591 is a reply to message #1763590] Wed, 17 May 2017 17:05 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
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)
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:Creating hyperlinks in Xtext
Next Topic:Cannot be resolved
Goto Forum:
  


Current Time: Fri Dec 13 15:45:47 GMT 2024

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

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

Back to the top