On Thu, 14 Oct 2004 17:01:39 +0200, Sébastien Saint-Sevin seb-cl-mailist@matchix.com wrote:
How can I then abort the scan quickly, while avoiding funcalling the filter with the rest of the string ? Something like (setf *start-pos* end-of-string-value) ?
No, never change these internal values unless you're looking for trouble - see docs. Just return NIL from the filter. (I suppose you're talking about the 0.9.0 filters here.)
Something like
(defvar *max-start-pos* 0)
(defun my-filter (pos) (and (< pos *max-start-pos*) pos))
(scan '(:sequence ... (:filter my-filter 0) ...) target)
should assure that there's only a match if the position between the first ... and the second ... is below *MAX-START-POS*.
The zero is optional but it'll potentially help the regex engine to optimize the scanner depending on the rest of the parse tree.
Here's an example for optimization:
* (defun my-filter (pos) (print "I was called") pos)
MY-FILTER * (cl-ppcre:scan '(:sequence "fo" (:filter my-filter) "bar") "xyzfoobar")
"I was called" NIL * (cl-ppcre:scan '(:sequence "fo" (:filter my-filter 0) "bar") "xyzfoobar")
NIL
Note that in the second example the filter wasn't called at all because due to the zero-length declaration the regex engine was able to determine that the target string must end with "fobar" - which it didn't. In the first example this couldn't be done because there wasn't enough information available.
You shouldn't lie to the regex engine, though... :)
Thanks a lot, you're so good ;-)
Nah... :)
Cheers, Edi.