Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » creating objects in the EMF
icon5.gif  creating objects in the EMF [message #1727099] Fri, 18 March 2016 23:17 Go to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
Hello,

I need to create certain objects in the EMF when another objects are created. i.e if in my language I can declare a variable as an array of integers, then after this variable is declared I need to create a toString procedure in my language that takes an array of integers. So, when the user writes after that toString(myArray), he finds the toString procedure already declared for him implicitly.

a sample for the grammar :
defs:
declarations+=variables+
;
variables :
'var' name=ID ':' ( ('Array' '[' INTEGER ']') | 'integer' | 'string' ) ;

procedure:
'proc' name=ID '(' parameters+=ID (',' parameters+=ID)* ')'
;

develop :
'dev' '{'
procCall=[procedure] '(' variables+=[variables]+ ')'
'}'
;

This is a sample of what the language should do:
defs {
var v1 : integer
var v2 : Array[5]
var v3 : string
}

dev {
toString (v1) //This should be ok because a method toString is implicitly declared after the v1 is declared
toString(v2) //This should be ok because a method toString is implicitly declared after the v3 is declared
toString(v3) //This should NOT be ok bec. v3 is already a string
}

So I need to create a method toString that takes one variable of type integer under the declaration of v1. and when the user f3 on toString, it should go to the declaration of v1 bec. toString is not declared explicitly in the file by the user.

-----------------------------------------------
I have been looking into post processing but I found that it needs a lot of work to be done and I am not sure if I am going in the right direction. Can anyone guide me to how to start in making this?

Thanks Smile
Re: creating objects in the EMF [message #1727107 is a reply to message #1727099] Sat, 19 March 2016 07:00 Go to previous messageGo to next message
Anton Kosyakov is currently offline Anton KosyakovFriend
Messages: 9
Registered: March 2016
Junior Member
Hi,

You can use a library approach to provide toString procedure: http://zarnekow.blogspot.de/2012/11/xtext-corner-8-libraries-are-key.html.
For type checking you will need custom validations: https://eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation.
BTW it is impossible to say of which type should be an argument looking at a procedure.

Anton


Get professional support from the Xtext committers at www.typefox.io.
Re: creating objects in the EMF [message #1727108 is a reply to message #1727099] Sat, 19 March 2016 07:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
Hi post processing is about the metaamodel. Your usecase sounds more like http://xtextcasts.org/episodes/18-model-optimization

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: creating objects in the EMF [message #1727128 is a reply to message #1727108] Sat, 19 March 2016 19:03 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
Hi Anton and Christian,
I will have a look at both ways and return to you both to tell u the results.

Thanks alot Smile
Re: creating objects in the EMF [message #1727129 is a reply to message #1727107] Sat, 19 March 2016 19:06 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
The link to the libraries are no longer available
Re: creating objects in the EMF [message #1727130 is a reply to message #1727129] Sat, 19 March 2016 19:11 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
Hi Christian,
So, you think I should try the model optimization over the post processing right?
Re: creating objects in the EMF [message #1727137 is a reply to message #1727130] Sun, 20 March 2016 08:36 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
I think you didn't get me right, I want to create an EObject of type procedure (and takes parameters and has a return type and all the grammar rule's items) and add it to the current model so that the user can use it directly. I dont want it as a feature in an existing EObject.
Re: creating objects in the EMF [message #1727154 is a reply to message #1727137] Sun, 20 March 2016 10:25 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
No you Need the postprocessing Or a manually metamodel Or uncalled
Rules for the METAmodel and the derived State Computer for the Model 2 Model trafo


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Expression tree
Next Topic:Workspace Builds repeatedly when running as eclipse application
Goto Forum:
  


Current Time: Sat Sep 25 16:28:19 GMT 2021

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

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

Back to the top