Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Attaching keywords to variables within Xbase expressions
Attaching keywords to variables within Xbase expressions [message #1018767] Thu, 14 March 2013 12:42 Go to next message
Oren Mishali is currently offline Oren MishaliFriend
Messages: 15
Registered: March 2013
Junior Member
Hi all,

I would like to attach (optional) keywords to variables within Xbase expressions.

For example, the following syntax should be supported:

special x > 3 && special y < 6

I am looking for a simple way to achieve that goal. Any help is appreciated.

Thanks,
Oren
Re: Attaching keywords to variables within Xbase expressions [message #1018933 is a reply to message #1018767] Thu, 14 March 2013 18:07 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Oren,

I'm not sure that I can follow your idea, but you may want to look into
overriding the parser rule where you want to add information to the AST
and specialize that one.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 14.03.13 13:42, schrieb Oren Mishali:
> Hi all,
>
> I would like to attach (optional) keywords to variables within Xbase
> expressions.
>
> For example, the following syntax should be supported:
>
> special x > 3 && special y < 6
>
> I am looking for a simple way to achieve that goal. Any help is
> appreciated.
>
> Thanks,
> Oren
>
Re: Attaching keywords to variables within Xbase expressions [message #1020925 is a reply to message #1018933] Tue, 19 March 2013 07:40 Go to previous messageGo to next message
Oren Mishali is currently offline Oren MishaliFriend
Messages: 15
Registered: March 2013
Junior Member
Thanks Sebastian,

I've tried the approach you have suggested. I've extended XEqualityExpression as follows (note the addition of the new 'special' keyword):

XEqualityExpression returns XExpression:
'special' ? XRelationalExpression (=>({XBinaryOperation.leftOperand=current} feature=[types::JvmIdentifiableElement|OpEquality])
rightOperand=XRelationalExpression)*;

This change indeed allows to write Xbase expressions such as:

(special x == 3)

Next, I've tried to add a new variable in order to know whether the new 'special' keyword was added:

XEqualityExpression returns XExpression:
(special ?= 'special')? XRelationalExpression (=>({XBinaryOperation.leftOperand=current} feature=[types::JvmIdentifiableElement|OpEquality])
rightOperand=XRelationalExpression)*;

Unfortunately, I get the following two errors:

Cannot find compatible feature special in sealed EClass XExpression from imported package http://www.eclipse.org/xtext/xbase/Xbase: The type 'XExpression' does not have a feature 'special'.

An unassigned rule call is not allowed, when the 'current' was already created.

Thanks,
Oren

Re: Attaching keywords to variables within Xbase expressions [message #1021352 is a reply to message #1020925] Tue, 19 March 2013 22:57 Go to previous message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I think you'll have to extend XEqualityExpression in a subclass that
includes the boolean special field, and then use a parser action to
indicate that it should create an instance of that subclass:

XEqualityExpression returns XExpression:
{MyXEqualitySubclass} (special ?= 'special')? XRelationalExpression
(=>({XBinaryOperation.leftOperand=current}
feature=[types::JvmIdentifiableElement|OpEquality])
rightOperand=XRelationalExpression)*;

Hallvard

On 19.03.13 00.40, Oren Mishali wrote:
> Thanks Sebastian,
>
> I've tried the approach you have suggested. I've extended
> XEqualityExpression as follows (note the addition of the new 'special'
> keyword):
>
> XEqualityExpression returns XExpression:
> 'special' ? XRelationalExpression
> (=>({XBinaryOperation.leftOperand=current}
> feature=[types::JvmIdentifiableElement|OpEquality])
> rightOperand=XRelationalExpression)*;
>
> This change indeed allows to write Xbase expressions such as:
>
> (special x == 3)
>
> Next, I've tried to add a new variable in order to know whether the new
> 'special' keyword was added:
>
> XEqualityExpression returns XExpression:
> (special ?= 'special')? XRelationalExpression
> (=>({XBinaryOperation.leftOperand=current}
> feature=[types::JvmIdentifiableElement|OpEquality])
> rightOperand=XRelationalExpression)*;
>
> Unfortunately, I get the following two errors:
>
> Cannot find compatible feature special in sealed EClass XExpression from
> imported package http://www.eclipse.org/xtext/xbase/Xbase: The type
> 'XExpression' does not have a feature 'special'.
>
> An unassigned rule call is not allowed, when the 'current' was already
> created.
>
> Thanks,
> Oren
>
>
Previous Topic:Script editing without the actual editor
Next Topic:Library of keywords, function, and method signatures
Goto Forum:
  


Current Time: Thu Apr 25 03:38:44 GMT 2024

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

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

Back to the top