Model Scripting in your Browser: Introducing CatsooLang

Online Model Scripting Terminal

A new Domain Specific Language (DSL) built to give you the ability to modify and query your models from your browser, directly in GenMyModel.

Who does not want to query or modify her/his model? Do you ever tell to yourself after a modification in your model: “Damn, I need to postfix all my 50 Classes with ‘DAO’…”? Or “I must add an attribute to all my classes… It’s gonna take forever”. If you don’t, well… lucky you, I asked myself this kind of questions many times a day.

Query/Refactor Your Model with CatsooLang

Model query is usually made using Object Constraint Language (OCL). If you want to know more about OCL, I strongly suggest you to read the Object Constraint Language (OCL): a Definitive Guide by Jordi Cabot and Martin Gogolla. This language is often used as basis for model to model transformation language (QVT, ATL…) and model to text transformation (Acceleo…). OCL is a static typed language and is very powerful but sometimes you only want to quickly interpret a simple query without thinking about type casting or without thinking about how to create a simple reusable function which will modify your model or create your model in a textual way.

As an answer, the GenMyModel team presents you the Catsoo Model Scripting Language (CatsooLang) and the CatsooLang terminal, a model scripting language interpreted in the browser. This language is dynamically typed, support ad-hoc polymorphism and support imperative and sort of functional programming style. CatsooLang is integrated in GenMyModel using an interactive console (the CatsooLang terminal) in which you can type your CatsooLang expressions.

What does it look like?

Its syntax is close to OCL with some ideas taken from QVT. It’s is a mix between imperative and functional programming language. Here is a query example:

var classes := __ROOT objects()[uml::Class]->select(e | e.ownedAttribute <> []);

This fragment will put in the variable classes all the Class from your model having attributes. You can read it this way: ‘From the root of my model, get all the elements and keep the classes.Then, from this collection, select the classes which have a non empty collection of attributes’.

Want more? Here’s a model fragment creation:

var newclass := create uml::Class{name := 'MyNewClass'; isAbstract := true};

This fragment will create a new abstract class named ‘MyNewClass’ but does not attach it to your model yet.

As you can see, CatsooLang is a low level language (understand: ‘you can modify each single feature of your model regarding its metamodel’) but it comes with various libraries that will help you to easily handle/modify/create your model. You can reach a work in progress documentation at this adress: CatsooLang Documentation about language features (function call, function creation, model navigation…).

Can I try it in GenMyModel?

Sure! Since few weeks, you probably noticed there is a new bad ass layout for the GenMyModel editor which uses docks. If you look closely, you can see that a dock has been added in the bottom left of your screen: Terminal tab. If you gently click on it, the CatsooLang terminal will gently open.

CatsooLang Terminal

This terminal is equivalent to Python, Lua, OCaml, you_name_it interactive console, you can directly write your CatsooLang expression in there and wait for the result. Here is what happens if you type the expressions presented above on a UML class diagram in GenMyModel (notice the use of the log(...) keyword):

Catsoo Expression Evaluation on UML Models

You can also try these codes on other UML models (e.g., on this class diagram), feel free to browse and fork models from our model repository.

Design Faster?

Sometimes, it can become handy to have a bunch of functions on the shelf that can be used in order to easily create big inheritance trees, to rename all model elements or to generate getter/setter for all your attributes in one line. To sum up, you can define a lot of refactoring functions in CatsooLang. Some are already coded and available in predefined libraries. Later on, we will explain you how to tame this language and how to get the most out of it for more productivity. We’ll give a few hints on how to provide your own scripts and share them with all your teammates.

To conclude this post, here is a tip for you: the terminal is embedded with a bunch of shortcuts (more or less the same you have in a UNIX/Linux terminal), use them to type and edit your CatsooLang expressions faster. Also, we could work on smart auto-completion. If you are interested, let us know!

General Keyboard Shortcuts

* CTRL + SHIFT + h     Displays this help
* ENTER                Evaluates the current line
* SHIFT + ENTER        Inserts a new line at cursor position
* UP                   Selects previous entry from history
* CTRL + UP            Selects previous entry from history (skips multi-lines)
* DOWN                 Selects next entry from history
* CTRL + DOWN          Selects next entry from history (skips multi-lines)
* CTRL + l             Clears shell screen
* CTRL + a             Moves the cursor to the begining of the line
* CTRL + e             Moves the cursor to the end of the line
* CTRL + f             Moves the cursor to the right
* CTRL + b             Moves the cursor to the left
* CTRL + k             Cuts the line from the cursor position to the end of the line
* CTRL + u             Cuts the line from the cursor position to the beginning of the line
* CTRL + y             Pastes the previously cut line at cursor position
* CTRL + j             Evaluates the current line (same effect than ENTER)
* CTRL + d             Deletes the character to the right of cursor
* CTRL + h             Deletes the character to the left of cursor

CatsooLang Keyboard Shortcuts

* CTRL + i       Wraps current instruction into a 'log();' instruction and sets the cursor position before the last bracket
* CTRL + s       Inserts a 'select' instruction at cursor position
* CTRL + r       Inserts a 'reject' instruction at cursor position

CatsooLang Documentation

There is some commands relative to the terminal only
'help'         Displays this screen
'history'      Displays all the command written in the terminal since the session beginning
'#sandbox-on'  Enables sandbox mode (safe-mode)
'#sandbox-off' Disables sandbox mode (safe-mode)


Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

About the author

vince Team

Music, cards and beer lover...

Also PhD in Computer Science specialized in software modeling, code generation and model driven development. Interest/work in code generation, reverse engineering techniques, interpretation and compilation.