Design decisions¶
Decisions made for the language and the library, newest last. The reason is kept with each one. Syntax, grammar and boundary changes are recorded here, in this repo, not left in the vault.
G rows answer the 12 grammar ambiguities of the First Slice note (vault: 41 TDL Reference/tess-dl First Slice.md). The note leaves them to the tess-dl session: each takes the note's recommendation unless the Notes column says otherwise. The maintainer answered the open questions on 2026-11-02; they are G13 to G18.
2026-11-02 (grammar, plan step 1)¶
| # | Decision | Notes |
|---|---|---|
| G1 | An unquoted value is one kind, Word, whose text is the whole run (spaces inside kept, outer whitespace dropped). A word whose text is a number is a Number. |
The rule "an unquoted value runs to the end of the line, the next ,, a closing brace or a comment" implies one run. Hello world is one word; 1st is a word; 16 is a number. |
| G2 | In the metadata block every bare value is a Word, never a number. 0.1 is the text 0.1. |
Versions are strings (ADR-0014 layout rule 3): 0.10 and 0.1 must not be the same value. |
| G3 | Numbers are 16, -4, 0.9: an optional -, digits, optionally . and digits. No exponent, hex, digit separators, leading +, .5 or 5.. A word that only starts with digits (16px) is a word. |
Smallest set the shell's lengths and opacities need. More can be added later without breaking a file. |
| G4 | Call starts at any word written directly against (; the arguments are values separated by spaces, to the ), on one line. |
The shell, not the parser, knows which call names exist, so it can say "unknown colour function". |
| G5 | String escapes: \\, \", \', \n, \t, \u plus four hex digits. Anything else is tdl-bad-escape. |
As recommended. |
| G6 | Line endings, tabs, BOM: \n and \r\n are both accepted and each line keeps its own; a tab is whitespace; a leading BOM is accepted and kept; a lone \r is plain whitespace; a --- line may have trailing spaces or tabs. |
A lossless tree must keep all of them. The lone \r and trailing-space details go beyond the recommendation; they are the least surprising reading. |
| G7 | A slot is on one line. A line end before }} is tdl-unclosed-slot. |
D54 of the vault's ADR-0014. |
| G8 | A list may span lines; items are separated by , or a newline, with an optional trailing ,. |
As recommended; matches how entries are separated in a block. |
| G9 | Children is an ordinary block and Import an ordinary property. Only If, Else, For, In and Key are reserved. |
The parser stays free of the shell's meaning. |
| G10 | Key characters: a letter, then letters, digits and _. The same rule serves block heads, For variables and Name: values. |
D4 forbids numeric keys. One rule for every name keeps tdl-bad-name simple. |
| G11 | Maximum nesting depth is 64, counting the root block as 1; blocks, If/For bodies and lists each add a level. |
Proposed by the note. A stack-safe parser must reach it without a RecursionError. |
| G12 | Trivia is kept in source spans, not modelled. Comments are entries in their block in source order; blank lines and indentation live in the spans between nodes. | Keeps the tree small and makes the exact round trip a property of the spans (lossless-roundtrip). |
| G13 | One more language code: tdl-unexpected-text, for text that is not valid where it stands: a missing colon (Width 32), a key with no value, an Else with no If, a For without In or Key, an unclosed ( in a call, a stray { in an unquoted value. The message and hint say which case. |
Answers Q1 (maintainer, 2026-11-02). It makes 18 language errors; the vault's "17" and its TDL Language error table need the new row. |
| G14 | In value position, a # followed directly by a non-space character is tdl-bare-hash; a # followed by whitespace or the end of the line is a comment. |
Answers Q2 (maintainer). Color: #fff is an error; Color: # note is an empty value (G16) and a comment. |
| G15 | A slot delimiter ({{ }}, <| |> since G38) inside a quoted string is plain text. A quoted string never holds a slot; a template is written unquoted. |
Answers Q3 (maintainer). Quotes switch slots off. |
| G16 | A property with no value is an error (tdl-unexpected-text). |
Answers Q4 (maintainer). |
| G17 | Else follows the If body's closing brace, on the same line or after newlines and comments. |
Answers Q5 (maintainer). |
| G18 | The four extra codes are accepted: tdl-too-large (over 1 MiB, checked before parsing), tdl-too-deep (over 64 levels), tdl-unsupported-version (the TDL: version is newer than the library's), tdl-bad-encoding (invalid UTF-8 in load, with the byte offset). |
Answers Q6 (maintainer). Together with G13 the library has 22 codes. |
2026-11-02 (corpus, plan step 2)¶
| # | Decision | Notes |
|---|---|---|
| G19 | Withdrawn by G38. }} rule. An adjacent }} outside a slot and outside a string is always tdl-double-close, pointing at the first } of the pair, whatever the number of open blocks. |
Keeps the rule lexical. {{ {'a': {'b': 1}} }} ends the slot at the first }} and the trailing }} is then tdl-double-close. |
| G20 | Positions of the two vague "points at" rows. tdl-no-root points at the first character after the closing --- line, including its line ending (5:1 when --- is line 4 and ends with \n; 4:4 if the file ends right after the ---). tdl-unexpected-text: a missing value, at the first non-whitespace character after the : (the # of a comment, or the line end); a key with no :, at the first character after the key and its whitespace; an unclosed (, at the line end; For without Key, at the { that opens the body; For without In, at the first {{ after the variable; Else without If, at the Else; a stray { in an unquoted value, at that {. |
The note leaves both open; each position is the first character that does not fit. |
| G21 | tdl-bad-encoding position. Line and column are computed from the valid UTF-8 prefix before the first bad byte (line = 1 + newlines in the prefix; column = 1 + characters since the last newline). |
The bad byte itself cannot be counted in characters. |
| G22 | canonical() shape (what expect.json "canonical" holds): {"metadata": {KEY: VALUE, ...}, "root": BLOCK}, comments dropped. Value: {"word": text}, {"string": resolved_value}, {"number": 16} (JSON int) or {"number": 0.9} (JSON float), {"percent": 50}, {"call": name, "args": [value, ...]}, {"list": [value, ...]}, {"slot": text} (exactly as between the braces), {"template": [{"text": "Battery "}, {"slot": " battery.percent "}, {"text": "%"}]}. Entry: {"block": type, "entries": [entry, ...]}, {"property": key, "value": value}, {"if": slot_value, "body": [entry...], "else": [entry...] or null}, {"for": variable, "in": slot_value, "key": slot_value, "body": [entry...]}. A metadata value is a word or a string. The runner compares json.dumps(x, sort_keys=True) of both sides, so 16 and 16.0 differ. |
One shape for the runner and the shell to read; no positions and no comments. |
| G23 | Edit cases are three files: <case>.tdl, <case>.expect.json holding {"edit": {"call": ..., ...}}, and <case>.result.tdl. Calls: with_metadata (key, value), without_metadata (key), with_property (block: dotted path of Name: values as Document.find takes, key, value: the TDL text of the value), replace (start, end: character offsets, text). Every call returns a Document; with_property is run as doc.find(block).with_property(key, value) and the returned Document is the result. A refused edit is {"edit": {...}, "raises": "tdl-no-name"} with no .result.tdl. |
The vault says an edit returns a new Document. replace offsets and the with_property return type are the choices the maintainer may want to change. |
| G24 | Metadata insert rules for edits. with_metadata("UID", v) with no UID inserts UID: v on a new line directly after the last metadata line whose key is TDL or a version key (Shell). With a UID present only the value bytes change. Any other new key goes on a new line directly before the closing ---. A new line has no indentation and takes the line ending of the line before it. with_property adds Key: value on a new line after the last property of the block, with that property's indentation and the file's line ending there. |
Keeps an edit to the bytes it must change (lossless-roundtrip). |
| G25 | Cap entry. With Limits(max_errors=50), a file with 60 mistakes gives len(result.errors) == 50 and the message of the last entry contains the text 50. |
The vault says only "the last entry says so". |
| G26 | Step 3 follows the brief's row boundary. Step 3 is the tree, the parser and canonical() on a parsed document; it is done when loads plus canonical() match for every ok case (test_ok_case_reads_to_the_canonical_tree). dumps, load and the byte-for-byte round trip are step 5 (test_ok_case_round_trips_byte_for_byte). canonical() on a document read from text is in the first release because the corpus needs it; the formatter and canonical() on a tree built in code stay out until API Open Question 3 is answered. |
The brief lists canonical() under "Not in the First Slice", meaning the Python-builder use. The corpus is read by the shell and needs it on parsed trees. |
| G27 | Calls count as nesting levels, like blocks, bodies and lists: f(f(f(...))) deeper than 64 is tdl-too-deep at the f that passes the limit. |
A call can nest inside a call, so without a level count a long run of f( would overflow Python's stack. G11 listed only blocks, bodies and lists. |
| G28 | Step 4 follows the brief's row boundary. loads is the step 4 check: it raises the first listed error with its code, position, related origins, message and hint (test_error_case_loads_raises_the_first_listed_error, all text cases). tdl-bad-encoding needs bytes, so its error is built by a private decoder in step 4 and load is wired to it in step 5 (test_error_case_load_raises_the_same_first_error). The full list through parse is step 7 (test_error_case_parse_lists_every_listed_error). |
The brief says step 4 is done when the error cases pass, but load is step 5 and parse step 7; one test per step keeps each step checkable on its own. |
| G29 | Every tdl-unexpected-text kind is documented and has a corpus case. The reader had 24 places that raise it; the list in language.md now names all the kinds and where each points (G20 extended), and tests/corpus/errors/ has a case for each. Also: a # or , inside a call is an error (a # followed by a non-space is tdl-bare-hash); an unclosed [ points at the } or end of file that reaches it; a TDL: value that does not start with a number is tdl-unsupported-version. |
Step 4's audit. These are positions and kinds, not new codes, so they stay inside the session's decisions. |
| G30 | dumps returns the source text; load reads at most max_bytes + 1 bytes; a str that cannot be UTF-8 is tdl-bad-encoding. dumps(doc) is doc.text (no re-rendering), dump writes it as UTF-8 with the byte-order mark kept. load refuses a longer input as tdl-too-large without reading it whole. loads on text with a lone surrogate raises tdl-bad-encoding at that character instead of UnicodeEncodeError. |
The API promises loads raises only TDLError; a Python str can hold characters that no UTF-8 file can (found in step 4). The code's wording said "load only", which now means bytes or text that cannot be UTF-8. |
| G32 | How the edit calls behave where G23 and G24 are silent. (1) A metadata value is plain text: written as a bare word when it reads back the same (non-empty, no outer space, no leading quote or #, no line end, no #), else as a double-quoted string with \\, \", \n, \t and \u000d escapes. (2) with_property takes the TDL text of exactly one value on one line; it is checked by reading it alone, so 1 }, a, b and 1 # c are refused with ValueError. (3) with_property adds inline (Panel { A: 1, H: 40 }) when the last property shares its line with something other than a comment, puts a first property after the { line with the first entry's indentation (or the head's plus two spaces), and inline after the { in a one-line block. (4) Document.find(path): the first name is the metadata Name and stands for the root block; each next name is the Name: of a block directly inside the one before; the first match wins; none raises KeyError. (5) without_metadata of an absent key returns the same document. (6) A call that is wrong whatever the file holds raises ValueError; a result that is not a valid file raises TDLError. |
G23 and G24 give the corpus cases; these are the rules the cases leave open, chosen so an edit can never silently change anything but the named bytes. |
| G31 | How parse recovers. parse returns ParseResult(document, errors) with the errors in source order. A bad entry is skipped to the end of its line or to the } that closes its block, skipping braces the bad line opened itself; a bad metadata line is skipped and the next read; }} is reported once and closes up to two open blocks; each unclosed { is reported when the file ends; a second root block is reported and read; the limit errors stop the file with one error. The cap keeps the first 50 errors found; the 50th says The list stops at 50 errors. only when there was a 51st; nothing is read after it. document is the tree without the bad entries, or None. loads stops at the first mistake it meets, which parse lists too. The corpus case slot-ends-at-first-close now lists two errors: after {{ {'a': {'b': 1}} }} the trailing }} closes the root block and the file's last } is a stray one. |
G25 left open how the cap is marked and what the tree holds. Cascades from one mistake are kept small by balanced-brace skipping; a mistake that opens a block on its own line (If {) can still cascade, which the cap bounds. |
| G33 | The conformance corpus ships in the source distribution, not in the wheel. tests/ (with tests/corpus/) is in the sdist; the wheel holds only src/tess_dl, py.typed and the licence. The shell reads the corpus of a released version from the sdist or the tag. |
A wheel that installed tests/corpus/ would put a top-level tests directory in every environment. The First Slice brief says the shell installs the package's test data or copies a released version; this takes the second. The maintainer may prefer a separate tesserae-dl-corpus package. |
| G34 | The import name is tess_dl, not tdl. The package directory is src/tess_dl and every import tdl became import tess_dl. The PyPI name stays tesserae-dl. The error-code slugs (tdl-unclosed-block), the .tdl file extension and the language's name (TDL) are unchanged: they name the language, not the module. There is no tdl alias or shim. |
tdl is short enough to collide with another project's top-level package, and a top-level name cannot be shared. tess_dl follows the repo name (tess-dl) and is unlikely to clash. 0.1.0 was published with tdl, so this is a breaking change: it needs a new version (before 1.0 a minor bump may break the API), and the maintainer decides which. A hypothetical future command-line tool may still be called tdl; that is a command, not an import. |
| G35 | Block edits and index paths (task T-011, for tess-ui's configuration application). Block.without_property(key), Block.with_child(block_text, index=None) -> (Document, Block), Block.without_child(child) and Block.move_child(child, to) return a new Document (as with_property does); Block.index_path and Document.at(index_path) give a stable address. Index paths: the entry indexes from the root, comments included; an If counts its body then its else body. index and to count all entries (tess-ui's answer (a)); without_property of an absent key is a KeyError (answer (b), unlike without_metadata, G32); with_child also returns the new block (answer (c)). An index that points at a comment at the end of a line is moved past it. block_text errors are TDLSyntaxError with origins inside the text (file <block_text>), because the application underlines the user's text. A whole-line removal takes the comment at the end of the line; comment lines above stay. The reread result is checked to hold exactly the expected entries. Only a block can be inserted; an If or For can be moved and removed, not inserted. |
A selection must survive edits and many blocks have no name, so an address by position is needed; the guard makes a layout the rules did not foresee fail loudly instead of changing the file's meaning. Tier 1 (non-breaking additions), requested by tess-ui through tess-shell-vault. |
| G36 | The formatter and its canonical layout (task T-011, second branch). format_block(text) -> str (no trailing line ending) and format(document) -> Document. Layout: two spaces a level; one entry per line with no , between entries; Type { } for an empty block; } Else { on one line, but comments between an If's } and its Else stay on their own lines (G17 allows them); single spaces in For x In {{ }} Key {{ }} {; Key: value; own-line comments stay own-line at the new indent and end-of-line comments stay at the end of their line after two spaces; values, slots, strings and comments are written exactly as written, a multi-line value keeps its inner layout re-based; one blank line where the source had one or more, none at the start or end of a block; metadata written the same way (a comment at the end of a metadata line is kept: the tree does not model it, so the formatter reads it from the text); comment and blank lines around the root block kept (one blank line at most); the line ending of the first line throughout, a BOM kept, one final line ending. The result is reread and must have the same canonical() and the same comments or ValueError; idempotent. format of a document with errors raises TDLSyntaxError. The name format shadows the builtin under from tess_dl import *; it is the name tess-ui and tess-shell-vault agreed (D-014, D-030). Formatting a tree built in code waits (api.md open question 3). |
The configuration application writes new blocks and tidy files; a layout that depends only on the text and the tree keeps every edit and every value as it was. Tier 1 (new functions), requested by tess-ui through tess-shell-vault. |
| G37 | Slot and variable edits on If and For (task T-040, for tess-ui's configuration application). If.with_condition(slot_text), For.with_items(slot_text), For.with_key(slot_text) and For.with_variable(name) return a new Document and replace only the bytes they name; every index_path stays valid (nothing is added or removed). slot_text is the slot with its braces as written in a file, trimmed of outer whitespace, the inside kept byte for byte; it is checked by reading it alone, so a syntax error is a TDLSyntaxError with origins inside the text (file <slot_text>) and valid TDL that is not exactly one slot (word, {{ a }} b, {{ a }}, B: 1, {{ a }} # c) is a ValueError. with_variable changes only the declaration: references in slots are not renamed, because a slot is opaque to this library and a text rename would also hit strings and attribute names with the same spelling; a rename helper needs TEL and is not part of v1 (tess-ui's answer). A variable name must be a key and not reserved, else ValueError; a node built in code is ValueError. The reread result is checked: the node at the same path must equal the old node with only that field changed. The name with_variable follows the field For.variable and avoids a clash with Block.name (the Name: property). An Else body stays addressable (G35: body entries, then else-body entries) and every edit works through it; adding or removing an Else, a block's type word and a property key are not edits here. |
The configuration application edits an If or For in place and must keep its selection; these four are the whole set it asked for. Tier 1 (new methods), requested by tess-ui through tess-shell-vault. |
| G38 | Slots are written <| expression |>; {{ }} is gone; a For may name several variables (language 0.2; issue #21, decided by the maintainer on 2026-11-14). A slot starts at <| and ends at the first |> outside a quoted string; the other slot rules (one line, tdl-empty-slot, tdl-unclosed-slot, text and text origin, templates, no slot inside a quoted string) are unchanged, and both delimiters are two characters wide, so positions do not move. }} and {{ are ordinary braces: tdl-double-close is removed (G19 withdrawn) and two } in a row close two blocks. A {{ in an unquoted value is tdl-unexpected-text with a hint to <| |>. For takes name[, name]... before In (tess-ui's request, written as in Python's unpacking): For.variables holds the names, For.variable stays as the first, canonical() writes a string for one name and a list for several, with_variable takes "i, item" or a sequence, the new code tdl-duplicate-variable points at the second use of a name, and TDL does not check what the loop binds. LANGUAGE_VERSION is "0.2"; tools/migrate_slots.py converts 0.1 files. This supersedes the slot spelling in G7, G15, G20 and G31. |
TEL's expressions hold dict and set literals, where {{ {'a': {'b': 1}} }} could not be written under G19. <| and |> cannot occur in a valid TEL or Python expression outside a string (after < or | an operand must follow, and none starts with | or >), unlike << >>, -| |- or </ />. |
No questions are open.