Skip to main content



      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 03:56 Go to next message
Eclipse UserFriend
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 03:59 Go to previous messageGo to next message
Eclipse UserFriend
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 04:16 Go to previous messageGo to next message
Eclipse UserFriend
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 04:20 Go to previous message
Eclipse UserFriend
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: Fri Jun 20 16:59:03 EDT 2025

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

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

Back to the top