Language reference

Special characters (sigils)

$ — referring to context

You can access context data with the $ prefix. It can be used both in the executable section and in the condition.

node myNode { do { set $x = 10; wait *; } transitions { targetNode: goto targetNode on $x > 5; } } node targetNode { do { // Custom code... } transitions { } }

# — built-in API call

You can call built-in functions with the # prefix.

node myNode { do { set $x = #getCurrentTime(); } transitions { targetNode: goto targetNode on #getCurrentTime() > $x + 100; } } node targetNode { do { // Custom code... } transitions { } }

@ — literal identifier

@ prefix allows you to use language keywords as identifiers.

node myNode { do { goto @transition; } transitions { @transition: goto @node; } } node @node { do { // Custom code... } transitions { } }

Compiler directives

library

To decompose your script into separate files, declare one of them as library like this:

library node myNode { do { // Some code... } transitions { } }

import

You can import the library with the import directive, specifying the relative path to a library file as a parameter:

import "relativePathToLibrary.dsl"; /* block body */

context

You can declare context data with the context directive:

context { myInputData: number; } start node myNode { do { set x = $myInputData; } transitions { } }

Data types

Please, see Data types page.

Operators

Arithmetic operators

  • addition +
  • subtraction -
  • multiplication *
  • division /
  • modulo %

Ternary operator

<condition> ? <executes-on-true> : <executes-on-false>;

Logical operators

The language supports logical operators:

  • && - logic and
  • || - logic or
  • ! - logic not

Null check operators

  • Checking if a variable is null: <var> is null
  • Checking if a variable is not null: <var> is not null
/* * Node "targetNode" declaration. */ start node myNode { do { var x: { x:number; } ?= { x: 1 }; // "y" will be true, if "x" is not null and "x.x" equals to 1. var y = x is not null && x.x == 1; // "z" will be "x.x", if "x" is not null and 2 otherwise. var z = x is not null ? x.x : 2; } transitions { // Condition will be true when text event has either `correct_answer` or `semi_correct_answer` intent. targetNode: goto targetNode on #messageHasIntent("correct_answer") || #messageHasIntent("semi_correct_answer"); } }

Type casting operator

You can convert between types using the as operator. It performs "deep" type checking, recursively checking of the properties of its operand. If successful, val as Type returns val converted to the type Type. If not, it returns null. Thus, the type of the expression val as Type is Type?.

Check out the articles on type compatibility and type casting for more info.

Comments

Regular comments

Line comment starts with the // prefix:

{ /* Executable section */ // Line comment. }

Block comments are escaped with /* and */:

{ /* Executable section */ /* This is the comment body... * ...Continuing a block comment */ }

Node comment

A node comment can be specified with the comment keyword at the beginning of the node's body:

node myNode { comment "something" do { // Custom code... } transitions { // Transition definitions... } }

Statements

For, in statement

for statement executes a block of code for each element of the array.

start node myNode { do { var array: string[] = ["hello", "world"]; for (var item in array) { // Expected output: "hello", "world". #log(item); } exit; } transitions { } }
Found a mistake? Email us, and we'll send you a free t-shirt!

Enroll in beta

Request invite to our private Beta program for developers to join the waitlist. No spam, we promise.