1. syntax

alv programs consist of a series of expressions separated by chunks of whitespace. Each expression may be either a literal constant or a cell.

literal constants

There are three types of simple literals with different syntax:

numbers

Numbers consist of the digits 0-9 and can optionally begin with a negative sign and contain a decimal dot. The digits before or after the decimal point may be left off, but a number needs to consist of at least one digit.

The following are all valid numbers:

0
12
-7
0.1
10.
.1
123.

The regular expression -?(\d+\.\d*|\d*\.\d+|\d+) matches all numbers.

strings

Strings are enclosed by either single (') or double quotes ("). Backslashes and either type of quote can be escaped by prefixing them with a single backslash, i.e. the literal notation "\\\"" evaluates to the string \".

The following are all valid strings:

"hello world"
'hello world'
"it's a beautiful day"
'it\'s a beautiful day'
"this is a backslash: \\"
"this is a double quote: \""
""
''

symbols

Symbols must start with a letter (a-z or A-Z) or one of the following special characters:

- + * /
_ . , =
! ? % $
> < ~

The remaining characters can be letters, special characters from this set, or digits (0-9).

The following are all valid symbols:

helloWORLD
-
/
*dynamic*
*+*
var01
_test
foo$

The regular expression [a-zA-Z\-_+*^%\/.,=~!?$><][a-zA-Z0-9\-_+*^%\/.,=~!?$><]* matches all symbols.

cells

Cells consist of one or more subexpressions separated by chunks of whitespace and enclosed in parentheses (( and )). A cell optionally contains a tag immediately after the opening parenthesis. Whitespace between the opening parenthesis and the first subexpression or the closing parenthesis and the last subexpression is optional.

The first subexpression is considered the head of the cell and determines the behaviour of the cell.

tags

Tags consist of one or more digits (0-9) enclosed in square brackets ([ and ]). [1] and [255] are examples of valid tags.

template strings

Template Strings are a different syntax for cells that allows embedding alv expressions inside of a string literal. They can be used to perform string substitution, especially within code of other languages.

Template strings start with the character $ followed by an optional tag and a symbol that functions as the head of the cell and finally a "-delimited string literal. Within the string literal, a $ character begins an interpolation expression unless escaped by a single preceding blackslash.

The following are example template strings:

$empty""
$hello"world"
$fmt"three is $3 and four is $"four""
$[99]fmt"five is $(+ 3 2)"
$fmt"there is \$no substitution here"

Template strings are syntactic sugar that transforms into an array of string pieces and the values to substitute, the following cell expressions are semantically identical to the previous examples respectively:

(empty [""])
(hello ["world"])
(fmt ["three is " " and four is " ""] 3 "four")
([99]fmt ["five is" ""] (+ 3 2))
(fmt ["there is $no substitution here"])

arrays and structs

Array and struct literals too are syntatic shortcuts for the mkarray and mkstruct builtins respectively.

Arrays are a list of expressions separated by whitespace enclosed in square brackets ([ and ]). Similarly structs are a list of key-value pairs separated by whitespace and enclosed in curly brackets ({ and }).

Arrays and structs must contain at least one element or key-value pair respectively.

whitespace

The space, tab, newline, and line-feed special characters constitute whitespace and may be repeated any number of times to form a chunk. A chunk of whitespace may also contain any number of comments, but may neither begin nor end with a comment.

comments

A comment cell begins with #( and ends with a matching parenthesis ). Comment cells may contain other comments or cells.

Line comments begin with ## and end at the end of the line. Line comments have precedence over comment cells, i.e. comment cells within line comments do not continue past the end of the line.