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

DashaScript is a statically typed language. In general, the type system in DashaScript is similar to TypeScript's one, but it does not contain some of TS's elements (e. g. type templates). Also, its syntax is slightly different.

You can declare the variable's type with a colon after its name:

{ x: string?; }

All not-nullable variables must be initialized. Variable can be declared as nullable with ? after its type name.

Types can also be inferred during initialization, so you don't need to set it manually (see examples below).

Examples

Declaration of the variables in the context.

context { num: number = 0; str: string = "Hello"; flag: boolean?; }

Declaration of local variables.

start node myNode { do { var num: number = 0; // str's type will be infered to be string var str = "Hello"; } transitions { } }

Built-in types

Basic types

Type nameValue rangeExamples
stringstring“hello”, “123”, …
numberdouble-precision 64-bit binary format IEEE 7545.2, -21, …
booleanlogicaltrue, false

Derived data types

Array

Any type can be expanded to an array using the [] postfix:

{ x: string[]; }

Object

Object declaration is enclosed in curly braces, the object fields are declared as name and type, separated by a colon, each field declaration ends with a semicolon:

context { // Declaration of an "person" object with field "name", field "age" and optional field "phone". person: { name: string; age: number; phone: string?; } = { name: "Allen", age: 28, phone: "1994" }; }

A field can be declared optional by adding the ? postfix to the type.

Union types

Union of types is enclosed in angle brackets, the combined types are separated by a pipe:

context { numberOrString: <number|string> = 0; }

User-defined types

User can declare a custom type using the type keyword:

type MyType = { name: string; age: number; };

Operators

Arithmetic operators

  • addition +
  • subtraction -
  • multiplication *
  • division /
  • increment +=

Ternary operator

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

Logical operators

The language supports logical operators:

  • && - logic and
  • || - logic or

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"); } }

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.