如何替换 pyPEG 中的某些单词?例如我有句子
约翰踢足球
我想将John替换为Bob并将其组合为:
鲍勃踢足球。
from pypeg2 import *
class Try(str):
grammar = 'John ', restline
# I am think that here should be same callback function, but i have no idea how to type it
f = parse("John plays football", Try)
print(compose(f))
输出:
John plays football