コード例 #1
0
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("{"))

char = Word(alphanums + ' ', exact=1).leaveWhitespace()

space = FollowedBy(bslash) + (
    Literal(r'\ ') | Literal(r'\/')
    | Group(Literal(r'\hspace{') + number + Literal('}'))).setParseAction(
        handler.space).setName('space')

symbol = Regex("(" + ")|(".join([
    r"\\[a-zA-Z0-9]+(?!{)",
    r"[a-zA-Z0-9 ]",
    r"[+\-*/]",
    r"[<>=]",
    r"[:,.;!]",
    r"[!@%&]",
コード例 #2
0
ファイル: mathtext.py プロジェクト: jtomase/matplotlib
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))

char = Word(alphanums + ' ', exact=1).leaveWhitespace()

space = (Literal(r'\ ') | Literal(r'\/')
         | Group(Literal(r'\hspace{') + number + Literal('}'))).setParseAction(
             handler.space).setName('space')

#~ symbol = (texsym ^ char ^ binop ^ relation ^ punctuation ^ misc ^ grouping  ).setParseAction(handler.symbol).leaveWhitespace()
symbol = (texsym | char | binop | relation | punctuation | misc
          | grouping).setParseAction(handler.symbol).leaveWhitespace()

subscript = Forward().setParseAction(handler.subscript).setName("subscript")
superscript = Forward().setParseAction(
    handler.superscript).setName("superscript")
subsuperscript = Forward().setParseAction(