構文は Python の構文のサブセットであるため、Python の組み込みを使用できますast.parse
。
>>> import ast, textwrap
>>> src = "(DP>10) & (LowMQ[0] < 0.05) & (SPV < 0.05)"
>>> print '\n'.join(textwrap.wrap(ast.dump(ast.parse(src)), width=80))
Module(body=[Expr(value=BinOp(left=BinOp(left=Compare(left=Name(id='DP',
ctx=Load()), ops=[Gt()], comparators=[Num(n=10)]), op=BitAnd(),
right=Compare(left=Subscript(value=Name(id='LowMQ', ctx=Load()),
slice=Index(value=Num(n=0)), ctx=Load()), ops=[Lt()],
comparators=[Num(n=0.050000000000000003)])), op=BitAnd(),
right=Compare(left=Name(id='SPV', ctx=Load()), ops=[Lt()],
comparators=[Num(n=0.050000000000000003)])))])
一般的なケースは解決しませんが、非常に単純です。