Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using Names from a text file inside the DSL
Using Names from a text file inside the DSL [message #1733233] Wed, 25 May 2016 15:29 Go to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
Hi everyone,

I have a text file with some pairs, for example:
ABC, 123
DEF, 456
GHI, 789

I want to write a DSL more or less like this:
"given the element ABC I want to go to element 123"

So, I want that the DSL give the left option from my text file (ABC, DEF, GHI), then if I use the ABC then the DSL should show the correct right option 123 is the element to be chosen.

Is there a way to do this?? The text file will not change when the DSL is executed.

Best regards
Re: Using Names from a text file inside the DSL [message #1733235 is a reply to message #1733233] Wed, 25 May 2016 15:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13193
Registered: July 2009
Senior Member
you have basically two options:

- make a dsl for the text file and have cross references from your stuff to the text file
- adapt validation and contentassist to validate and propose these values


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using Names from a text file inside the DSL [message #1733248 is a reply to message #1733235] Wed, 25 May 2016 16:47 Go to previous messageGo to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
Thanks for the reply!

Thinking at the "other DSL" option I have two question:
- How can I read the .txt to have access to the info?
- Or maybe is better to define a simple DSL .myTxt (for example) similar to the txt file? In this case I would not generate the .txt anymore, but instead I would generate the .myTxt file and use it in the main DSL.


I'm looking to this as an example of how use one DSL into another: https://christiandietrich.wordpress.com/2012/08/07/xtext-referencing-elements-of-one-dsl-from-another-dsl/
Re: Using Names from a text file inside the DSL [message #1733251 is a reply to message #1733248] Wed, 25 May 2016 17:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13193
Registered: July 2009
Senior Member
Yes i meant the Or Part.

Please note with xtext 2.9 you don't need to do the register parts in
the standalone setup
Instead add a referencedResource=".......yourdsl.genmodel" to the workflow 


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using Names from a text file inside the DSL [message #1733256 is a reply to message #1733251] Wed, 25 May 2016 18:07 Go to previous messageGo to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
Thanks Christian!
Re: Using Names from a text file inside the DSL [message #1733346 is a reply to message #1733256] Thu, 26 May 2016 17:11 Go to previous messageGo to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
Hi Christian,

I tested and everything works fine.
But when I tried to put the Mapping DSL (the one that was a txt file) into the Main DSL I have this situation: I already have a referencedResource (a EMF model that I created to be the scaffold for my DSL). How can I put a second referencedResource?

UPDATE:
I already repeat the referencedResource.
So I have
referencedResource="myEMFModel/model.genmodel"
referencedResource="MyMappingDSL/mapping.genmodel"

No error message here.

The problem is when I try to use an element from Mapping DSL into Main DSL

grammar br.traceability.dsl.MyTrace with org.eclipse.xtext.common.Terminals

import "platform:/resource/br.traceability.model/model/model.ecore"
import "http://www.traceability.br/mapping/dsl/Mapping" as map

FormalResults:
	'FormalResults' name=ID '{'
		timenodes+=TimeNode (',' timenodes+=TimeNode)*
	'}'
;

TimeNode:
	'TimeNode' name=ID '{'
		formalelement+=FormalElement (',' formalelement+=FormalElement)*
	'}'
;

FormalElement:
	'FormalElement' formalElement=[map::FormalElement] '{'
		// element=Element
	'}'
;


Error message at formalElement=[map::FormalElement]: "Cannot find compatible feature formalElement in sealed EClass FormalElement from imported package http://www.example.org/model: The type 'FormalElement' does not have a feature 'formalElement'."

In the EMF Model, the FormalElement is a EClass without attributes.

[Updated on: Thu, 26 May 2016 17:40]

Report message to a moderator

Re: Using Names from a text file inside the DSL [message #1733351 is a reply to message #1733346] Thu, 26 May 2016 17:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13193
Registered: July 2009
Senior Member
I dont get that Point you can add multiple referenced resources

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using Names from a text file inside the DSL [message #1733378 is a reply to message #1733351] Fri, 27 May 2016 05:47 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13193
Registered: July 2009
Senior Member
Hard to Say what's the problem
But importing the meta model via platform resource sound suspicious

Then: how does the Ecore for FormalElement look like


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:xtext.createEditor issue by using orion codeEdit plugin
Next Topic:Parse a text with selfdescribing rules
Goto Forum:
  


Current Time: Mon Nov 18 04:25:49 GMT 2019

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

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

Back to the top