<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Parsing on Miloš Kozák</title><link>https://pubs.miloskozak.cz/tags/parsing/</link><description>Recent content in Parsing on Miloš Kozák</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 11 Oct 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://pubs.miloskozak.cz/tags/parsing/index.xml" rel="self" type="application/rss+xml"/><item><title>What I learned writing a HOCON parser as my first Zig project</title><link>https://pubs.miloskozak.cz/posts/hocon-tokenizer-and-parser/</link><pubDate>Sun, 11 Oct 2026 00:00:00 +0000</pubDate><guid>https://pubs.miloskozak.cz/posts/hocon-tokenizer-and-parser/</guid><description>&lt;img src="https://pubs.miloskozak.cz/img/hocon-tokenizer-and-parser/zig-Hocon-badge-master-1650x500.png" alt="zig-Hocon" style="width:100%; max-width:660px; display:block; margin:0 auto 1.5rem"&gt;
&lt;p&gt;I have decided to build a tool that will resolve my configuration dilemma for all languages at once. The tool has a CLI and a native API.
Point it at a config file and it prints what your service will really read: includes spliced in, substitutions resolved against the environment it will run in, duplicate keys merged, the whole thing as JSON.&lt;/p&gt;</description></item><item><title>I built a HOCON conformance suite. It found bugs in the reference implementation.</title><link>https://pubs.miloskozak.cz/posts/hocon-conformance-suite/</link><pubDate>Sat, 10 Oct 2026 00:00:00 +0000</pubDate><guid>https://pubs.miloskozak.cz/posts/hocon-conformance-suite/</guid><description>&lt;p&gt;I have used &lt;a href="https://github.com/lightbend/config/blob/main/HOCON.md"&gt;HOCON&lt;/a&gt; in production for years. I like the format because it is readable and it allows config file composition, so it allows simple multi-environment config shared config files overrides minimizing config differences. As a Python developer, my ultimate combo for config management is &lt;a href="https://pydantic.dev"&gt;Pydantic&lt;/a&gt; + &lt;a href="https://github.com/chimpler/pyhocon"&gt;pyhocon&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I like to try new things, so this June my eyes landed on &lt;a href="https://ziglang.org/"&gt;Zig&lt;/a&gt;. I wanted to go back to the roots of programming and see what a modern &amp;ldquo;C&amp;rdquo; feels like. After reading the language reference I needed a project, and knowing the Java and Python implementations of HOCON don&amp;rsquo;t fully agree, it gave me an idea: &amp;ldquo;Zig has a native C interface, so why not write HOCON in Zig and expose it through C shim? Then every language can share one implementation. Magic!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;What a simple project I have picked, right?&lt;/p&gt;
&lt;p&gt;Writing the tokenizer, the abstract syntax tree, the config and the resolution is the beautiful part. But right after the first implementation works, the question comes: am I really compatible? Luckily there is a &lt;a href="https://github.com/lightbend/config/blob/main/HOCON.md"&gt;written spec&lt;/a&gt; and a whole internet of examples. Well, it turned out the spec and the reference implementation do not always agree. Here is a basic config that contains an error:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-hocon" data-lang="hocon"&gt;hosts = [db1, db2] db3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;a href="https://github.com/lightbend/config/blob/main/HOCON.md#string-value-concatenation"&gt;spec says&lt;/a&gt; an array next to a string in a concatenation is invalid. &lt;a href="https://github.com/lightbend/config"&gt;lightbend/config&lt;/a&gt; 1.4.9, the reference implementation, the one the spec was written for, gives you this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nt"&gt;&amp;#34;hosts&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;db1&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;db2&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;No error, no warning. &lt;code&gt;db3&lt;/code&gt; is gone. Write it the other way round, &lt;code&gt;db3 [db1, db2]&lt;/code&gt;, and you get the error you were promised.&lt;/p&gt;
&lt;p&gt;So before going further with the parser, I wrote down what HOCON is supposed to do. That became a &lt;a href="https://github.com/lejmr/zig-hocon/tree/main/conformance"&gt;conformance suite&lt;/a&gt;: 445 cases, each one a sentence of the spec turned into a config file and the value it must produce. lightbend/config 1.4.9 passes 90% of them, pyhocon 70%. My Zig parser, zig-hocon, 69%, and from here on it is built against the suite.&lt;/p&gt;</description></item></channel></rss>