You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
self-ml ^1 is a structural data language designed to be written by</title>
91
+
</head>
92
+
<body>
93
+
<!-- Title: Introducing self-ml -->
94
+
95
+
96
+
<!-- Subtitle: A human data format -->
97
+
98
+
99
+
<!-- Slug: self-ml -->
100
+
101
+
102
+
<p>self-ml<ahref="self-ml">^1</a> is a structural data language designed to be written by humans and read by computers. Its syntax is based on <ahref="http://en.wikipedia.org/wiki/S-expression">S-expressions</a> with some changes and simplifications.</p>
103
+
104
+
<divclass="sidebar"><divclass="inner"><h3>Why not <strong>JSON</strong>?</h3><p><ahref="http://www.json.org/">JSON</a> is a great computer ↔ computer format. It's ideal for RSS feeds or the output of a website's API.<p>
105
+
106
+
<p>self-ml is designed as a human ↔ computer format. Its main use is for configuration files and structured data.</p></div></div>
107
+
108
+
109
+
<p>The biggest feature of self-ml is its simplicity. It <em>doesn’t</em> have attributes, namespaces, dictionaries, symbols or even numerics. Lists and strings are all you got.</p>
<p>As you can see, especially from the last example, self-ml is a lot more succinct than XML, easier to read and easier to write. There’s not a single backslash escape in sight: self-ml is Regex Friendly™. self-ml can have lists of strings <code>(music iPod iTunes)</code> and multiple nodes under the root node.</p>
152
+
153
+
<h3>Casual Grammar</h3>
154
+
155
+
<divclass="warning"><strong>Warning:</strong> Technical details ahead. <ahref="#implementations">Skip to details on implementations</a>.</div>
156
+
157
+
158
+
<p>A <em>node</em> is the basic unit of self-ml. A node can either be a <em>list</em> or a <em>string</em>.</p>
159
+
160
+
<pre><code>node := list | string.</code></pre>
161
+
162
+
163
+
<p>A <em>list</em> comprises of a <em>head</em> and a list of other nodes, enclosed in round brackets. For example, <code>(head node1 node2 node3)</code>. Unlike usual s-exprs, the empty list <code>()</code> is not accepted.</p>
164
+
165
+
<pre><code>list := '(' string node_list ')'.
166
+
167
+
node_list := node_list node.
168
+
node_list := node_list.
169
+
node_list := .</code></pre>
170
+
171
+
172
+
<p><em>Strings</em> can be written in three forms:</p>
<li><p>If it contains no whitespace or brackets, then it can be written verbatim. For example, <code>some-string</code>.</p><pre><code>VERBATIM_STRING := [^[\](){}\s]+</code></pre></li>
181
+
182
+
<li><p>If all square brackets in the string are balanced, then it can be written enclosed in square brackets. For example, <code>[NSMutableString *x = [[[NSMutableString alloc] init] autorelease];]</code>.</p><pre><code>BRACKETED_STRING := '[' ... deal with nested brackets ... ']'</code></pre></li>
183
+
184
+
<li><p>If you need to express unbalanced square brackets <code>[ ]</code> then you can use a *backtick string*. A backtick string starts at a <code>`</code> continues until another <code>`</code> is found, unless that backtick has another backtick after it (two backticks insert a single backtick into the backtick string). For example, <code>`This is a ``backtick`` string`</code>.</p><pre><code>BACKTICK_STRING := `(``|[^`])*?`</code></pre></li>
185
+
</ol>
186
+
187
+
188
+
<p>The <em>root node</em> is a list containing all top level nodes in the document. As mentioned, you can have any number of top level nodes, including zero.</p>
189
+
190
+
<pre><code>root := node_list.</code></pre>
191
+
192
+
193
+
<p>There are two types of comments. Comments may only occur outside of bracketed and backtick string literals.</p>
194
+
195
+
<ol>
196
+
<li><p>Line comments start at <code>#</code> and continue until a <code>CR</code>, <code>LF</code>, <code>CR LF</code> or other newline character sequence is found.</p><pre><code>LINE_COMMENT := #.*$</code></pre></li>
197
+
198
+
<li><p>Block comments start at <code>{#</code> and end when a matching <code>#}</code> is found. Block comments may be nested.</p><pre><code>BLOCK_COMMENT := \{#.*?#\}</code></pre></li>
199
+
</ol>
200
+
201
+
202
+
<p><aname="implementations"></a></p>
203
+
204
+
<h3>Implementations</h3>
205
+
206
+
207
+
<p>I have written an implementation in C. It’s <ahref="http://github.com/fileability/self-ml">available on github</a>.</p>
208
+
209
+
<p>Other implementations are of course welcome! As are text editor plugins, testcases, documentation, patches, etc. Contact me <ahref="http://github.com/inbox/new">on github</a> or email <ahref="mailto:anything@fileability.net">anything@fileability.net</a>.</p>
210
+
211
+
<p><em>Edit:</em> There’s now a very simple <ahref="http://dequechair.com/self-ml-textmate.zip">textmate bundle</a></p>
0 commit comments