Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » overriding (adding) operators
overriding (adding) operators [message #64728] Fri, 28 November 2008 13:14 Go to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040507080901040102050609
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Christian,

For the purpose of MTL, we often need string concatenation (being a text
generation and all ;)). The "standard" OCL doesn't allow for "simple"
String concatenation, and I wanted to add a "+(String) : String" to the
MTL standard library in order to have something a little more
straightforward than "concat(String) : String".

That didn't work as would any other extension to the standard lib
though. Had I added a "plus(String) : String" operation, I would have
been able to make something like "'te'.plus('st')" ... but this doesn't
add any value as compared to the standard "'te'.concat('st')". What I
need is "'te' + 'st'". As there is no "+" operation defined as a
standard in OCL I would have thought this to be possible. Do you know of
any way to implement such a fonctionnality in the current OCL
implementation?

Laurent Goubet
Obeo

--------------040507080901040102050609
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

begin:vcard
fn:Laurent Goubet
n:Goubet;Laurent
org:<a href="http://www.obeo.fr/">Obeo</a>
email;internet:laurent.goubet@obeo.fr
url:http://www.obeo.fr
version:2.1
end:vcard


--------------040507080901040102050609--
Re: overriding (adding) operators [message #64751 is a reply to message #64728] Fri, 28 November 2008 14:34 Go to previous message
Eclipse User
Originally posted by: cdamus.zeligsoft.com

Hi, Laurent,

Knowledge of infix operators like '+' is encoded in the LPG grammar.
OCL's grammar expects numeric values on either side of the '+' operator.

You will have to extend the grammar in a similar way as the various QVT
projects at Eclipse have done. In fact, I think the QVT language also
aliases string concatenation using '+', so I think they will provide an
especially good example for your.

HTH,

Christian

laurent Goubet wrote:
> Hi Christian,
>
> For the purpose of MTL, we often need string concatenation (being a text
> generation and all ;)). The "standard" OCL doesn't allow for "simple"
> String concatenation, and I wanted to add a "+(String) : String" to the
> MTL standard library in order to have something a little more
> straightforward than "concat(String) : String".
>
> That didn't work as would any other extension to the standard lib
> though. Had I added a "plus(String) : String" operation, I would have
> been able to make something like "'te'.plus('st')" ... but this doesn't
> add any value as compared to the standard "'te'.concat('st')". What I
> need is "'te' + 'st'". As there is no "+" operation defined as a
> standard in OCL I would have thought this to be possible. Do you know of
> any way to implement such a fonctionnality in the current OCL
> implementation?
>
> Laurent Goubet
> Obeo
Previous Topic:[Announce] MDT OCL 1.3.0 I200811251600 is available
Next Topic:[Announce] MDT OCL 1.3.0 I200812021600 is available
Goto Forum:
  


Current Time: Fri Aug 22 19:35:06 EDT 2014

Powered by FUDForum. Page generated in 0.01960 seconds