leah blogs

June 2004

24jun2004 · Real Life Markup Language (RLML)

Yesterday and today I implemented a parser for the Real Life Markup Language (RLML) invented by Paul Battley for Ruby.

RLML aims to “Make an alternative to XML that is simple to use for both man and machine.” You can read the provisional specification at http://po-ru.com/rlml/rlml.txt

So far, I have programmed a very low core, non validating API CoreParser, StreamParser, a more SAX-like streaming API, and TreeParser, a DOM-like interface. Each of these builds on the other ones.

For example, this XML document:

<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

would look like that in RLML:

rlml/iso-8859-1
note
{
    to{Tove} from{Jani} heading{Reminder}
    body{Don't forget me this weekend!}
}

These are the events in CoreParser:

[:encoding, "iso-8859-1"], [:start_tag, "note"],
[:start_tag, "to"], [:idata, "Tove"], [:end_tag],
[:start_tag, "from"], [:idata, "Jani"], [:end_tag],
[:start_tag, "heading"], [:idata, "Reminder"],
[:end_tag], [:start_tag, "body"], [:idata, "Don't"],
[:idata, " "], [:idata, "forget"], [:idata, " "],
[:idata, "me"], [:idata, " "], [:idata, "this"],
[:idata, " "], [:idata, "weekend!"], [:end_tag], [:end_tag]

And this is emitted in StreamParser:

[:encoding, "iso-8859-1"], [:start_tag, "note"],
[:start_tag, "to"], [:data, "Tove"], [:end_tag, "to"],
[:start_tag, "from"], [:data, "Jani"], [:end_tag, "from"],
[:start_tag, "heading"], [:data, "Reminder"],
[:end_tag, "heading"], [:start_tag, "body"],
[:data, "Don't forget me this weekend!"],
[:end_tag, "body"], [:end_tag, "note"]

Finally, TreeParser returns this:

#&lt;Tree: [#&lt;Tree:note [#&lt;Tree:to ["Tove"]&gt;,
                      #&lt;Tree:from ["Jani"]&gt;,
                      #&lt;Tree:heading ["Reminder"]&gt;,
         #&lt;Tree:body ["Don't forget me this weekend!"]&gt;]&gt;]&gt;

Building the API this way was a lot of fun, as each layer only does its job. And yes, you can pipeline the streaming APIs. :-)

RLML is definitely a niche markup language, but it’s very easy to implement (~280 LoC so far) and has a simple, nice, userfriendly syntax. (It’s also possible to be converted from/to XML, with the loss respective conversion of attribute data.)

Now, on with unit tests…

Gottseidank bin ich Atheist.

Tanz’ den Indepen-dance!

Aus Ferstls Heft: telegrap, pone, wich, tings.

NP: Pearl Jam—Bushleaguer

Copyright © 2004–2022