Syntactic sugar with assigned actions [message #1256294] |
Tue, 25 February 2014 09:29 |
Daniels Umanovskis 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:
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03653 seconds