TCL Syntax
Created on 2022-09-14T20:50:58-05:00
- A script is a string containing one or more commands.
- Commands are separated by semicolons and unescaped newlines.
- A backslash followed by a newline is an escaped newline. For the purposes of parsing that is treated as though a single space " " character had been read.
- Commands are comprised of one or more words which are any contiguous characters separated by whitespace.
- A word which begins with double quotes represents a string where all characters until the next unescaped double quote are treated as a single word.
- Argument expansion: if a word starts with {*} and a non whitespace character then argument expansion happens. Argument expansion removes the {*} characters and performs parsing and substitution as normal. The result of that parsing and substitution is then parsed as a list without further variable and word substitutions.
- Braces: if the first character of the word is a brace "{" then capture all characters until the closing brace "}". Braces nest so unescaped { within a block must be matched with unescaped }.
- Command substituion: if the first character of the word is a "[" then treat the characters after the [ as a recursive TCL interpretation. Run that script (up to the next unescaped "]".)
- Variable substitution: $foo, $foo(index), and ${foo) replaces the word with some value which has been looked up.
- Backslashes: backslashes inside of a word are replaced according to a substitution table.
- Comments: When a word begins with "#" then ignore until after the next newline.
- Order of substitution: evaluation is done left to right and characters are touched only once.
- Substitution does not affect the bounds of a word. If the substitution introduces whitespace then those whitespace are considered part of the word.