Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Setting rule values implicitly in Xtext Grammar by keyword appereance
Setting rule values implicitly in Xtext Grammar by keyword appereance [message #1786844] Mon, 14 May 2018 07:56 Go to next message
Alfonso de la Vega is currently offline Alfonso de la VegaFriend
Messages: 5
Registered: January 2016
Junior Member
Hello,

I am developing a SQL-like grammar in Xtext, and I am trying to define the following syntax for attributes of an entity:

   text userId unique;


For that syntax, I created the following rule (not correct, it shows what I want to achieve):

Attribute:
  type=Type name=ID ("unique" {this.isUnique=true})?;


The desired behaviour would be to set an isUnique attribute of the rule to true, just because of the appearance of the "unique" keyword.

Is there a way to define this in the Xtext grammar?

Thank you very much,
Alfonso
Re: Setting rule values implicitly in Xtext Grammar by keyword appereance [message #1786845 is a reply to message #1786844] Mon, 14 May 2018 07:59 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Excerpt from the grammar language manual:
Quote:
The ?= sign (boolean assignment operator) expects a feature of type EBoolean and sets it to true if the right hand side was consumed, independently from the concrete value of the right hand side.


Use as follows:
Attribute:
  type=Type name=ID (unique?="unique")?;
Re: Setting rule values implicitly in Xtext Grammar by keyword appereance [message #1786846 is a reply to message #1786845] Mon, 14 May 2018 08:16 Go to previous messageGo to next message
Alfonso de la Vega is currently offline Alfonso de la VegaFriend
Messages: 5
Registered: January 2016
Junior Member
Hello Karsten,

You are right, I missed that from the documentation.

Thanks!

Alfonso
Re: Setting rule values implicitly in Xtext Grammar by keyword appereance [message #1786847 is a reply to message #1786846] Mon, 14 May 2018 08:20 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Beyond the documentation it is always useful to look up existing grammars. There are tons of them out there and many have interesting ideas. In the sources from Xtext there are already some good things, or take the Xtext examples that you can install from the File/New menu.
Previous Topic:Generated project tries to access missing URL
Next Topic:Xtext with other AST generators
Goto Forum:
  


Current Time: Sun Sep 23 07:21:51 GMT 2018

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

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

Back to the top