Up to Main Index Up to Journal for January, 2013 JOURNAL FOR WEDNESDAY 9TH JANUARY, 2013 ______________________________________________________________________________ SUBJECT: Parsing data files DATE: Wed Jan 9 23:21:06 GMT 2013 First entry of 2013 and it's late - I should have written it yesterday :( So what happened yesterday? I've been hacking away on WolfMUD's record jar file format[1]. This is the first step to storing configuration data, player data and 'world' data in easily manageable text files. After two late nights coding I can actually read and parse my format which looks like: # # The Dragon's Breath tavern. L1 to L4 # Ref: L1 Type: Start Name: Fireplace Aliases: TAVERN,FIREPLACE Exits: E→L3 SE→L4 S→L2 You are in the corner of a common room in the Dragon's Breath tavern. There is a fire burning away merrily in an ornate fireplace giving comfort to weary travellers. Shadows flicker around the room, changing light to darkness and back again. To the south the common room extends and east the common room leads to the tavern entrance. %% Ref: L2 Type: Start Name: Common Room Aliases: TAVERN, COMMON Exits: N→L1 NE→L3 E→L4 Inventory: I1, L5 You are in a small, cosy common room in the Dragon's Breath tavern. Looking around you see a few chairs and tables for patrons. To the east there is a bar and to the north you can see a merry fireplace burning away. %% Ref: L3 Type: Start Name: Tavern entrance Aliases: TAVERN, ENTRANCE Exits: E→L5 S→L4 SW→L2 W→L1 You are in the entryway to the Dragon's Breath tavern. To the west you can see an inviting fireplace, while south an even more inviting bar. Eastward a door leads out into the street. %% Ref: L4 Type: Start Name: Tavern Bar Aliases: TAVERN, BAR Exits: N→L3 NW→L1 W→L2 You standing at the bar. Behind which you can see various sized and shaped bottles. Looking at the contents you decide an abstract painter would get lots of colourful inspirations after a long night here. %% Ref: I1 Type: Item Name: A curious brass lattice Aliases: LATTICE Weight: 2 This is a finely crafted, intricate lattice of fine brass wires forming a roughly ball shaped curiosity. I can load and create the locations, link up the exits and create the lattice and put it into the right location, then TELNET in and wander around. The code is currently a right old mess but it is working. As soon as it's cleaned up and I've got configuration settings working I think I'll have to make a PROTOTYPE2 release. One interesting thing to note is that even using reflection you can't create a variable on the fly from a string representing the type's name. That is given the string "Basic" you can't instantiate a struct of type Basic. So I currently have a switch structure creating instances of things based on their 'Type' from the record jar entry - not an interface{} in sight. This does mean everything is type checked properly and sane ;) -- Diddymus [1] Actually it's based on a combination of RFC822 and the Cookie Jar format as described by Eric Raymond in "The Art of Unix Programming", chapter 5: http://www.catb.org/esr/writings/taoup/html/ch05s02.html Up to Main Index Up to Journal for January, 2013