|
| 1 | +# piml |
| 2 | + |
| 3 | +## Parenthesis Intended Markup Language |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +## What is PIML? |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +## Syntax Rules: The Building Blocks of PIML |
| 12 | + |
| 13 | +PIML's syntax is intentionally minimal, focusing on consistency and clarity. |
| 14 | + |
| 15 | +### Keys |
| 16 | + |
| 17 | +Keys are the identifiers for data elements and are always enclosed in parentheses. This explicit demarcation makes keys instantly recognizable. |
| 18 | + |
| 19 | +```piml |
| 20 | +(my_key) my_value |
| 21 | +(another key with spaces) another_value |
| 22 | +``` |
| 23 | + |
| 24 | +### Indentation |
| 25 | + |
| 26 | +Indentation is fundamental to PIML's structure, defining hierarchical relationships between data elements. |
| 27 | + |
| 28 | +* **Recommendation:** Use **2 spaces** for each level of indentation to maintain visual consistency. |
| 29 | +* **Strict Rule:** Mixing tabs and spaces for indentation is **prohibited** to prevent parsing ambiguities. |
| 30 | + |
| 31 | +### Comments |
| 32 | + |
| 33 | +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. |
| 34 | + |
| 35 | +```piml |
| 36 | +(data) value # This explains the data |
| 37 | +``` |
| 38 | + |
| 39 | +### Escaping |
| 40 | + |
| 41 | +The backslash (`\`) character is used to escape special characters within string values, ensuring that characters like `(` or `#` can be part of the data itself. |
| 42 | + |
| 43 | +* Common escapes include `\n` (newline), `\t` (tab), and `\\` (literal backslash). |
| 44 | +* Example: `(title) My \(Awesome\) Title |
| 45 | + |
| 46 | +## Data Types: Representing Information in PIML |
| 47 | + |
| 48 | +PIML supports a range of data types, from simple primitives to complex nested structures. |
| 49 | + |
| 50 | +### Primitive Types |
| 51 | + |
| 52 | +* **Single-line Strings:** Unquoted text values that reside on a single line. |
| 53 | + ```piml |
| 54 | + (name) John Doe |
| 55 | + ``` |
| 56 | +* **Integers:** Whole numbers. |
| 57 | + ```piml |
| 58 | + (age) 30 |
| 59 | + ``` |
| 60 | +* **Floats:** Decimal numbers. |
| 61 | + ```piml |
| 62 | + (price) 19.99 |
| 63 | + ``` |
| 64 | +* **Booleans:** Logical values, represented as `true` or `false`. |
| 65 | + ```piml |
| 66 | + (is_active) true |
| 67 | + ``` |
| 68 | + |
| 69 | +### Null and Empty Representations: The `nil` Unifier |
| 70 | + |
| 71 | +One of PIML's distinctive features is the use of `nil` as a unified representation for three distinct states: |
| 72 | + |
| 73 | +1. **Null:** The absence of a value. |
| 74 | +2. **Empty Array:** An empty list. |
| 75 | +3. **Empty Object:** An empty map. |
| 76 | + |
| 77 | +```piml |
| 78 | +(optional_setting) nil |
| 79 | +(empty_items) nil |
| 80 | +(empty_config) nil |
| 81 | +``` |
| 82 | + |
| 83 | +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. |
| 84 | + |
| 85 | +### Multi-line Strings |
| 86 | + |
| 87 | +For text spanning multiple lines, PIML allows the content to start on the next indented line, preserving newlines. |
| 88 | + |
| 89 | +```piml |
| 90 | +(description) |
| 91 | + This is a multi-line string example. |
| 92 | + It can hold extensive textual content. |
| 93 | +``` |
| 94 | + |
| 95 | +### Arrays (Lists) |
| 96 | + |
| 97 | +Ordered collections of items are denoted by a `>` prefix on each indented item. |
| 98 | + |
| 99 | +```piml |
| 100 | +(fruits) |
| 101 | + > apple |
| 102 | + > banana |
| 103 | + > orange |
| 104 | +``` |
| 105 | + |
| 106 | +### Sets (Unique, Unordered Collections) |
| 107 | + |
| 108 | +PIML introduces `>|` for sets, which are collections of unique, unordered items. Duplicate values are ignored by parsers. |
| 109 | + |
| 110 | +```piml |
| 111 | +(unique_ids) |
| 112 | + >| id_a |
| 113 | + >| id_b |
| 114 | + >| id_a # This duplicate will be ignored |
| 115 | +``` |
| 116 | + |
| 117 | +### Objects (Maps) |
| 118 | + |
| 119 | +Unordered key-value pairs are defined through indentation, creating nested structures. |
| 120 | + |
| 121 | +```piml |
| 122 | +(user) |
| 123 | + (name) Alice |
| 124 | + (email) alice@example.com |
| 125 | +``` |
| 126 | + |
| 127 | +#### List of Objects |
| 128 | + |
| 129 | +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. |
| 130 | + |
| 131 | +```piml |
| 132 | +(contributors) |
| 133 | + > (contributor) |
| 134 | + (id) 1 |
| 135 | + (name) Bob |
| 136 | + > (contributor) |
| 137 | + (id) 2 |
| 138 | + (name) Carol |
| 139 | +``` |
| 140 | + |
| 141 | +### Specialized Types (by Convention) |
| 142 | + |
| 143 | +PIML encourages conventions for specialized data: |
| 144 | + |
| 145 | +* **Dates/Times:** Typically represented as strings in ISO 8601 format (e.g., `2023-10-27T10:30:00Z`). |
| 146 | +* **Binary Data:** Usually encoded as base64 strings. |
| 147 | + |
| 148 | +## PIML in Action: A Comprehensive Example |
| 149 | + |
| 150 | +Let's look at a more complete example demonstrating various PIML features: |
| 151 | + |
| 152 | +```piml |
| 153 | +(document_metadata) |
| 154 | + (title) PIML Specification Document |
| 155 | + (version) 1.0.0 |
| 156 | + (author) Fezcodex |
| 157 | + (creation_date) 2025-11-12T10:00:00Z |
| 158 | + (is_draft) true |
| 159 | + (tags) |
| 160 | + > data-format |
| 161 | + > serialization |
| 162 | + > piml |
| 163 | + (abstract) |
| 164 | + This document outlines the PIML format, |
| 165 | + its syntax, and its design philosophy. |
| 166 | + It aims for human-centric data representation. |
| 167 | + (contact) |
| 168 | + (email) contact@example.com |
| 169 | + (website) [https://fezcode.github.io](https://fezcode.github.io) |
| 170 | + (empty_settings) nil |
| 171 | + |
| 172 | +(configuration) |
| 173 | + (database) |
| 174 | + (type) SQLite |
| 175 | + (path) /data/app.db |
| 176 | + (max_connections) 50 |
| 177 | + (api_keys) |
| 178 | + >| key_abc |
| 179 | + >| key_xyz |
| 180 | + (feature_toggles) |
| 181 | + (new_ui) true |
| 182 | + (beta_analytics) false |
| 183 | +``` |
| 184 | + |
| 185 | +## PIML vs. The World: A Comparison |
| 186 | + |
| 187 | +PIML carves its niche by offering a distinct balance of features compared to other popular data formats. |
| 188 | + |
| 189 | +### PIML vs. JSON |
| 190 | + |
| 191 | +* **PIML Advantages:** |
| 192 | + * **Readability:** Significantly less visual noise due to the absence of quotes for keys and single-line strings, and no mandatory commas. |
| 193 | + * **Comments:** Native support for `#` comments, a feature lacking in JSON. |
| 194 | + * **Multi-line Strings:** More natural and cleaner syntax for multi-line text. |
| 195 | +* **PIML Trade-off:** |
| 196 | + * **`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. |
| 197 | + |
| 198 | +### PIML vs. YAML |
| 199 | + |
| 200 | +* **PIML Advantages:** |
| 201 | + * **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. |
| 202 | +* **PIML Trade-off:** |
| 203 | + * **Feature Set:** PIML deliberately omits advanced YAML features like anchors, aliases, and complex document structures, focusing on a simpler, more direct representation. |
| 204 | + |
| 205 | +### PIML vs. TOML |
| 206 | + |
| 207 | +* **PIML Advantages:** |
| 208 | + * **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. |
| 209 | +* **PIML Trade-off:** |
| 210 | + * **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. |
| 211 | + |
| 212 | +## Conclusion |
| 213 | + |
| 214 | +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. |
0 commit comments