Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Syntactic sugar with assigned actions(Defining an element that creates two others)
Syntactic sugar with assigned actions [message #1256294] Tue, 25 February 2014 09:29 Go to next message
Daniels Umanovskis is currently offline Daniels UmanovskisFriend
Messages: 1
Registered: February 2014
Junior Member
I'm working with a more complex grammar, but my case can be boiled down to the following example.

Suppose I have Foo objects and Bar objects that my DSL can describe. Foo objects are standalone, Bar objects are created to correspond to Foo objects, so the grammar is like:

FooExpression :
'foo' name = ID
('{'
	//some optional parameters
'}')?
;

BarExpression : 
'bar' 'for' nameLink = ID ('as' name = ID)?
;


BarExpression uses the ID terminal and not a proper cross-link to Foo because that's a constraint in my actual use-case, but that should not be relevant here.

So this grammar lets you write things like:

foo myFoo1
foo myFoo2

bar for myFoo1 as myBar1
bar for myFoo2


Now, I would like to also have a syntactic sugar element that would translate to creating a Foo and a Bar for it. That is, I imagine I would write:

sugar myFoo3


and that would exactly correspond to

foo myFoo3
bar for myFoo3


The impression I got from Xtext's doc is that assigned actions are for creating and assigning objects of other rules, so my guess at the grammar element was:

SyntaxSugar :
'sugar' name=ID
{FooExpression.name=current.name}
{BarExpression.nameLink=current.name}
;


That's not a valid element though, and in fact it seems like accessing fields of current is not possible.

How do I define my syntactic sugar element correctly?

[Updated on: Tue, 25 February 2014 13:31]

Report message to a moderator

Re: Syntactic sugar with assigned actions [message #1257798 is a reply to message #1256294] Wed, 26 February 2014 20:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13642
Registered: July 2009
Senior Member
HI,

this is not possible

maybe the hook IDerivedStateComputer is something for you
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: Syntactic sugar with assigned actions [message #1258037 is a reply to message #1257798] Thu, 27 February 2014 02:24 Go to previous message
Xi Lin is currently offline Xi LinFriend
Messages: 21
Registered: January 2014
Junior Member
I think that post processing or override the afterModelLinked method should works.
Previous Topic:Combining Grammars
Next Topic:How can I add sourceDir to xtext-maven-plugin
Goto Forum:
  


Current Time: Thu Oct 29 03:29:16 GMT 2020

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

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

Back to the top