[climacs-devel] Re: regex
Nicolas Sceaux
nicolas.sceaux at free.fr
Thu May 5 14:21:51 UTC 2005
Lawrence Mitchell <wencel at gmail.com> writes:
> After discussing alternatives here and with Edi, it seems like
> the way forward is to modify cl-ppcre to change all occurances of
> (SCHAR *STRING* ...) and the like in the sources to some function
> that returns a character in a Climacs buffer.
>
> That is, rather than doing (scan regex string) and then matching
> in string, do (scan regex buffer) and somehow match in buffer.
OK, I think I managed to have SCAN do its job on a buffer instead of a
string. On a fresh image:
---- test.lisp ----
(in-package :common-lisp-user)
(defpackage :climacs-buffer
(:use #:cl)
(:export #:buffer #:size #:buffer-object #:buffer-substring))
(in-package :climacs-buffer)
;;; fake buffer implementation, for testing
(defclass buffer ()
((contents :initarg :contents)))
(defmethod size ((buffer buffer))
(length (slot-value buffer 'contents)))
(defmethod buffer-object ((buffer buffer) offset)
(aref (slot-value buffer 'contents) offset))
(defmethod buffer-substring ((buffer buffer) start &optional (end (size buffer)))
(subseq (slot-value buffer 'contents) start end))
(in-package :common-lisp-user)
(defvar *buffer* (make-instance 'climacs-buffer:buffer :contents "
salut les amis. Comment allez-vous tous les 4 ?"))
(pushnew :climacs-ppcre *features*)
(asdf:oos 'asdf:compile-op :cl-ppcre)
(asdf:oos 'asdf:load-op :cl-ppcre)
---- test.lisp ----
;;;; Compile file /home/nicolas/lisp/climacs-ppcre/test.lisp ...
...
CL-USER> (cl-ppcre:scan "\\w+\\s+(\\d+)" *buffer*)
41
46
#(45)
#(46)
CL-USER> (climacs-buffer:buffer-substring *buffer* 41 46)
"les 4"
which seems not bad.
I'll clean a bit my hacks on CL-PPCRE and then send them here.
Nicolas
More information about the climacs-devel
mailing list