def input_action(self, tokens): scan_info = fuzzy_scan(tokens, self.lexicon) dbg(4, scan_info, 'scan info', self.input_action) if 'err' in scan_info: self.commenter(1, "Don't know {0}.".format(scan_info['err'])) return parse_info = rp.parse_nvod(scan_info['match'], self.lexicon) dbg(4, parse_info, 'parse info', self.input_action) if 'err' in parse_info: self.commenter(1, "Don't know what to do: {0}".\ format(show_parse_errors(parse_info['err']))) return cmd = make_command(parse_info) verb, args = cmd[0], cmd[1:] try: action_method = getattr(self.level, verb) except AttributeError: self.commenter(1, "Don't know how to '{0}'!".format(verb)) return for name in parse_info['name']: action_method(self.name_actors[name], *args)
def test_valid_cmds(self): cmd = ["yip", "move", "up"] result = rp.parse_nvod(cmd, self.lexicon, with_name=1) self.check(result, ["name", "verb", "direct"], [["yip"]] + cmd[1:]) cmd = ["xenia", "drop", "health", "left"] result = rp.parse_nvod(cmd, self.lexicon, with_name=1) self.check(result, ["name", "obverb", "object", "direct"], [["xenia"]] + cmd[1:]) cmd = ["xenia", "yip", "down"] result = rp.parse_nvod(cmd, self.lexicon, with_name=1) self.check(result, ["name", "direct"], [["xenia", "yip"]] + cmd[2:]) cmd = ["up"] result = rp.parse_nvod(cmd, self.lexicon, with_name=0) self.check(result, ["name", "direct"], [[]] + cmd) cmd = ["drop", "armor", "right"] result = rp.parse_nvod(cmd, self.lexicon, with_name=0) self.check(result, ["name", "obverb", "object", "direct"], [[]] + cmd)
def test_invalid_cmds(self): self.check_err(rp.parse_nvod([], self.lexicon, with_name=1)) self.check_err(rp.parse_nvod([], self.lexicon, with_name=0)) cmd = ["up", "attack", "yip"] self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=1)) self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=0)) cmd = ["a", "b", "c", "d", "e"] self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=1)) self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=0)) cmd = ["yip"] self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=1)) self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=0)) cmd = ["move"] self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=1)) self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=0)) cmd = ["up"] self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=1)) cmd = ["a", "b", "c", "d", "e"] self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=1)) self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=0)) cmd = xrange(8) self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=1)) self.check_err(rp.parse_nvod(cmd, self.lexicon, with_name=0))