是否可以使用一些空格作为分隔符?我的意思是...
给定一些python运算符优先级解析器,我想将自然语言与运算符混合在一起,作为记笔记的简写,即'caffeine : A1 antagonist -> caffeine : peripheral stimulant'
有解释'caffeine is an A1 antagonist implies that it is a peripheral stimulant'
。
例如,我希望能够将其解析parse('a:b -> c : d e')
为[[['a', ':', 'b'], '->', ['c', ':', ['d', 'e']]]]
像这样的东西
operands = delimitedList(Word(alphanums), delim=',')
# delim=' ' obviously doesn't work
precedence = [
(":", 2, opAssoc.LEFT),
("->", 2, opAssoc.LEFT),
]
parser = operatorPrecedence(operands, precedence)
def parse(s): return parser.parseString(s, parseAll=True)
print parse('a:b -> c : d e')
可能的?