Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xbase
xbase [message #629403] Tue, 28 September 2010 07:19 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I took a brief look at the grammar for xpression (part of xbase) and was
a bit puzzled by the following (slightly modified):

OP: '+'|'-'
ADD: left=MULT op=[ecore::EObject|OP] ...

MULT: ...

I guess that you want to store the op, so you assign it to a feature.
However, it's a general reference, not an attribute. For this to work
there must be pre-made objects with names '+' and '-' added to some
artificial outer scope (or rather: EObjectDescriptions of them with '+'
and '-' as names), so that the linker can lookup '+' and '-' and find
the corresponding EObject.

Is this a "trick" for defining named EObject constants. Can someone
elaborate on its use?

Hallvard
Re: xbase [message #629445 is a reply to message #629403] Tue, 28 September 2010 10:08 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 9/28/10 9:19 AM, schrieb Hallvard Trætteberg:
> Hi,
>
> I took a brief look at the grammar for xpression (part of xbase) and was
> a bit puzzled by the following (slightly modified):
>
> OP: '+'|'-'
> ADD: left=MULT op=[ecore::EObject|OP] ...
>
> MULT: ...
>
> I guess that you want to store the op, so you assign it to a feature.
> However, it's a general reference, not an attribute. For this to work
> there must be pre-made objects with names '+' and '-' added to some
> artificial outer scope (or rather: EObjectDescriptions of them with '+'
> and '-' as names), so that the linker can lookup '+' and '-' and find
> the corresponding EObject.
>
> Is this a "trick" for defining named EObject constants. Can someone
> elaborate on its use?

In Xbase the infix operators are just syntactic sugar for method
invocation. That is those operators actually refer to methods.

I.e. + refers to a declared method with the name 'add'. This is some
kind of operator overloading also used in Groovy. So far it is typed to
EObject, since we havn't come up with something more specific like
(Invocable), but we might gonna change that.

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: xbase [message #629451 is a reply to message #629445] Tue, 28 September 2010 10:29 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 28.09.10 12.08, Sven Efftinge wrote:
>> Is this a "trick" for defining named EObject constants. Can someone
>> elaborate on its use?
>
> In Xbase the infix operators are just syntactic sugar for method
> invocation. That is those operators actually refer to methods.
>
> I.e. + refers to a declared method with the name 'add'. This is some
> kind of operator overloading also used in Groovy. So far it is typed to
> EObject, since we havn't come up with something more specific like
> (Invocable), but we might gonna change that.

Interesting! How is this handled during linking, to establish the
reference? Do you use a special scope?

Hallvard
Re: xbase [message #629495 is a reply to message #629451] Tue, 28 September 2010 13:32 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 9/28/10 12:29 PM, schrieb Hallvard Trætteberg:
> On 28.09.10 12.08, Sven Efftinge wrote:
>>> Is this a "trick" for defining named EObject constants. Can someone
>>> elaborate on its use?
>>
>> In Xbase the infix operators are just syntactic sugar for method
>> invocation. That is those operators actually refer to methods.
>>
>> I.e. + refers to a declared method with the name 'add'. This is some
>> kind of operator overloading also used in Groovy. So far it is typed to
>> EObject, since we havn't come up with something more specific like
>> (Invocable), but we might gonna change that.
>
> Interesting! How is this handled during linking, to establish the
> reference? Do you use a special scope?

The class org.eclipse.xtext.xbase.typing.OperatorMapping does the
mapping from operator to method name. The scoping then uses the method
signatures.

Sven


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Previous Topic:Cross-reference to duplicated classes
Next Topic:"Partial" Formatting
Goto Forum:
  


Current Time: Thu Apr 25 00:21:49 GMT 2024

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

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

Back to the top