Hi Antonio,

Here's an adaptation of something I dug up out of some old list messages,
by Stephen Butler:

>> non-brack: complement charset "<>"
== make bitset! #{
FFFFFFFFFFFFFFAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
}
>> bal-brack: ["<" any [non-brack | bal-brack] ">"]
== ["<" any [non-brack | bal-brack] thru ">"]
>> parse text1 [to "<" bal-brack copy b to end (print b)]
 to be copied to rest > this also
== true

Using recursion like this you don't have to try to count the brackets
yourself. What this does is look for the first "<", and stops at the
beginning (using TO not THRU). Then PARSE tries to match a balanced
"<" and ">". In between the "<" and ">" can come any number of characters
which are not "<" or ">", and any number of balanced "<" and ">". When
it comes to the end of the balanced brackets, it just copies to the end of
the string.

Hope it helps,
Eric

Reply via email to