From 63cdc4605d03635af45210f3fe7e4479bfe098ed Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 4 Aug 2025 23:09:16 +0200 Subject: docs/reference: add template string section --- docs/reference/01_syntax.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'docs/reference') diff --git a/docs/reference/01_syntax.md b/docs/reference/01_syntax.md index 445725c..4db70f9 100644 --- a/docs/reference/01_syntax.md +++ b/docs/reference/01_syntax.md @@ -71,10 +71,41 @@ 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"]) + # 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 -- cgit v1.2.3