On Thu, 14 Oct 2004 18:18:46 +0200, Sébastien Saint-Sevin seb-cl-mailist@matchix.com wrote:
(defvar *max-start-pos* 0)
(defun my-filter (pos) (and (< pos *max-start-pos*) pos))
(scan '(:sequence ... (:filter my-filter 0) ...) target)
The majority of regex I'm using are unfortunately not optimizable.
Are you sure?
Going back to my buffer. Let's say I'm looking at ten lines at a time. I want start to occurs only at first line and I can do it with filters (that's great !). But the engine will still continue moving forward into the string for the nine remaining lines, and it will call my filter for each position in each line to just get nil everytime.
I'm sorry but I still don't fully understand your problem. Could you give an example with actual code and data?
So the question for forcing a full abort immediatly and not calling so many times the filter. In fact this is the case for all filter that once it has returned nil, will return nil forever (and are in a position in the parse tree where they can't be shadowed by some backtracking!).
Are you using DO-SCANS or another loop construct? How about this?
(defvar *max-start-pos* 0)
(defvar *stop-immediately* nil)
(defun my-filter (pos) (cond ((< pos *max-start-pos*) pos) (t (setq *stop-immediately* t) nil)))
(let (*stop-immediately*) (do-scans (...) (when *stop-immediately* (return)) ;;; your stuff here ))
So once *STOP-IMMEDIATELY* is set by your filter the loop will be instantly exited.
Cheers, Edi.