CurlyML is a simple, concise format for storing and transmitting structured data and documents.
CurlyML allows you describe structured data in a way that is efficiently, easily readable and writeable to both human beings and machines, with no extraneous fuss or redundant markup.
Essentially, CurlyML is designed to get out of your way so you can get on with describing your data. This is in direct contrast with XML, which is overkill for the vast majority of tasks.
# this line is a comment # so is this one car { make { Toyota } model { Corolla } # this over here is a comment too doors { 4 } information { url { http://www.toyota.com/products/corolla#info } # the '#' in the url above isn't the start of a comment # because it is inside a "word". } stereo { custom { true } brand { Aiwa } model { GX7-40 } comment { "I liked it" } } }
As you can see, most of what is visible pertains to the data or its structure. You would have a hard time denying that this is simple, clear, concise and very readable. You've probably deduced most of CurlyML's rules just from looking at this, but just in case: This is a heirarchy of data, best thought of as a tree. Curly braces, as used in numerous popular programming languages, define the scope of nodes in the tree. Whitespace characters (spaces, tabs, newline etc) are for the most part ignored: you can write it any way you want.
The root node in this case is "car". The root node contains other nodes, and which may contain other nodes and so on. Every node will generally have some text in it, this could be thought of as its name for nodes that have children, or as just plain text data for nodes that don't. We make a point of not caring about the difference in the interests of simplicity.
If you are familiar with XML you will no doubt noticed that CurlyML nodes don't have attributes. We think that the attribute vs. child-node argument amounts to semantic nitpickery when it comes to the real world, and XML attributes decrease readability. Forget about 'em. Anything you can put in an attribute you can put in a child node, in CurlyML, with no cost.
#example of flexible text nodes journal-entry { date { 2004-12-15 } Today I went to the library, but I couldn't find any books on chickens. Oh well. mood { hungry } references { } # an empty parent node }
How would the parser parse this? The intutive way. It would construct a root node named "/" by default, add a child node "journal-entry" node to that. Inside that, things get interesting. The first thing we add to the journal-entry node is a child node called "date", with a leaf node inside it for the date 2004-12-15.
Next, we start scooping up text for our next node. We gobble up all the words until we pass "mood" and hit an opening curly. The parser knows that it has not only completed collecting all that text this node, but because it's hit an opening curly, it's also collected the name of a subsequent node which it knows to be a parent.
It then parses the mood subtree in much the same way as the date one.
Then it runs into another node, references. It knows this is a parent node, because it's followed by an opening curly. But this parent node has no children. This is how we distinguish empty parent nodes from leaf nodes. A parent node has a list of children which may be empty. A leaf node doesn't have a list for children.
If we were to draw boxes to show the resulting node heirarchy, it might look like this:
Our reference implementation illustrates everything that we care about when it comes to a node: what its name/text is, and who its children are. We don't care about anything else. Really.
A CurlyML parser could be written to load a document into memory. In this case the parser should return a a single root Node with name that user can never use: "/". All the top-level nodes in the document should be children of that node. A document could contain a bunch of top level nodes. We see no reason to restrict a document to only having a single top level node (i.e. root). The document itself is really the root, so let's not make the user mess around defining the root.