I'm playing with writing a MUD/text adventure (please don't laugh) in Ruby. Can anyone give me any pointers towards an elegant, oop-based solution to parsing input text?
We're talking about nothing more complex than "put wand on table", here. But everything needs to be soft; I want to extend the command set painlessly, later.
My current thoughts, slightly simplified:
Each item class (box, table, room, player) knows how to recognise a command that 'belongs' to it.
The game class understands a sort of a domain-specific language involving actions such as "move object X inside object Y", "show description of object X", etc.
The game class asks each item in the room if it recognises the input command. First to say yes wins.
It then passes control to a method in the item class that handles the command. This method rephrases the command in the DSL, passes it back to the game object to make it happen.
There must be well-worn, elegant ways of doing this stuff. Can't seem to google anything, though.