拒绝PARSE规则以匹配至少2#[无]的首次出现 [英] Rebol PARSE rule to match to first occurrence of at least 2 #[none]s
我只能展示Red和Rebol2的解决方案.由于规则中的单词会自动减少,因此您必须屏蔽它们.
红色
>> parse [x x x x _ a _ _ b] [to [ '_ '_] y: ]
== false
>>
>> y
== [_ _ b]
Rebol2
>> parse [x x x x _ a _ _ b] [some [r: [ '_ '_ ] (y: r) | skip] ]
== true
>> y
== [_ _ b]
由 HostileFork 编辑问题后,Red的解决方案就这样
>> parse [x x x x #[none] a #[none] #[none] b] [to [none! none!] y:]
== false
>> y
== [none none b]
>>
根据 giuliolunati
注释中的问题的例子
>> parse [x x x x 0 a 1 2 b] [to [integer! integer!] y:]
== false
>> y
== [1 2 b]
See similar question for string case.
In R3-Alpha, I tried to adapt the @sqlab response to block case:
parse [x x x x #[none] a #[none] #[none] b] [to [none! none!] ??]
I expect ??: [#[none] #[none] b]
, but get
** Script error: PARSE - invalid rule or usage of rule: none!
It's the result right and my expectation wrong? Or it's a bug?
解决方案
I can just show a solution for Red and Rebol2. As the words in the rule are reduced automatic, you have to shield them.
Red
>> parse [x x x x _ a _ _ b] [to [ '_ '_] y: ]
== false
>>
>> y
== [_ _ b]
Rebol2
>> parse [x x x x _ a _ _ b] [some [r: [ '_ '_ ] (y: r) | skip] ]
== true
>> y
== [_ _ b]
After the editing of the question by HostileFork the solution for Red looks like that
>> parse [x x x x #[none] a #[none] #[none] b] [to [none! none!] y:]
== false
>> y
== [none none b]
>>
example according the question in the comment of giuliolunati
>> parse [x x x x 0 a 1 2 b] [to [integer! integer!] y:]
== false
>> y
== [1 2 b]
这篇关于拒绝PARSE规则以匹配至少2#[无]的首次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文