Tuesday, August 24, 2004

IML

I've always thought that xml is a sort of unatural way to describe hirarchical data, at least when it should be human readable. I've obviously also always thought that python's use of indent is a great case of connecting the good with the useful. Of I hacked, and out came "Indent Markup Languag". It may be a bit unripe ( only the second iteration so far ) but this will show once I put it to some real-world use. To illustrate the concept, some IML and how it converts to XML.

the iml:

html
head
title "mypage"
body
a color="black" href="http://www.google.com" "google"
table
tr
td "test"
td
"another"
tr
td bgcolor="red" "second"
td
"and a nice
multiline
test"

that evaluates to:

<html>
<head>
<title>
mypage
</title>
<body>
<a color="black" href="http://www.google.com">
google
</a>
<table>
<tr>
<td>
test
</td>
<td>
another
</td>
</tr>
<tr>
<td bgcolor="red">
second
</td>
<td>
and a nice
multiline
test
</td>
</tr>
</table>
</body>
</head>
</html>


I think that's pretty nice :)
If you want, play around with the parser

2 comments:

Anonymous said...

You might be interested in looking at YAML (http://www.yaml.org/). Check out the "Get Started" link on there for an example.

Ben Sizer (came here via Ian Bicking's weblog)

Florian said...

I checked out yaml before I did this, three particular things disturbing about yaml.

-Yaml is not a markup language. Long story simple truth, markups can be converted against each other, not markups are either not safe or not sanely translated into markup.
-Yaml introduces some line-noise I did not want
-I do not want to set on a fixed indent-width ( as you may have noticed, the first line of a block in iml sets the correct indent for the rest of the blocks, quite like python.

In short thus, yaml or xml are not pythonic, iml is.