Rebol PARSE rule to match to first occurrence of at least 2 #[none]s

我是研究僧i 提交于 2019-12-13 03:49:28

问题


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?


回答1:


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]


来源:https://stackoverflow.com/questions/54577826/rebol-parse-rule-to-match-to-first-occurrence-of-at-least-2-nones

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!