def __init__(self): family = Regex(r'([^%s]|(\\[%s]))*' % (family_punc, family_punc)) \ .setParseAction(self._family) size = Regex(r"([0-9]+\.?[0-9]*|\.[0-9]+)") \ .setParseAction(self._size) name = Regex(r'[a-z]+') \ .setParseAction(self._name) value = Regex(r'([^%s]|(\\[%s]))*' % (value_punc, value_punc)) \ .setParseAction(self._value) families = (family + ZeroOrMore(Literal(',') + family)).setParseAction( self._families) point_sizes = (size + ZeroOrMore(Literal(',') + size)).setParseAction( self._point_sizes) property = ((name + Suppress(Literal('=')) + value + ZeroOrMore(Suppress(Literal(',')) + value)) | name).setParseAction(self._property) pattern = (Optional(families) + Optional(Literal('-') + point_sizes) + ZeroOrMore(Literal(':') + property) + StringEnd()) self._parser = pattern self.ParseException = ParseException
percent = Literal('%') ampersand = Literal('&') misc = exclamation | at | percent | ampersand over = Literal('over') under = Literal('under') #~ composite = over | under overUnder = over | under accent = Literal('hat') | Literal('check') | Literal('dot') | \ Literal('breve') | Literal('acute') | Literal('ddot') | \ Literal('grave') | Literal('tilde') | Literal('bar') | \ Literal('vec') | Literal('"') | Literal("`") | Literal("'") |\ Literal('~') | Literal('.') | Literal('^') number = Combine(Word(nums) + Optional(Literal('.')) + Optional(Word(nums))) plus = Literal('+') minus = Literal('-') times = Literal('*') div = Literal('/') binop = plus | minus | times | div roman = Literal('rm') cal = Literal('cal') italics = Literal('it') typewriter = Literal('tt') fontname = roman | cal | italics | typewriter texsym = Combine(bslash + Word(alphanums) + NotAny("{"))
semicolon = Literal(';') exclamation = Literal('!') punctuation = colon | comma | period | semicolon at = Literal('@') percent = Literal('%') ampersand = Literal('&') misc = exclamation | at | percent | ampersand over = Literal('over') under = Literal('under') #~ composite = over | under overUnder = over | under number = Combine(Word(nums) + Optional(Literal('.')) + Optional(Word(nums))) plus = Literal('+') minus = Literal('-') times = Literal('*') div = Literal('/') binop = plus | minus | times | div roman = Literal('rm') cal = Literal('cal') italics = Literal('it') typewriter = Literal('tt') fontname = roman | cal | italics | typewriter texsym = Combine(bslash + Word(alphanums) + NotAny(lbrace))