|Re: overriding (adding) operators [message #64751 is a reply to message #64728]
||Fri, 28 November 2008 19:34
Originally posted by: cdamus.zeligsoft.com|
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.
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
> Laurent Goubet
Powered by FUDForum
. Page generated in 0.01356 seconds