Um... extensible parsing?

Philip Swartzleonard starx at pacbell.net
Thu May 9 15:33:29 EDT 2002


I am interested in making a program in python that helps people edit the 
gameworld definition files used in the Angband and it's many and various 
varients. They are a fairly simple text file format, and each record 
follow a mostly set pattern. For exapmle, here's the format for one of 
the files from ToME:

# N: serial number : monster name
# G: symbol : color
# I: speed : hit points : vision : armor class : alertness
# W: depth : rarity : corpse weight : experience for kill
# E: weapons : torso : arms : finger : head : leg
# O: treasure : combat : magic : tool
# B: attack method : attack effect : damage
# F: flag | flag | etc
# S: spell frequency |
# S: spell type | spell type | etc
# D: Description

The only problem here is that some of the lines are optional and may be 
missing from a valid record. A sample of the actual file looks like 
this:

N:157:Black harpy
G:H:D
I:120:3d8:16:22:10
W:9:1:600:19
E:0:1:1:0:1:0
O:0:0:0:0
B:CLAW:HURT:1d2
B:CLAW:HURT:1d2
B:BITE:HURT:1d3
F:FEMALE | CAN_FLY | WILD_TOO | WILD_MOUNTAIN | DROP_CORPSE |
F:RAND_25 | ANIMAL | EVIL | MORTAL | BASEANGBAND
D:A woman's face on the body of a vicious black bird.

N:158:Skaven
G:r:G
I:110:11d8:15:25:20
W:9:1:600:20
E:1:1:1:2:1:1
O:35:35:20:0
B:HIT:HURT:1d4
B:HIT:HURT:1d4
F:EVIL | FRIENDS | DROP_60 | DROP_90 | DROP_SKELETON | DROP_CORPSE |
F:OPEN_DOOR | MALE | WILD_TOO | WILD_WASTE | WILD_SWAMP |
F:MORTAL | ZANGBAND
D:A mutated rat-creature from the great waste, it is vaguely
D:humanoid in appearance and walks on its hind legs. This race
D:serves chaos fervently and is greatly feared by others.

As you can see, there are a lot of things to remember and a lot of 
chances to screw up when editing these things, which is why I want to 
make something to make this easier. The problem is, there are many files 
that use the same basic structure, and the files structre and e.g. 
avilable flags differs between varients. For exapmle, here's a simpler 
kind of file that i want use to prototype this program with:

# N:<index>:<name>
# I:<max_cost>:<max_inflate>:<min_inflate>:<haggle_per>:<insult_max>
# C:<hated cost>:<normal cost>:<liked cost>
# L:liked races
# H:hated races

N:0:Bilbo the Friendly(Hobbit)
I:20000:170:108:5:15
C:120:100:80
L:Elf | Half-Elf | High-Elf | Dunadan | Hobbit | Dwarf | RohanKnight
H:Orc | Troll | DeathMold | Half-Ogre | Beorning | Kobold
    
Here, C, L, H lines are optional.

Anyway, I want to make a generic editor program that reads some datafile 
to determine the structure of the 'info' file it needs to edit, and 
constructs it's interface from there. I'd assume i'd have some kind of 
list interface to deal with the records (using the N line information 
that all of thie files that I want to edit use), and that I'd have 
customized controls for editing the different types of data (e.g. 
flag_checkboxes, string_field, dice_field, number_field). What i -don't- 
have a clue how to do is the part that puts the pieces together 
depending on the situation, and the parts that actually parse the 
various files. What i'm asking for is any pointers or insight that could 
help me solve this problem more efficently. Thank you.

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list