Hyperlambda, a better relational file format

XML, although its tooling space is really good, is simply too verbose. I’d argue that XML is so verbose it’s close to being unreadable by the human brain. JSON is better, but suffers from being too tied down to JavaScript, preventing you to (among other things) repeating the same key twice in the same scope. In addition, its syntax doesn’t make it easy to read, without providing tons of formatting to it. In its condensed syntax, JSON is also unreadable by the human brain.

YAML is really good. However, even YAML’s condensed syntax, is too much syntax. Besides, we need a simpler way to declare types. So I invented Hyperlambda. Yup, Hyperlambda is actually just a file format. And although its intrinsically tied to Phosphorus Five, there’s nothing preventing you from simply using it as a file format. Implementing your own parser to parse it is also dead simple – Assuming you don’t want to use my existing (Open Sauce) parser, which you can easily do, without using the rest of Phosphorus Five in fact. In fact, my existing parser is so simple, I didn’t even care to implement a tokeniser, since the format has only two distinct tokens. I think it’s roughly 1-200 lines of code. Below is an example.

foo:bar
  child1:hello
  child2:world
foo2:bar2

The above illustrates 2 nodes, where the first node has two children. The name is to the left of the colon (:), and its value is to the right. So it’s a “name/value/children” file format. This structure happens to easily be able to describe anything that JSON, XML and JSON is capable of describing, only in a much more human readable format. In fact, it’s also a superior way to describe CSV content, since it also supports C# string literals. Below is an example.

foo:"This is a\r\nnew line"

In the above example, we have injected a CR/LF sequence,  allowing us to provide special characters, and even UNICODE literals, the same way we would in a C# string. It also supports multiline C# strings, such as the following illustrates.

foo:@"This is a
new line"

The above of course results in the exact same result as the previous example. And to make x-platform simpler, it *always* serialises a carriage return as a CR+LF sequence. Below is an example of creating a “CSV file”, using Hyperlambda syntax instead.

record
  name:Thomas Hansen
  phone:90909090
record
  name:John Doe
  phone:91919191

Slightly more verbose, but much more readable. And in fact, it also supports types. Below is an example that illustrates usage of types.

record
  name:Thomas Hansen
  age:int:44
record
  name:John Doe
  age:int:45

Notice the additional entity in between the “age” and its value, declaring the RHS value of “age” to be of type “int” ==> integer. If you’re looking for a simple to implement, and easy to read file format, for storing for instance your configuration settings, or other types of data – You might want to have a look at Hyperlambda. And in fact, you can use my existing parser, at which point you can simply invoke an Active Event, and have my parser do the heavy lifting, having returned a “Node” structure back to caller, that you can easily semantically traverse, almost the same way you’d traverse your XML DOM structure. Below is an example of invoking the Active Event that parses a Hyperlambda string for you.

var node = new Node ("", "your-hyperlambda-goes-here");
var nodeResult = someApplicationContextObject.RaiseEvent("hyper2lambda", node);

The above would make your “nodeResult” contain the nodes from your Hyperlambda, having tons of supporting methods and properties, such as “LastChild”, subscript operator to retrieve children nodes, etc, etc, etc. And in fact, it even allows you to comment your nodes, using C#/Java comments if you wish. Below is an example …

/*
 * This is a record.
 */
record
  // This is the name of the record.
  name:Thomas Hansen
  age:int:44
record
  name:John Doe
  age:int:45
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.