repos
/
Oh, Ducks!
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
"lispier" regexps, l*last-child stuff
Annotate for file /regexp-template.lisp
2009-11-13 pix
1
;;;; we add an automagical &rest, because cl-unification's cl-ppcre support
04:19:11 '
2
;;;; requires matching the entire string, and we're generally concerned with
'
3
;;;; just the beginning of it.
2009-11-18 pix
4
(in-package #:oh-ducks)
2009-11-13 pix
5
04:19:11 '
6
(defmethod make-template ((kind (eql 'regexp+)) (spec cons))
'
7
(destructuring-bind (re-kwd regexp &optional vars &rest keys)
'
8
spec
2009-11-13 pix
9
(declare (ignore re-kwd))
2009-11-13 pix
10
(make-instance 'unify::regular-expression-template
2009-11-13 pix
11
:spec (list* 'unify::regexp
2009-11-13 pix
12
(concatenate 'string regexp "(.*)$")
2009-11-13 pix
13
(append vars '(?&rest))
2009-11-13 pix
14
keys))))
04:19:11 '
15
2009-11-15 pix
16
;; for parsing front-to-back
14:25:29 '
17
(defmethod make-template ((kind (eql 'regexp^)) (spec cons))
'
18
(destructuring-bind (re-kwd regexp &optional vars &rest keys)
'
19
spec
'
20
(declare (ignore re-kwd))
'
21
(make-instance 'unify::regular-expression-template
'
22
:spec (list* 'unify::regexp
'
23
(concatenate 'string "^" regexp "(.*)$")
'
24
(append vars '(?&rest))
'
25
keys))))
'
26
'
27
;; For parsing back-to-front
'
28
(defmethod make-template ((kind (eql 'regexp$)) (spec cons))
'
29
(destructuring-bind (re-kwd regexp &optional vars &rest keys)
'
30
spec
'
31
(declare (ignore re-kwd))
'
32
(make-instance 'unify::regular-expression-template
'
33
:spec (list* 'unify::regexp
2010-01-04 pix
34
(cond
05:59:48 '
35
((stringp regexp)
'
36
(concatenate 'string "^(.*?)" regexp "$"))
'
37
((listp regexp)
'
38
`(:sequence :start-anchor
'
39
(:register (:non-greedy-repetition 0 nil :everything))
'
40
,@regexp
'
41
:end-anchor))
'
42
(t (error "Unknown regexp format.")))
2009-11-15 pix
43
(append '(?&rest) vars)
14:25:29 '
44
keys))))
'
45
2009-11-13 pix
46
;; (match (#t(regexp+ "^f(o+)" (?o)) "fooooooobar") (values o &rest))
07:44:02 '
47
;; => "ooooooo", "bar"
2009-11-14 pix
48
;; prevent clisp from crashing when it loads .fas files with our regexp templates in them
00:47:11 '
49
(defmethod make-load-form ((object unify::regular-expression-template) &optional env)
2009-11-13 pix
50
(declare (ignore env))
2009-11-14 pix
51
`(make-template ',(first (template-spec object)) ',(template-spec object))
00:47:11 '
52
#+(or) ; make-instance should be fine, too
2009-11-13 pix
53
`(make-instance ',(class-of object) :spec ',(template-spec object)))
12:15:14 '
54