Making a shiny new axe

First, some true back-story:

You probably already know that XML was designed as a storage format by the computer hardware cartels in order to maintain a high demand for enterprise grade storage and XML accelerators. You may also know the only reason JSON exists as a data interchange format is because it requires very little grey-matter straining to manipulate using JavaScript. I may well be corrected, but YAML appears to exist only to have hilarious unbounded fun trying to explain to non-techies what “Significant white-space” is. These formats excel in their own little niches, they also happen to suck pretty tremendously when used outside of said niche.

Why make your own format?

With requirements for serialization of various game resources in my game engine I needed functionality that isn’t possible in any of the above and that a tailored format was needed. Also, I thought it sounded a pretty cool project.

List of demands

  • Lists, dictionaries, strings, floats, bools – all the stuff you’d expect.
  • CDATA-style blocks. Chunks of strings with no concerns over escaping or other such shenanigans.
  • In-line comments and block comments. Configuration files in particular can be very complex, and containing documentation alongside the variables is double plus good.
  • It has to be as easy to edit as possible. I dislike syntax saccharin and wanted something as clean as possible.
  • It’s mine. NIH is awesome right?

Is it ready to use?

Yes, if you’re a masochist and/or just can’t help yourself. The parser works fine, but you’ll be casting from object all over the place. Object serialization and de-serialization is on the list, as in better handling of malformed input – Check GitHub for an up-to-date roadmap.

Where can I get it from?

The easiest way is via nuget:

PM> Install-Package Hatchet

Or, head over to GitHub and clone the repository.

Just show me the codes

Here is an example file format:

{ // open object definition

  name "Hatchet" // double-quoted string
  author 'Dale Reidy' // single quoted string
  isAwesome true // boolean
  cost 0 // integer
  durability 9001 // todo: nerf durability?

  description ![
     This is a block of text.
     It can span multiple lines.
     And contain "huge" amount of text.
     !] // a block of text

  versions [0.1 0.2 0.3 0.4] // list of floats

  tagcloud ['json' xml "data-storage"] // list of strings. 'xml' is implicitly parsed as a string

  dependencies [ // a list of objects
    { name "nunit" version "2" } // notice lack of comma
    { name "fluentassertions" version "" } // todo: find actual version number

} // close object definition

You can parse it like so:

// Valid for release

public void ExampleParsing()
    var input = File.ReadAllText(@"c:\that-block-above-this.txt");
    var result = (Dictionary<string, object>)parser.Parse(ref input);

    var parser = new Hatchet.Parser();
    var author = (string)result["author"];

    Console.WriteLine("Hatchet was made by {0}", author);