On 5/13/05, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: > First, I'm quite certain that $r2 and $r3 are different. For > illustration, let's use a variation like: > > $q2 = rx / \w [ abc ::: def | ghi ::: jkl | mn ::: op ] /; > $q3 = rx / \w [ [ abc :: def | ghi :: jkl | mn :: op ] ]/; > > "xyzabc---xyzghijklmno" ~~ $q2 # fails after seeing "zabc" > "xyzabc---xyzghijklmno" ~~ $q3 # matches "zghijkl"
Okay, I know where the misunderstanding is. When we use these kinds of examples, let's not rely on the implicit matching semantic. I'm saying that the above code is equivalent to: # the following is a rule, so ::: backtracks out of it and no further rule q2 { \w [ abc ::: def | ghi ::: jkl | mn ::: op ] } rule q3 { \w [ [ abc :: def | ghi :: jkl | mn :: op ] ] } "xyzabc---xyzghijklmno" ~~ /^ .*? <q2>/; # ::: backtracks into the .*? "xyzabc---xyzghijklmno" ~~ /^ .*? <q3>/; The presence of the \w does nothing, because \w doesn't backtrack. Alternations and quantifiers backtrack when you fail beyond them, \w just fails. You never enter the same subpattern (meant in the most general case: .* is a subpattern, for instance) in the same state. Something had to change behind you in order for a subpattern to be re-entered. I think the misunderstanding is rather simple. You keep talking like you prepend a .*? to the rule we're matching. I think that's wrong (and this is where I'm making a design call, so we can dispute on this once we're clear that it's this that is being disputed). I think there is a special rule: rule matchanywhere($rx) { .*? <$rx> } Which makes a *subrule call* to the rule we're matching. Therefore ::: just breaks out of that subrule, and backtracks into the .*? again. Because of this, I think there will be a difference between ::: and <commit> at the top level, but not :: and :::. Luke