use*_*565 7 parsing smalltalk petitparser
我想解析
'This,is,an,example,text'
Run Code Online (Sandbox Code Playgroud)
就像在findTokens中一样
'This,is,an,example,text' findTokens: $,
an OrderedCollection('This' 'is' 'an' 'example' 'text')
Run Code Online (Sandbox Code Playgroud)
但无法弄清楚怎么用PetitParser,delimitedBy:和separatedBy:没有帮助我,我尝试过
( #any asParser delimitedBy: $, asParser ) plus flatten parse: 'This,is,an,example,text'
Run Code Online (Sandbox Code Playgroud)
但显然没有用
当我想排除某些内容时,我总是在 PetitParser 中使用这种模式。只需将“我正在寻找的内容”或“我想要排除的内容”(以更容易描述的为准)定义为解析器,然后对其进行否定,并根据需要进行处理。
s := 'This,is,an,example,text'.
separator := $, asParser ==> [ :n | nil ].
token := separator negate plus flatten.
p := (token separatedBy: separator) ==> [ :nodes |
nodes copyWithout: nil ].
p parse: s.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
956 次 |
| 最近记录: |