很酷的是Rebol的PARSE方言足够概括,它可以在符号结构和字符串上进行模式匹配和提取。像这样:
; match a single "a" character, followed by any number of "b" chars
>> string-rule: ["a" some "b"]
>> parse "abb" string-rule
== true
>> parse "aab" string-rule
== false
; look for a single apple symbol, followed by any number of bananas
>> block-rule: ['apple some 'banana]
>> parse [apple banana banana] block-rule
== true
>> parse [apple apple banana] block-rule
== false
但是,假设我正在寻找一个包含苹果符号的块,然后找到与string-rule
匹配的任意数量的字符串:
; test 1
>> parse [apple "ab" "abbbbb"] mixed-rule
== true
; test 2
>> parse [apple "aaaa" "abb"] mixed-rule
== false
; test 3
>> parse [banana "abb" "abbb"] mixed-rule
== false
我如何制定这样的mixed-rule
?查看文档,它表明可以使用INTO:
http://www.rebol.net/wiki/Parse_Project#INTO
看似自然的答案似乎不起作用:
>> mixed-rule: ['apple some [string! into ["a" some "b"]]]
当它通过测试1并且正确地为测试3返回false时,它在测试2中错误地返回true。这是我的错误还是Rebol中的错误(我正在使用r3 A111)?
答案 0 :(得分:3)
对REBOL3 forum提出异议建议:
only the second string is checked.
Should be:
['apple some [and string! into ["a" some "b" ]]]