Rebol PARSE 规则以匹配至少 2 #[none] 的第一次出现
Rebol PARSE rule to match to first occurrence of at least 2 #[none]s
字符串大小写见 。
在 R3-Alpha 中,我尝试调整 @sqlab 对块大小写的响应:
parse [x x x x #[none] a #[none] #[none] b] [to [none! none!] ??]
我期望 ??: [#[none] #[none] b]
,但得到
** Script error: PARSE - invalid rule or usage of rule: none!
是结果对了我的预期错了吗?或者这是一个错误?
我可以展示一个针对 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]
字符串大小写见
在 R3-Alpha 中,我尝试调整 @sqlab 对块大小写的响应:
parse [x x x x #[none] a #[none] #[none] b] [to [none! none!] ??]
我期望 ??: [#[none] #[none] b]
,但得到
** Script error: PARSE - invalid rule or usage of rule: none!
是结果对了我的预期错了吗?或者这是一个错误?
我可以展示一个针对 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]