LibrePCB Blog

LibrePCB Has Switched to S-Expressions

October 30, 2017

One major goal of LibrePCB is to use human readable files to represent libraries, projects and so on. This is important to let the user understand what the EDA tool actually does when modifying a schematic or board. In addition, a good file format is essential for version control systems to keep track of changes in libraries and projects.

But LibrePCB doesn’t just want to have some human readable file format. It wants to use the best possible file format for our specific needs!

XML and Similar Formats

Until now, LibrePCB used XML as file format. But unfortunately we were not very happy with it, because of several reasons:

  • The XML specifications are rather complex (we used only a small subset of the available features). In this blog post you can see that this complexity can even be dangerous!
  • The syntax is quite verbose (it even contains redundant information, e.g. <size>2.54</size>).
  • Available XML generators typically provide only little control over the formatting of the generated XML files. This leads to either very long files (many linebreaks) or very long lines (only few linebreaks). Both is bad for readability.

Other file formats (or their generators) have similar issues, so it seems that the only reasonable solution is to use a custom file format, or at least a custom generator.

S-Expressions with Custom Generator

To avoid completely reinventing the wheel, we decided to use the S-Expressions file format. KiCad uses this file format since version 4.0, and it seems that it’s really well suited for the use case of an EDA tool.

S-Expressions are very simple to understand, but still powerful enough for LibrePCB. And the syntax is not verbose, but still expressive.

With a custom S-Expressions generator, we are now able to control every little bit of the format of our generated files. Here you can see the difference between the old XML file format and the new S-Expressions file format:

XML vs. S-Expressions

Note: Even if the S-Expressions file has 6 lines more than the XML file, it’s ~16% smaller in size!

RSS Feed