aboutsummaryrefslogtreecommitdiffstats
path: root/docs/reference
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-08-04 21:09:16 +0000
committers-ol <s+removethis@s-ol.nu>2025-08-04 21:35:30 +0000
commit63cdc4605d03635af45210f3fe7e4479bfe098ed (patch)
tree5d89d273a1c24081f2768410e313956edf89b53c /docs/reference
parentbuiltins: add fmt (diff)
downloadalive-63cdc4605d03635af45210f3fe7e4479bfe098ed.tar.gz
alive-63cdc4605d03635af45210f3fe7e4479bfe098ed.zip
docs/reference: add template string section
Diffstat (limited to 'docs/reference')
-rw-r--r--docs/reference/01_syntax.md31
1 files changed, 31 insertions, 0 deletions
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