我正在尝试解析一个句子,同时将数字转换为它们的数字表示。
作为一个简单的例子,我想要句子
三个苹果
解析并转换为
3个苹果
使用此代码简单代码,我实际上可以正确解析句子并将三转换为3,但是当我尝试将结果展平时,3恢复为三。
Parser three() => string('three').trim().map((value) => '3');
Parser apples() => string('apples').trim();
Parser sentence = three() & apples();
// this produces Success[1:13]: [3, apples]
print(sentence.parse('three apples'));
// this produces Success[1:13]: three apples
print(sentence.flatten().parse('three apples'));
我错过了什么吗?展平行为是否正确?
在此先感谢 L