DeltaScript

Lightweight scripting language skeleton designed to be easily extended for the specification and implementation of domain-specific languages


Overview

DeltaScript is a concise, statically typed scripting language that is designed to be extended. Its extensions can define new data types, namespaces and functions, but inherit their syntax from DeltaScript. Thus, DeltaScript extensions form a family of syntactically identical domain-specific languages that share an underlying standard library of primitive types and native functions.

Example script

// accepts an input "input" color as a parameter
// returns a list of colors transformed from input in various ways
(~ color input -> color<>) {
    ~ (color -> color)[] color_functions = [
         c -> rgba(c.r, 0, 0, c.a),     // isolate red channel
         c -> rgba(0, c.g, 0, c.a),     // isolate green channel
         ::iso_blue,                    // reference to function "iso_blue"
         c -> {
            int avg = (c.r + c.g + c.b) / 3;
            return rgba(avg, avg, avg, c.a);
         },                             // greyscale of color
         c -> rgb(rc(), rc(), rc()),    // random opaque color
         c -> #ffffff                   // the color white
    ];
    ~ color<> channels = <>;            // initializes an empty list of colors

    // iterates through the (color -> color) functions in color_functions
    // calls each function with "input" as input and appends its
    //   return value to "channels"
    for (f in color_functions)
        channels.add(f.call(input));

    return channels;
}

// helper function to isolate the blue channel of a color
iso_blue(~ color c -> color) -> rgba(0, 0, c.b, c.a)

// helper function to generate a random color channel value
// uses the hexadecimal integer literal 0x100 (= 256)
rc(-> int) -> rand(0, 0x100)

Development

Technologies

ANTLR

The DeltaScript grammar is implemented with ANTLR.

ANTLR is a parser generator tool that uses the rules of a user-defined grammar to generate code in a given target language to easily lex and parse program files that are supposed to conform with the rules of the input grammar.

Java

The official implementation of DeltaScript is an interpreter that targets Java 17.

Use Cases

More information