Monday, December 17, 2007

Parsing, redux

Currently, the state of complex commands like "get", "put", "drop", and "get" (not yet implemented) are terrifying.

That's not even to mention something like the old administrative command "bring".

The reason? Parsing.

Yes, more parsing.

The goal of PyMUD commands are to be as intuitive (in terms of English) as possible, while still maintaining ease of use.

For example, the commands "bring me to the town forum in canticett" is English. It is not easy to use.

"bring me to forum in canticett", the old implementation, is a little less English, a little easier to use, and infinitely more easy to parse.

The problem arises, however, when you try to create intuitive alternatives to a given grammar.

What if, instead of bringing me to a room in a zone, I want to be brought to a player? What then? Why shouldn't "bring me to charlie" work?

It should, or I'm not a PyMUD developer!

The issue here is that "bring me to <room> in <zone>" makes a few assumptions. First of all, that "bring" is followed by "me to", and at some point, the word "in", with two phrases flanking it. That latter part is completely ignored by "bring me to <player>".

Furthermore, what if I want to "bring charlie to forum in canticett".

And what if I want to bring a specific Item, by its unique ID tag, to the location of a specific Door, by its unique ID tag? "bring 35 to 982"?

The plot thickens!

As you can see, this only addresses one command, not even 1/2 of the list up top.

The solution?

Pyparsing!

Pyparsing lets me specify grammars, even incredibly loose grammars like the example above, and in a few lines extract the subject, target, whether it's a Room or a Mobile or what-have-you, all without so much as breaking a sweat. At first I wasn't sure if it was suited to our needs, but the swell guy behind the project was able to point me in the right direct.

This has been a public service announcement.

1 comment:

Anonymous said...

You know who I heard parses top down instead of bottom up? That snidely Viserys AKA Steven AKA Bojangles.