gpt4 book ai didi

parsing - 使用 PetitParser 在 Smalltalk 字符串中查找标记

转载 作者:行者123 更新时间:2023-12-04 11:58:43 25 4
gpt4 key购买 nike

我想解析

'This,is,an,example,text'

就像在 findTokens 中一样
'This,is,an,example,text' findTokens: $, 
an OrderedCollection('This' 'is' 'an' 'example' 'text')

但无法弄清楚如何使用 PetitParser、delimitedBy: 和eparatedBy: 没有帮助我我试过了
( #any asParser delimitedBy: $, asParser ) plus flatten parse:  'This,is,an,example,text'

但显然没有用

最佳答案

您可以使用 delimitedBy:结合 withoutSeparators :

|text parser|

text := 'This,is,an,example,text'.
parser := (#word asParser plus flatten delimitedBy: ($, asParser)) withoutSeparators.

parser parse: text

似乎是对 PetitParser 的最新改进。

关于parsing - 使用 PetitParser 在 Smalltalk 字符串中查找标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7803675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com