Skip to content

Commit b433833

Browse files
committed
piml
1 parent 5b7fc0b commit b433833

File tree

5 files changed

+549
-264
lines changed

5 files changed

+549
-264
lines changed

public/posts/piml-deep-dive.txt

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# piml (Parenthesis Intended Markup Language)
2+
3+
In the ever-evolving landscape of data serialization formats, PIML (Parenthesis Intended Markup Language) emerges as a compelling alternative, prioritizing human readability and writability without compromising machine parseability. This post delves into the core tenets of PIML, exploring its syntax, data types, and how it stacks up against established formats like JSON, YAML, and TOML.
4+
5+
## What is PIML?
6+
7+
PIML is a data serialization format designed for clarity and ease of use by both humans and machines. It leverages a unique `(key)` syntax and indentation-based nesting to create a visually intuitive representation of structured data. Conceived as a middle ground between the verbosity of JSON and the potential ambiguity of YAML, PIML aims to offer a clean, unambiguous, and highly readable format for various data exchange and configuration needs.
8+
9+
## Syntax Rules: The Building Blocks of PIML
10+
11+
PIML's syntax is intentionally minimal, focusing on consistency and clarity.
12+
13+
### Keys
14+
15+
Keys are the identifiers for data elements and are always enclosed in parentheses. This explicit demarcation makes keys instantly recognizable.
16+
17+
```piml
18+
(my_key) my_value
19+
(another key with spaces) another_value
20+
```
21+
22+
### Indentation
23+
24+
Indentation is fundamental to PIML's structure, defining hierarchical relationships between data elements.
25+
26+
* **Recommendation:** Use **2 spaces** for each level of indentation to maintain visual consistency.
27+
* **Strict Rule:** Mixing tabs and spaces for indentation is **prohibited** to prevent parsing ambiguities.
28+
29+
### Comments
30+
31+
PIML supports single-line comments using the `#` symbol. Anything from `#` to the end of the line is ignored by parsers, allowing for clear inline documentation.
32+
33+
```piml
34+
(data) value # This explains the data
35+
```
36+
37+
### Escaping
38+
39+
The backslash (`\`) character is used to escape special characters within string values, ensuring that characters like `(` or `#` can be part of the data itself.
40+
41+
* Common escapes include `\n` (newline), `\t` (tab), and `\\` (literal backslash).
42+
* Example: `(title) My \(Awesome\) Title
43+
44+
## Data Types: Representing Information in PIML
45+
46+
PIML supports a range of data types, from simple primitives to complex nested structures.
47+
48+
### Primitive Types
49+
50+
* **Single-line Strings:** Unquoted text values that reside on a single line.
51+
```piml
52+
(name) John Doe
53+
```
54+
* **Integers:** Whole numbers.
55+
```piml
56+
(age) 30
57+
```
58+
* **Floats:** Decimal numbers.
59+
```piml
60+
(price) 19.99
61+
```
62+
* **Booleans:** Logical values, represented as `true` or `false`.
63+
```piml
64+
(is_active) true
65+
```
66+
67+
### Null and Empty Representations: The `nil` Unifier
68+
69+
One of PIML's distinctive features is the use of `nil` as a unified representation for three distinct states:
70+
71+
1. **Null:** The absence of a value.
72+
2. **Empty Array:** An empty list.
73+
3. **Empty Object:** An empty map.
74+
75+
```piml
76+
(optional_setting) nil
77+
(empty_items) nil
78+
(empty_config) nil
79+
```
80+
81+
This design choice prioritizes syntactic simplicity, though it means the specific *type* of an empty collection (array vs. object) is not preserved when `nil` is used.
82+
83+
### Multi-line Strings
84+
85+
For text spanning multiple lines, PIML allows the content to start on the next indented line, preserving newlines.
86+
87+
```piml
88+
(description)
89+
This is a multi-line string example.
90+
It can hold extensive textual content.
91+
```
92+
93+
### Arrays (Lists)
94+
95+
Ordered collections of items are denoted by a `>` prefix on each indented item.
96+
97+
```piml
98+
(fruits)
99+
> apple
100+
> banana
101+
> orange
102+
```
103+
104+
### Sets (Unique, Unordered Collections)
105+
106+
PIML introduces `>|` for sets, which are collections of unique, unordered items. Duplicate values are ignored by parsers.
107+
108+
```piml
109+
(unique_ids)
110+
>| id_a
111+
>| id_b
112+
>| id_a # This duplicate will be ignored
113+
```
114+
115+
### Objects (Maps)
116+
117+
Unordered key-value pairs are defined through indentation, creating nested structures.
118+
119+
```piml
120+
(user)
121+
(name) Alice
122+
(email) alice@example.com
123+
```
124+
125+
#### List of Objects
126+
127+
PIML provides a clear way to represent lists of objects, combining the array `>` marker with nested object syntax. The key within the object (e.g., `(contributor)`) serves as metadata for readability and is ignored by parsers.
128+
129+
```piml
130+
(contributors)
131+
> (contributor)
132+
(id) 1
133+
(name) Bob
134+
> (contributor)
135+
(id) 2
136+
(name) Carol
137+
```
138+
139+
### Specialized Types (by Convention)
140+
141+
PIML encourages conventions for specialized data:
142+
143+
* **Dates/Times:** Typically represented as strings in ISO 8601 format (e.g., `2023-10-27T10:30:00Z`).
144+
* **Binary Data:** Usually encoded as base64 strings.
145+
146+
## PIML in Action: A Comprehensive Example
147+
148+
Let's look at a more complete example demonstrating various PIML features:
149+
150+
```piml
151+
(document_metadata)
152+
(title) PIML Specification Document
153+
(version) 1.0.0
154+
(author) Fezcodex
155+
(creation_date) 2025-11-12T10:00:00Z
156+
(is_draft) true
157+
(tags)
158+
> data-format
159+
> serialization
160+
> piml
161+
(abstract)
162+
This document outlines the PIML format,
163+
its syntax, and its design philosophy.
164+
It aims for human-centric data representation.
165+
(contact)
166+
(email) contact@example.com
167+
(website) [https://fezcode.github.io](https://fezcode.github.io)
168+
(empty_settings) nil
169+
170+
(configuration)
171+
(database)
172+
(type) SQLite
173+
(path) /data/app.db
174+
(max_connections) 50
175+
(api_keys)
176+
>| key_abc
177+
>| key_xyz
178+
(feature_toggles)
179+
(new_ui) true
180+
(beta_analytics) false
181+
```
182+
183+
## PIML vs. The World: A Comparison
184+
185+
PIML carves its niche by offering a distinct balance of features compared to other popular data formats.
186+
187+
### PIML vs. JSON
188+
189+
* **PIML Advantages:**
190+
* **Readability:** Significantly less visual noise due to the absence of quotes for keys and single-line strings, and no mandatory commas.
191+
* **Comments:** Native support for `#` comments, a feature lacking in JSON.
192+
* **Multi-line Strings:** More natural and cleaner syntax for multi-line text.
193+
* **PIML Trade-off:**
194+
* **`nil` Ambiguity:** The unified `nil` for null, empty arrays, and empty objects simplifies syntax but means PIML cannot perfectly distinguish between these empty collection types, potentially affecting round-trip conversions from JSON.
195+
196+
### PIML vs. YAML
197+
198+
* **PIML Advantages:**
199+
* **Simplicity & Predictability:** PIML's syntax is much smaller and more constrained, avoiding the "many ways to do one thing" complexity and the subtle whitespace pitfalls often associated with YAML. The explicit `(key)` syntax reduces ambiguity.
200+
* **PIML Trade-off:**
201+
* **Feature Set:** PIML deliberately omits advanced YAML features like anchors, aliases, and complex document structures, focusing on a simpler, more direct representation.
202+
203+
### PIML vs. TOML
204+
205+
* **PIML Advantages:**
206+
* **Nesting Flexibility:** PIML's indentation-based nesting is more adaptable for arbitrarily deep and complex data structures, contrasting with TOML's more rigid `[table]` and `[[array of tables]]` approach.
207+
* **PIML Trade-off:**
208+
* **Configuration Focus:** TOML excels as a configuration file format due to its flat, key-value pair nature. PIML is more general-purpose, though it can certainly be used for configuration.
209+
210+
## Conclusion
211+
212+
PIML offers a refreshing perspective on data serialization, emphasizing human-centric design while maintaining machine parseability. Its explicit key syntax, indentation-driven structure, and thoughtful approach to data types make it a strong contender for scenarios where clarity, readability, and ease of writing are paramount. As data continues to grow in complexity, formats like PIML provide valuable alternatives for developers seeking more intuitive ways to manage and exchange information.

public/posts/posts.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"slug": "piml",
4+
"title": "piml (Parenthesis Intended Markup Language) Deep Dive",
5+
"date": "2025-11-12",
6+
"updated": "2025-11-12",
7+
"description": "A deep dive into PIML, a human-readable data serialization format, its syntax, data types, and comparison with JSON, YAML, and TOML.",
8+
"tags": ["piml", "data-format", "serialization", "markup", "dev"],
9+
"category": "dev",
10+
"filename": "piml-deep-dive.txt"
11+
},
212
{
313
"slug": "image-toolkit-deep-dive",
414
"title": "Image Toolkit Deep Dive",

0 commit comments

Comments
 (0)