An excellent reference on writing rules (and composing a rule file) can be found here. Since Marty spent so much time on this and is very proud of his effort, I will not duplicate the effort here (yet).