Files
Decodal/doc/manual/source/language/syntax.md
T

2.2 KiB

Lexical Structure and Syntax

This chapter summarizes the surface syntax. See the EBNF in Grammar for the precise grammar.

Language name and extension

The project is named Decodal. Its full descriptive name is Deferred Constraint Data Language, abbreviated DCDL. Source files use the .dcdl extension.

config.dcdl
schema.dcdl
service.dcdl

Module source

An entire file can contain a single expression. A sequence of field definitions at the top level is treated as an implicit object.

host = String;
port = Int default 8080;

The source above is equivalent to:

{
    host = String;
    port = Int default 8080;
}

Comments

A comment begins with # and continues to the end of the line.

# comment
host = "127.0.0.1"; # trailing comment

Semicolons

Semicolons separate object fields, let bindings, and match arms. A trailing semicolon is allowed.

{
    host = "127.0.0.1";
    port = 8000;
}

Identifiers

An identifier begins with an ASCII letter and may continue with ASCII letters, digits, or _. Naming conventions can use lower_snake, lowerCamel, or UpperCamel.

my_config
mkConfig
IPv4Address

Path references

Use a dot to reference a field.

config.host
config.feature_hoge.enable

Fields inside an object can also be defined with a dot path.

{
    feature_hoge.enable = false;
}

This represents the same structure as:

{
    feature_hoge = {
        enable = false;
    };
}

Reserved words

The following words are reserved:

let
in
match
import
default
as
true
false

Operators

The primary operators are:

+ - * /       arithmetic
++            array concatenation
! && ||       logical operations
== != < <= > >= comparisons
&             constraint-preserving composition
//            patch composition
default       fallback specification
as            range containment check and refinement from left to right
=>            function
.             field reference / dot-path definition
...           value constraint for an array or associative array

Operator precedence is defined in Operators.