R3 Parse: Is there any lazy quantifiers in parse dialect?

Started by Rex on 3-Mar-2014/6:49:30-8:00
In parse dialect, it seems that all quantifiers (repetitions) are greedy, and I am wondering whether there are any lazy quantifiers?
Can you give an example of what you'd like to do?
Greedy quantifiers work like this: If you match "aaaaa" with [some "a"], the position after the match should come to the end of the sequence. In other words the quantifier 'some eats up all the sequence. But I want the quantifiers to stop as soon as it captures the minimal amount of data which make it true. In the example above, the lazy version of 'some should stop as soon as it reaches the first "a" , because that's already enough for the condition to be true (at least one "a"). I am wondering whether there are quantifiers work this way. And if not, whether it is possible to make one on my own.
I think this is what you're looking for. Using "thru" and "to end" returns a true value for the entire parse function: >> parse "aaaaaa" [thru "a" to end] == true And also allows you to perform an operation with the input string, at the point where the first matching value is found: >> parse "aaaaaa" [thru "a" copy x to end (print x)] aaaaa == true parse "aaaaaabab" [thru "a" copy x to end (print x)] aaaaabab == true >> parse "aaaaaabab" [thru "b" copy x to end (print x)] ab == true
If you want to capture the input string, including the matching character, use "to" instead of "thru": >> parse "aaaaaabab" [to "b" copy x to end (print x)] bab == true
And that's not limited to single characters. You can match a string: >> parse "aaaaaabab" [to "ba" copy x to end (print x)] bab == true >> parse "aaaaaabab" [thru "ba" copy x to end (print x)] b == true

Reply