[cl-ppcre-devel] Buffered multi-line question

Sébastien Saint-Sevin seb-cl-mailist at matchix.com
Thu Oct 14 18:38:17 UTC 2004


> > 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?

(defvar *my-string* "line1 word1 word2
line2 word1 word2
line3 word1 word2")

(defvar *my-scanner*
   '(:sequence
      (:filter my-filter 0)
      :WORD-BOUNDARY
      (:GREEDY-REPETITION 1 NIL :WORD-CHAR-CLASS)
      :WORD-BOUNDARY))

(let ((end-of-first-line 17))
   (defun my-filter (pos)
      (format t "Called at: ~A~%" pos)
      (and (< pos end-of-first-line)
         pos)))

CL-PPCRE 87 > (scan *my-scanner* *my-string*)
Called at: 0
0
5
#()
#()

==> OK, A match is found on first line.

CL-PPCRE 88 > (setf *my-scanner*
   '(:sequence
      (:filter my-filter 0)
      :WORD-BOUNDARY
      "line2"
      (:GREEDY-REPETITION 1 NIL :WORD-CHAR-CLASS)
      :WORD-BOUNDARY))
(:SEQUENCE (:FILTER MY-FILTER) :WORD-BOUNDARY "line2" (:GREEDY-REPETITION 1
NIL :WORD-CHAR-CLASS) :WORD-BOUNDARY)


CL-PPCRE 89 > (scan *my-scanner* *my-string*)
Called at: 0
Called at: 1
Called at: 2
Called at: 3
Called at: 4
Called at: 5
Called at: 6
Called at: 7
Called at: 8
Called at: 9
Called at: 10
Called at: 11
Called at: 12
Called at: 13
Called at: 14
Called at: 15
Called at: 16
Called at: 17
Called at: 18
Called at: 19
Called at: 20
Called at: 21
Called at: 22
Called at: 23
Called at: 24
Called at: 25
Called at: 26
Called at: 27
Called at: 28
Called at: 29
Called at: 30
Called at: 31
Called at: 32
Called at: 33
Called at: 34
Called at: 35
Called at: 36
Called at: 37
Called at: 38
Called at: 39
Called at: 40
Called at: 41
Called at: 42
Called at: 43
Called at: 44
Called at: 45
Called at: 46
Called at: 47
NIL

==> Here is the trouble: how to make the match abort when position 17 is
reach. Coz from there, the filter will always returns nil. So the last 30
calls are wasted time.


> > 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?
>

No.
I think the loop I'm speaking about is created by "insert-advance-fn" &
"create-scanner-aux" (while not understanding all the details by now...)

Last point, I can't access the position where the match actually has started
(the first of the fourth values returned by scan), so I have no way to
extract the current global match without using register.

Cheers,
Sebastien.









More information about the Cl-ppcre-devel mailing list