Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[m2t-dev] [MTL] standard library additions

Hi Arjan,

While using MTL during the tests I perform on the current implementation, I stumbled upon things difficult (or plain bothersome) to do in OCL and for which we could provide convenience additional operations in the standard library. Namely :

1) Checking that a String starts with a given substring (self.substring(1, x) = 'substring')
2) Checking that a String ends with a given substring (self.substring(x, self.size()) = 'substring')
3) Fetching all ancestors (of a given type) for a given element (OCL _expression_ is too long to fit on a human-readable mail :))
4) Fetching all descendants (of a given type) for a given element (same as above)

Additionally, The specification provides a "substitute" operation, but not its "substituteAll" counterpart and both "replace" and "replaceAll" operations that operate on regular expressions. Do you think it would be possible to add the following operations to the MTL standard library specifications :

EOperations that would be added to the "String" OCL primitive type
1) endsWith( String substring ) : Boolean
Returns true if self ends with the substring substring, false otherwise.
2) startsWith( String substring ) : Boolean
Returns true if self starts with the substring substring, false otherwise.
3) substituteAll( String substring, String replacement ) : String
Substitutes all substrings substring in self by substring replacement and returns the resulting string. If there is no occurrence of the substring, The original string is returned. substring and replacement are not treated as regular expressions.
4) replace( String substring, String replacement ) : String
Substitutes the first occurence of substring substring in self by substring replacement and returns the resulting string. If there is no occurrence of the substring, The original string is returned. substring and replacement are treated as regular expressions.
5) replaceAll( String substring, String replacement ) : String
Substitutes all substrings substring in self by substring replacement and returns the resulting string. If there is no occurrence of the substring, The original string is returned. substring and replacement are treated as regular expressions.

EOperations that would be added to the "OCLType" OCL primitive type
6) ancestor( ) : Sequence(T)
Returns all super-elements of self.
7) ancestor( OCLType type ) : Sequence(T)
Returns all super-elements of self which type is equal to type.
8) descendant( ) : Sequence(T)
Returns all direct and indirect children of self.
9) descendant( OCLType type ) : Sequence(T)
Returns all direct and indirect children of self which type is equal to type.

For now, I have implemented the first 5 (didn't give a shot to the last 4 as yet) in a "non-standard" library but I think all are more than convenient to provide for an m2t language.

Regards,

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


Back to the top