Beispiel #1
0
    c[name + '_uc'] = objectgenerator.FirstOfGroup(children=u)
    c[name] = objectgenerator.FirstOfGroup(children=r)


_build('locale_day_names', dn)
_build('locale_day_abbrs', da)

_build('locale_month_names', mn)
_build('locale_month_abbrs', ma)

da = [s.lower() for s in da]
dn = [s.lower() for s in dn]
ma = [s.lower() for s in ma]
mn = [s.lower() for s in mn]

common.share(c)


class NameInterpreter:
    offset = 1

    def __init__(self, offset=1):
        self.offset = offset

    def __call__(self, info, buffer):
        (tag, left, right, children) = info
        value = buffer[left:right].lower()
        for table in self.tables:
            try:
                return table.index(value) + self.offset
            except ValueError:
Beispiel #2
0
    def dieSize(self, (t,s1,s2,sub), buffer):
        self.expr.dieSize = int(buffer[s1+1:s2])

    def repeat(self, (t,s1,s2,sub), buffer):
        self.expr.repeat = int(buffer[s1:s2])

    def rollRepeat(self, (t,s1,s2,sub), buffer):
        return disp.dispatchList(self, sub, buffer)


diceParser = parser.Parser(grammar, root="diceExpressionRoot")


def parseDice(s):
    succ, children, end = diceParser.parse(s, processor=Processor())
    if not succ or not end == len(s):
        raise RuntimeError('%s is not a valid dice expression' % (s,))
    return children[0]


# make productions exportable
c = {}
for name in ['diceExpression', 'dieModifier']:
	c[ name ] = objectgenerator.LibraryElement(
		generator = diceParser._generator,
		production = name,
	)

common.share( c )