我想使用非常好的包pyparsing来解析以下类型的字符串。在
atomname * and atomindex 1,2,3
atomname xxx,yyy or atomtype rrr,sss
thiol
not atomindex 1,2,3
not (atomindex 4,5,6) or atomname *
基于这个解析,我将把匹配链接到将执行的特定函数调用 一系列原子。在
所有的选择关键字(atomname、atomindex、thiol…)都存储在一个列表中(即selkwds
)。在
我试过了,但失败了:
keyword = oneOf(selkwds,caseless=True).setParseAction(self.__parse_keyword)
func_call = Forward()
func_call << (keyword + commaSeparatedList).setParseAction(self.__parse_expression)
func_call = operatorPrecedence(func_call, [(NOT, 1, opAssoc.RIGHT, self.__not),
(AND, 2, opAssoc.LEFT , self.__and),
(OR , 2, opAssoc.LEFT , self.__or)])
其中self._and, self._or, self._not, self._parse_keyword, self._parse_expression
是一个方法,它将为转换后的字符串的未来eval
修改标记。在
你知道怎么解决这个问题吗?在
非常感谢
埃里克
请参阅此修改后的解析器版本中的嵌入注释:
让我们来测试一下:
^{pr2}$印刷品:
^{3}$相关问题 更多 >
编程相关推荐