Skip to main content



      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 04:29 Go to next message
Eclipse UserFriend
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 08:31] by Moderator

Re: Syntactic sugar with assigned actions [message #1257798 is a reply to message #1256294] Wed, 26 February 2014 15:11 Go to previous messageGo to next message
Eclipse UserFriend
HI,

this is not possible

maybe the hook IDerivedStateComputer is something for you
http://xtextcasts.org/episodes/18-model-optimization
Re: Syntactic sugar with assigned actions [message #1258037 is a reply to message #1257798] Wed, 26 February 2014 21:24 Go to previous message
Eclipse UserFriend
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: Sat Jul 05 10:03:43 EDT 2025

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

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

Back to the top