Skip to content

Commit 57d713a

Browse files
docs(examples): add new TOON examples for delimiter scoping and mismatch
1 parent b071a78 commit 57d713a

5 files changed

Lines changed: 34 additions & 12 deletions

File tree

examples/README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Complete, valid TOON files demonstrating core features:
5252
- Useful for TSV-like data
5353
- Spec: §11 Delimiters
5454

55+
- [`valid/delimiter-scoping.toon`](valid/delimiter-scoping.toon) - Document vs active delimiter
56+
- Shows that tabular row cells split only on the active delimiter
57+
- Shows that object field values still follow document delimiter quoting rules
58+
- Spec: §11.1 Delimiters (Encoding Rules)
59+
5560
### Key Folding and Path Expansion (v1.5+)
5661

5762
> Regenerate any of these examples via the reference CLI, e.g. `npx @toon-format/cli --encode --keyFolding safe examples/valid/key-folding-basic.json --output examples/valid/key-folding-basic.toon`.
@@ -87,45 +92,49 @@ Complete, valid TOON files demonstrating core features:
8792

8893
Examples that intentionally violate TOON syntax rules:
8994

90-
- **[`invalid/length-mismatch.toon`](invalid/length-mismatch.toon)** - Array length mismatch
95+
- [`invalid/length-mismatch.toon`](invalid/length-mismatch.toon) - Array length mismatch
9196
- Declares `[3]` but provides only 2 items
9297
- Should fail validation in strict mode
9398
- Spec: §14.1 Strict Mode (Array Count & Width)
9499

95-
- **[`invalid/missing-colon.toon`](invalid/missing-colon.toon)** - Missing colon after key
100+
- [`invalid/missing-colon.toon`](invalid/missing-colon.toon) - Missing colon after key
96101
- Keys must be followed by `:`; when a value appears on the same line, the format MUST be `: ` (colon + single space)
97102
- Demonstrates common syntax error
98103
- Spec: §8 Objects, §14.2 Syntax Errors
99104

100-
- **[`invalid/path-expansion-conflict-strict.toon`](invalid/path-expansion-conflict-strict.toon)** - Path expansion conflict (v1.5+)
105+
- [`invalid/path-expansion-conflict-strict.toon`](invalid/path-expansion-conflict-strict.toon) - Path expansion conflict (v1.5+)
101106
- First line creates nested path `user.profile.name`, second line tries to assign primitive to `user.profile`
102107
- Fails when decoded with `expandPaths="safe"` and `strict=true` (default)
103108
- With `strict=false`, applies LWW conflict resolution (later value wins)
104109
- Spec: §13.4 Path Expansion, §14.5 Conflicts
105110

106-
- **[`invalid/key-folding-non-identifier.toon`](invalid/key-folding-non-identifier.toon)** - Non-identifier segments (v1.5+)
107-
- Contains keys like `first-name` with hyphens (not valid IdentifierSegments)
111+
- [`valid/key-folding-non-identifier.toon`](valid/key-folding-non-identifier.toon) - Non-identifier segments (v1.5+)
112+
- Contains dotted keys with segments like `first-name` with hyphens (not valid IdentifierSegments)
113+
- Keys are quoted (hyphens are not allowed in unquoted keys)
108114
- These remain as literal dotted keys when `expandPaths="safe"` is used
109-
- Demonstrates safe mode validation: only expands keys with valid identifier segments
110-
- Note: This is NOT an error – it's valid TOON, but shows when expansion doesn't occur
111-
- Spec: §13.4 Safe Mode Requirements, §1.9 IdentifierSegment
115+
- Spec: §13.4 Safe Mode Requirements, §1.9 IdentifierSegment, §7.3 Key Encoding
116+
117+
- [`invalid/delimiter-mismatch.toon`](invalid/delimiter-mismatch.toon) - Header delimiter mismatch
118+
- Declares pipe delimiter in brackets (`[N|]`) but uses comma-separated fields (`{a,b}`)
119+
- MUST error in strict mode
120+
- Spec: §6 Header Syntax (delimiter equality requirement)
112121

113122
## Conversions
114123

115124
Side-by-side JSON ↔ TOON examples showing equivalent representations:
116125

117-
- **[`conversions/users.json`](conversions/users.json)** + **[`conversions/users.toon`](conversions/users.toon)**
126+
- [`conversions/users.json`](conversions/users.json) + [`conversions/users.toon`](conversions/users.toon)
118127
- Same tabular data in both formats
119128
- Shows token reduction achieved by TOON (≈30-60% for tabular data)
120129
- Demonstrates the primary use case: uniform arrays of objects
121130

122-
- **[`conversions/config.json`](conversions/config.json)** + **[`conversions/config.toon`](conversions/config.toon)** (v1.5+)
131+
- [`conversions/config.json`](conversions/config.json) + [`conversions/config.toon`](conversions/config.toon) (v1.5+)
123132
- Deeply nested configuration data (server, database, logging settings)
124-
- Regenerated with `keyFolding="safe"`; because most objects are multi-key, folding halts quickly and the output stays primarily nested (the **stop condition**)
133+
- Regenerated with `keyFolding="safe"`; because most objects are multi-key, folding halts quickly and the output stays primarily nested (the stop condition)
125134
- Shows ≈40-50% token reduction versus the JSON source while remaining spec-compliant
126135
- Highlights how safe folding behaves when little or no folding is permitted
127136

128-
- **[`conversions/api-response.json`](conversions/api-response.json)** + **[`conversions/api-response.toon`](conversions/api-response.toon)** (v1.5+)
137+
- [`conversions/api-response.json`](conversions/api-response.json) + [`conversions/api-response.toon`](conversions/api-response.toon) (v1.5+)
129138
- API response with nested data and metadata
130139
- Regenerated with `keyFolding="safe"`; multi-sibling branches like `data` and `meta` stay fully nested instead of becoming dotted keys (stop condition on display)
131140
- Shows practical use case for serializing API responses while preserving deterministic structure
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
items[2|]{a,b}:
2+
1|2
3+
3|4
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rows[1|]{id|value}:
2+
1|a,b
3+
4+
items[1|]:
5+
- note: "a,b"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"user.first-name": Ada
2+
"user.last-name": Lovelace
3+
"contact.e-mail": ada@example.com
4+
"settings.notify-by-email": true

examples/valid/objects.toon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ name: Ada Lovelace
33
active: true
44
email: ada@example.com
55
score: 98.5
6+
nickname: null

0 commit comments

Comments
 (0)