2
import os, sys, string, random
6
from twisted.internet import defer
7
from twisted.python import reflect, rebuild, util
10
from pottery import text as T, epottery, iterutils
11
from pottery.predicates import atLeastOne, isNot, And
13
OPPOSITE_DIRECTIONS = {
19
def stripper(s, loc, toks):
21
toks[0] = toks[0][1:-1]
24
def targetString(name):
25
qstr = pyparsing.quotedString.setParseAction(stripper)
27
pyparsing.Word(pyparsing.alphanums) ^
28
qstr).setResultsName(name)
30
class CommandType(type):
32
def __new__(cls, name, bases, attrs):
33
infrastructure = attrs.pop('infrastructure', False)
34
t = super(CommandType, cls).__new__(cls, name, bases, attrs)
35
if not infrastructure:
36
cls.commands[reflect.qual(t)] = t
39
def parse(self, player, line):
40
for cls in self.commands.values():
42
match = cls.match(player, line)
43
except pyparsing.ParseException:
48
for k,v in match.items():
49
if isinstance(v, pyparsing.ParseResults):
51
return cls().run(player, line, **match)
52
return defer.fail(epottery.NoSuchCommand(line))
54
class Command(object):
55
__metaclass__ = CommandType
58
def match(cls, player, line):
59
return cls.expr.parseString(line)
60
match = classmethod(match)