in reply to The "anchor" misnomer in regexes

FWIW, I agree with you that "anchor" is a misnomer. It gives the impression that when you say /foo$/ that the $ is a fixed location that the RE engine revolves around (which, as you say, is only the case under certain optimizations).

Ideally, in Perl 6, we'll have real anchors ...

I'm not quite sure what you mean, but it sounds like you think we'll have a way to tell the rules engine something like "jump to this point in the input stream and work sideways" or something. I don't think that "anchors" will be any different in perl6 than they are in perl5 except that we'll probably have more of them by default and they'll all be called "zero-width assertions" as is appropriate. It could just be my lack of imagination, but I don't foresee the rules engine having a way to easily switch its directionality for instance; it will still be primarily left-to-right.

Replies are listed 'Best First'.
Re^2: The "anchor" misnomer in regexes
by TimToady (Parson) on Dec 16, 2005 at 18:11 UTC
    Hmm, well, the engine is required to switch directionality to check lookbehind assertions, and given that, the optimizer would be silly not to turn /\s+$/ into /$<?after \s+>/. (With allowances for differing capture semantics, of course.)
      AFAIK, the current engine has no such requirement. Instead the restriction is placed that says that only fixed-length lookbehind expressions will work. That way the engine can get to the assertion, backs up, tries to match, then proceed based on that answer. No need to match backwards.

      By contrast Java can match backwards, and the capacity shows in its ability to do variable width lookbehind assertions.

      Well, I guess it was my lack of imagination then :-) But does that mean that right-to-left directionality changes will all be encapsulated in lookbehinds?