如何在同一规则中将字符串解析和块解析混合在一起? [英] How to mix together string parsing and block parsing in the same rule?

查看:102
本文介绍了如何在同一规则中将字符串解析和块解析混合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很酷,Rebol的PARSE方言被广泛推广,可以在符号结构以及字符串上进行模式匹配和提取.像这样:

It's cool that Rebol's PARSE dialect is generalized enough that it can do pattern matching and extraction on symbolic structures as well as on strings. Like this:

; 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相匹配的任意数量的字符串:

But let's say I'm looking for a block containing an apple symbol, and then any number of character strings matching the 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:

How would I formulate such a mixed-rule? Looking at the documentation it suggests that one can use INTO:

http://www.rebol.net/wiki/Parse_Project#INTO

看似自然的答案似乎不起作用:

The seemingly natural answer doesn't seem to work:

>> mixed-rule: ['apple some [string! into ["a" some "b"]]]

通过测试1并正确返回测试3的false时,在测试2中返回错误的true.这是我的错误还是Rebol中的错误(我正在使用r3 A111)?

While it passes test 1 and correctly returns false for test 3, it incorrectly returns true in test 2. Is this my mistake or a bug in Rebol (I'm using r3 A111)?

推荐答案

跳过

这篇关于如何在同一规则中将字符串解析和块解析混合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆