Settings two attributes when consuming one token [message #1387817] |
Wed, 25 June 2014 16:28 |
Cioran Naroic Messages: 18 Registered: December 2013 |
Junior Member |
|
|
Hi everyone,
I need to write a grammar for an external Ecore that I cannot change. I would like to set the value of two different attributes when consuming one token in the parsed file.
Let's take a very simple example:
Foo returns Foo:
'Foo' name1 = STRING
;
When consuming the associated STRING, I would like to set both name1 and name2 (Foo's attributes) to the same parsed value (ie. when parsing Foo "bar", I would like to get an instance foo1 of Foo with foo1.name1 = foo1.name2 = "bar").
In my real case, I'm actually referencing another [Element | ID] and I would like to set two references pointing to this same element (but writing only one time the ID in the parsed file!).
Using some sort of post-processor for that purpose would not be a problem. I tried to put it into the Validator (validating Foo by setting name2 with the parsed name1 value), but in my case both attributes are mandatory [1..1] and the editor complains about name2 not being set (although it I look the generated model in the end it is set...).
More generally, I would like to know if there is some hook to post-process the model generated by Xtext. For example, if the EClass Addition contains attributes "left" and "right" (define in the source file), I would like to automatically set its attribute "sum" = left + right once the source file is parsed.
Is that possible?
Thank you,
[Updated on: Wed, 25 June 2014 17:12] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03185 seconds