How to mix together string parsing and block parsing in the same rule?

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

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

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"]]]

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)?

Upvotes: 4

Views: 308

Answers (1)

Sunanda
Sunanda

Reputation: 1555

Steeve over on the REBOL3 forum suggests this:

only the second string is checked.
Should be:
    ['apple some [and string! into ["a" some "b" ]]]

Upvotes: 3

Related Questions