Heisenbug

April 15, 2009

How the object based parser works.

Filed under: Backpack — by jenf @ 10:09 pm

The object based parser is now pretty robust in terms of functionality, it needs more work in terms of error handling.
The following is an example of how to declare the verb ‘help’ and connect it to the help function in ruby, simple enough.

module Backpack
  class SystemObject
    include Parser
    verb "help", :help
    def help
     puts "You need it"
    end
  end
end

And for strings with an object attached:

  class Item < BackpackObject
    verb "examine", primarynoun, :examine
    def examine
      puts self.inspect
    end

    verb "put", noun, ["into","in","inside","through"], primarynoun,:insert
    def insert(x)
      puts "insert %s" % x
    end
 end

It currently doesn’t support multiobjects, but that’s not to difficult to add. Unfortunately it has caused a slight rethink in how exits in Backpack are handled, and is causing a slight rewrite (as well as a tidy up).

The system also exposed an area of ruby which I wasn’t sure of before, inheritance and metafunctionality that is created when the class is loaded, the verb function adds a class variable and this is not visible to the child, this then has to be put back together when the verb is being parsed.

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress.com