'Generate the general pyparsing rules for this calendar
@return: the rules dict
rules = {"d": Day of the month as a zero-padded decimal number
"b": Month as localeâs abbreviated name
"B": Month as localeâs full name
"m": Month as a zero-padded decimal number
"y": Year without century as a zero-padded decimal number
"Y": Year with century as a decimal number
"H": Hour (24-hour clock) as a zero-padded decimal number
"I": Hour (12-hour clock) as a zero-padded decimal number
"p": Localeâs equivalent of either AM or PM
"M": Minute as a zero-padded decimal number
"S": Second as a zero-padded decimal number
@todo: support day-of-week options (recognize but suppress when parsing)'

def _get_rules(self):

    import pyparsing as pp
    T = current.T
    calendar = self.calendar
    oneOf = pp.oneOf
    parse_int = self._parse_int
    def numeric(minimum, maximum):
        '    Helper    to    define    rules    for    zero-padded    numeric    values    '
        zp = '    '.join((('%02d' % i) for i in xrange(minimum, min(10, (maximum + 1)))))
        np = '    '.join((('%d' % i) for i in xrange(minimum, (maximum + 1))))
        return (oneOf(zp) ^ oneOf(np)).setParseAction(parse_int)
    month_days = calendar.MONTH_DAYS
    days = [(max(d) if isinstance(d, tuple) else d) for d in month_days]
    day = numeric(1, max(days)).setResultsName('day')
    CaselessLiteral = pp.CaselessLiteral
    replaceWith = pp.replaceWith
    num_months = len(calendar.MONTH_NAME)
    month = numeric(1, num_months).setResultsName('month')
    expr = None
    for (i, m) in enumerate(calendar.MONTH_NAME):
        month_number = str((i + 1))
        month_literal = CaselessLiteral(m)
        month_t = str(T(m))
        if (month_t != m):
            month_literal |= CaselessLiteral(month_t)
        month_literal.setParseAction(replaceWith(month_number))
        expr = ((expr | month_literal) if expr else month_literal)
    month_name = expr.setParseAction(parse_int).setResultsName('month')
    expr = None
    for (i, m) in enumerate(calendar.MONTH_ABBR):
        month_number = str((i + 1))
        month_literal = CaselessLiteral(m)
        month_t = str(T(m))
        if (month_t != m):
            month_literal |= CaselessLiteral(month_t)
        month_literal.setParseAction(replaceWith(month_number))
        expr = ((expr | month_literal) if expr else month_literal)
    month_abbr = expr.setParseAction(parse_int).setResultsName('month')
    Word = pp.Word
    nums = pp.nums
    year2 = Word(nums, min=1, max=2)
    year2 = year2.setParseAction(parse_int).setResultsName('year2')
    year4 = Word(nums, min=1, max=4)
    year4 = year4.setParseAction(parse_int).setResultsName('year4')
    hour24 = numeric(0, 23).setResultsName('hour24')
    hour12 = numeric(0, 12).setResultsName('hour12')
    minute = numeric(0, 59).setResultsName('minute')
    second = numeric(0, 59).setResultsName('second')
    am = ('AM', str(T('AM')), 'am', str(T('am')))
    am = oneOf('    '.join(am)).setParseAction(pp.replaceWith('AM'))
    pm = ('PM', str(T('PM')), 'pm', str(T('pm')))
    pm = oneOf('    '.join(pm)).setParseAction(pp.replaceWith('PM'))
    ampm = (am ^ pm).setResultsName('ampm')
    rules = {'d': day, 'b': month_abbr, 'B': month_name, 'm': month, 'y': year2, 'Y': year4, 'H': hour24, 'I': hour12, 'p': ampm, 'M': minute, 'S': second}
    return rules
