-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.lisp
More file actions
36 lines (29 loc) · 1.27 KB
/
parse.lisp
File metadata and controls
36 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
;; (c) www.neverblued.info
;; LLGPL -> http://opensource.franz.com/preamble.html
(in-package #:wsf)
(defgeneric server-parsers (parse-server))
(defclass parse-server (lisp-server)
((parsers :accessor server-parsers :initform nil)))
(defclass regex-parser ()
((regex :initarg :regex :accessor parser-regex)
(patch :initarg :patch :accessor parser-patch)))
(defgeneric ranked-parsers (parse-server))
(defmethod ranked-parsers (server)
(server-parsers server))
(defun parse (text &optional (server *server*))
(let ((*package* (server-package server)))
(iter (for parser in (ranked-parsers server))
(with-accessors ((regex parser-regex)
(patch parser-patch))
parser
(setf text
(regex-replace-all regex text
(awith patch
(typecase it
(string it)
(function
(lambda (source &rest patch-args)
(awith (apply it patch-args)
(or it source))))))
:simple-calls t)))))
text)