Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext] Default values for optional assignments?
[Xtext] Default values for optional assignments? [message #468198] Tue, 04 August 2009 09:44 Go to next message
Hauke Fuhrmann is currently offline Hauke Fuhrmann
Messages: 321
Registered: July 2009
Senior Member
Dear xtext folks,

is there a way to specify default values for attribute assignments that
are optional?

Like in:

Node:
(attr=INT)? name=ID

If one omits the INT token, then attr will be initialized with 0 as I
understand. Is there a way to set this default value to some other value?

Cheers,
HAuke
Re: [Xtext] Default values for optional assignments? [message #468219 is a reply to message #468198] Tue, 04 August 2009 10:56 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2807
Registered: July 2009
Senior Member
Hi Hauke,

please have a look at the post processing hook for the meta model
generation. The documentation can be found at http://www.xtext.org. The
FAQ provides an entry point for this one, too:
http://wiki.eclipse.org/Xtext/FAQ#How_can_I_control_the_Xtex t_meta_model_inference_.3F

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 04.08.2009 15:44 Uhr, schrieb Hauke Fuhrmann:
> Dear xtext folks,
>
> is there a way to specify default values for attribute assignments that
> are optional?
>
> Like in:
>
> Node:
> (attr=INT)? name=ID
>
> If one omits the INT token, then attr will be initialized with 0 as I
> understand. Is there a way to set this default value to some other value?
>
> Cheers,
> HAuke
Re: [Xtext] Default values for optional assignments? [message #985906 is a reply to message #468219] Fri, 16 November 2012 11:00 Go to previous messageGo to next message
Christopher Brind is currently offline Christopher Brind
Messages: 9
Registered: October 2011
Junior Member
Hi,

I am trying to work this out as well. I see this post is quite old now so I wonder if that FAQ is still accurate? I can't find the things it is referring to in my IDE.

Any help assigning default values to optional grammar would be appreciated.

Cheers,
Chris
Re: [Xtext] Default values for optional assignments? [message #985922 is a reply to message #985906] Fri, 16 November 2012 11:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5843
Registered: July 2009
Senior Member
hi,

IXtext2EcorePostProcessor is still there. it ships with one impl (XtendXtext2EcorePostProcessor)
you may need to install a complete xpand sdk the get full useage of the ide features described in the faq.
or you implement it yourself e.g. as i described it here http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/

~Christian
Re: [Xtext] Default values for optional assignments? [message #985923 is a reply to message #985922] Fri, 16 November 2012 12:03 Go to previous messageGo to next message
Christopher Brind is currently offline Christopher Brind
Messages: 9
Registered: October 2011
Junior Member
Thanks Christian, I had just started reading your blog post.
Re: [Xtext] Default values for optional assignments? [message #986747 is a reply to message #985923] Wed, 21 November 2012 09:19 Go to previous messageGo to next message
Christopher Brind is currently offline Christopher Brind
Messages: 9
Registered: October 2011
Junior Member
Hi again,

Your blog post helped in that I got to the point where I realised that for that particular problem I could just set the default value literal of the attribute.

The problem I have now is that I need to override the getter of an attribute so that if the attribute is null i return a value derived from one of the other attributes.

Obviously I can't just add an operation to override the getter as that invalidates the genmodel, so I'm a little stuck... any suggestions?

Thanks in advance.
Re: [Xtext] Default values for optional assignments? [message #986803 is a reply to message #986747] Wed, 21 November 2012 12:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5843
Registered: July 2009
Senior Member
Hmmm i have actually no idea for that. Maybe you have to switch to a
manually maintained metamodel

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: [Xtext] Default values for optional assignments? [message #986806 is a reply to message #468198] Wed, 21 November 2012 12:22 Go to previous message
Christopher Brind is currently offline Christopher Brind
Messages: 9
Registered: October 2011
Junior Member
Drat, that's a shame. Thanks for your reply anyway.
Previous Topic:I can do this on my grammar?
Next Topic:Add Environment Library
Goto Forum:
  


Current Time: Thu Apr 17 05:53:09 EDT 2014

Powered by FUDForum. Page generated in 0.04795 seconds