Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Settings two attributes when consuming one token(Or how to post-process models)
Settings two attributes when consuming one token [message #1387817] Wed, 25 June 2014 16:28 Go to next message
Cioran Naroic is currently offline Cioran NaroicFriend
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

Re: Settings two attributes when consuming one token [message #1387869 is a reply to message #1387817] Wed, 25 June 2014 18:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

did you consider to simply implement a IDerivedStateComputer?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Settings two attributes when consuming one token [message #1387951 is a reply to message #1387869] Wed, 25 June 2014 20:43 Go to previous message
Cioran Naroic is currently offline Cioran NaroicFriend
Messages: 18
Registered: December 2013
Junior Member
Thank you for the pointer, it seems to be exactly what I need. I had to use an Xbase-based grammar, though.

In the few languages I implemented until now, I precisely need this kind of postprocess hook. I find it unfortunate that there's no pointer to this in the official documentation.

Thank you Christian,


Previous Topic:Model inferrer issue during file access
Next Topic:DefaultGlobalScopeProvider and "class path mechanism"
Goto Forum:
  


Current Time: Fri Apr 19 22:47:37 GMT 2024

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

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

Back to the top