1. Home
  2. Docs
  3. ClusterControl
  4. Developer Guide
  5. ClusterControl Domain Specific Language (DSL)
  6. Language basics

Language basics

Preprocessor directives

This system has no preprocessor, the parsing is done in one stage. Some expressions however are implemented the same way it is implemented in most of the C/C++ language preprocessors. Here is a list of the supported preprocessor directives.

  • #include "filepath"
    Preprocessor directive to include a source file the same way it is used for the C/C++ languages.
  • #pragma once

Preprocessor directive to protect an include file to be included multiple times. The same as in the C/C++ languages.


Here is an example of the new operator.

var a = new Int;
var b = new CmonHost();
passed =
  a === 0 &&
  b.typeName() == "CmonHost";
  • Int
  • Bool
  • Double
  • Ulonglong
  • String
  • Error
  • Map
  • List
  • Array
  • CmonHost
  • CmonMySqlHost
  • CmonPostgreSqlHost
  • CmonGaleraHost
  • CmonMongoHost
  • CmonMaxScaleHost
  • CmonAdvice
  • CmonClusterConfig
  • CmonGraph
  • CmonJob


Boolean literals. These are just simply true and false.

String literals. The string literals are handled the usual way, they can be enclosed in single or double quotes, single-quoted strings may contain double quotes, the double-quoted strings can contain single quotes.

var carName1 = "Volvo XC60";
var carName2 = 'Volvo XC60';
var answer1 = "It's alright";
var answer2 = "He is called 'Johnny'";
var answer3 = 'He is called "Johnny"';

Strings literals can also be concatenated in compile time as it is seen in the C/C++ languages:

var a =
  "one "
  "two "
passed = a == "one two three";

Integer literals. Integer literals are integer numbers that are fit to be stored in the host computer’s “int” type. Here is an example:

var1 = 0xff;
var2 = 0XFFFF;
passed = var1 == 255 && var2 == 65535;

Unsigned long long literals. If an integer literal is too big to fit on an “int” type but fits in an unsigned long it is automatically stored in an unsigned long (or “Ulonglong” type). If the number is prefixed with “ull” it is also considered to have the Ulonglong type.

var a = 91872698761001;
var b = 10ull;
passed =
  a.typeName() == "Ulonglong" &&
  b.typeName() == "Ulonglong";

Double literals. All the numbers that are not fit any integer types will be stored in a double type as the usual double format strings.

var a = 10.2;
var b = 10.8E11;
var c = 2.8e-10;
passed =
  a.typeName() == "Double" &&
  b.typeName() == "Double" &&
  c.typeName() == "Double";

Error literals.

var a = #ARGS!;
passed = a === #ARGS!;

The available error literals are the following:

  • #NULL!
    Null value error.
  • #DIV/0!

Division by zero.

  • #VALUE!
    Type mismatch error e.g. log of a string.
  • #REF!
    Invalid variable reference, missing variable.
  • #NAME?
    The name was not found, e.g. a function name is invalid.
  • #NUM!
    Invalid numerical value e.g. sqrt(-1).
  • #N/A
    Value is not available.
  • #SYNTAX!
    Syntax error in the formula.
  • #ARGS!
    Argument number for a function is invalid.

Map literals. Map literals are associative arrays that can hold any type of value (even maps) and can be indexed by strings. Here is an example of how to create and use a map:

var a = {};
a["one"] = {};
a["one"]["two"] = "value";
passed =
  a.typeName() == "Map" &&
  a["one"]["two"] == "value";

The map keys could be listed using the .keys() method:

// an example iteration on the map:
var testmap = {};
testmap["key1"] = "test";
testmap["key2"] = "test";
keys = testmap.keys();
for (i = 0; i < keys.size(); ++i)
   print (keys[i] + ": " + testmap[keys[i]]);

Regular expression literals. Regular expression literals are supported the same way they are supported by the JavaScript language. Here is an example that demonstrates the usage of such literals:

var regexp = /([0-9]+)x([0-9]+)/i;
var string = "s: 640x480";
string.replace(regexp, "$2x$1");
// string === "s: 480x640";

Regular expressions have the type CmonRegExp.

Was this article helpful to you? Yes No 1