|
6 | 6 |
|
7 | 7 | (defun attrib-includes? (node attrib value)
|
8 | 8 | (member value
|
9 |
| - (cl-ppcre:split "\\s+" (get-attribute node attrib)) |
10 |
| - :test #'string-equal)) |
| 9 | + (cl-ppcre:split "\\s+" (get-attribute node attrib)) |
| 10 | + :test #'string-equal)) |
11 | 11 |
|
12 | 12 | (defun make-or-matcher (forms)
|
13 | 13 | (let ((matchers (mapcar (lambda (f) (make-matcher-aux f)) forms)))
|
14 | 14 | (lambda (%node%)
|
15 | 15 | "or-matcher"
|
16 | 16 | (iter (for matcher in matchers)
|
17 |
| - (thereis (funcall matcher %node%)))))) |
| 17 | + (thereis (funcall matcher %node%)))))) |
18 | 18 |
|
19 | 19 | (defun make-and-matcher (forms )
|
20 | 20 | (let ((matchers (mapcar (lambda (f) (make-matcher-aux f)) forms)))
|
21 | 21 | (lambda (%node%)
|
22 | 22 | "and-matcher"
|
23 | 23 | (iter (for matcher in matchers)
|
24 |
| - (always (funcall matcher %node%)))))) |
| 24 | + (always (funcall matcher %node%)))))) |
25 | 25 |
|
26 | 26 | (defun make-class-matcher ( class )
|
27 | 27 | (lambda (%node%)
|
|
31 | 31 | (defun make-hash-matcher ( id )
|
32 | 32 | (lambda (%node%)
|
33 | 33 | "hash-matcher"
|
34 |
| - (string-equal (buildnode:get-attribute %node% :id) id))) |
| 34 | + (string-equal (get-attribute %node% "id") id))) |
35 | 35 |
|
36 | 36 | (defun make-elt-matcher ( tag )
|
37 | 37 | (lambda (%node%)
|
|
46 | 46 | "attrib-matcher"
|
47 | 47 | (lambda (%node%)
|
48 | 48 | (case match-type
|
49 |
| - (:equals (string-equal (buildnode:get-attribute %node% attrib) match-to)) |
| 49 | + (:equals (string-equal (get-attribute %node% attrib) match-to)) |
50 | 50 | (:includes (attrib-includes? %node% attrib match-to))
|
51 | 51 | (:dashmatch (member match-to
|
52 |
| - (cl-ppcre:split "-" (buildnode:get-attribute %node% attrib)) |
53 |
| - :test #'string-equal)) |
| 52 | + (cl-ppcre:split "-" (get-attribute %node% attrib)) |
| 53 | + :test #'string-equal)) |
54 | 54 | (:begins-with (alexandria:starts-with-subseq
|
55 |
| - match-to |
56 |
| - (buildnode:get-attribute %node% attrib) |
57 |
| - :test #'char-equal)) |
| 55 | + match-to |
| 56 | + (get-attribute %node% attrib) |
| 57 | + :test #'char-equal)) |
58 | 58 | (:ends-with (alexandria:ends-with-subseq
|
59 |
| - match-to |
60 |
| - (buildnode:get-attribute %node% attrib) |
61 |
| - :test #'char-equal)) |
62 |
| - (:substring (search match-to (buildnode:get-attribute %node% attrib) |
63 |
| - :test #'string-equal )) |
64 |
| - (:exists (buildnode:get-attribute %node% attrib))))) |
| 59 | + match-to |
| 60 | + (get-attribute %node% attrib) |
| 61 | + :test #'char-equal)) |
| 62 | + (:substring (search match-to (get-attribute %node% attrib) |
| 63 | + :test #'string-equal )) |
| 64 | + (:exists (get-attribute %node% attrib))))) |
65 | 65 |
|
66 | 66 |
|
67 | 67 |
|
68 | 68 | (defun make-immediate-child-matcher (parent-matcher child-matcher)
|
69 | 69 | (lambda (%node%)
|
70 | 70 | (and (funcall child-matcher %node%)
|
71 |
| - (parent-element %node%) |
72 |
| - (funcall parent-matcher (parent-element %node%))))) |
| 71 | + (parent-element %node%) |
| 72 | + (funcall parent-matcher (parent-element %node%))))) |
73 | 73 |
|
74 | 74 | (defun make-child-matcher (parent-matcher child-matcher )
|
75 | 75 | (lambda (%node%)
|
76 | 76 | (and (funcall child-matcher %node%)
|
77 |
| - (iter (for n in (parent-elements %node%)) |
| 77 | + (iter (for n in (parent-elements %node%)) |
78 | 78 | ;; the root is/could be document node
|
79 | 79 | ;; we can really only test on elements, so
|
80 | 80 | ;; this seems pretty valid, solves github issue:5
|
|
84 | 84 | (defun make-immediatly-preceded-by-matcher (this-matcher sibling-matcher )
|
85 | 85 | (lambda (%node%)
|
86 | 86 | (and (funcall this-matcher %node%)
|
87 |
| - (previous-sibling %node%) |
88 |
| - (funcall sibling-matcher (previous-sibling %node%))))) |
| 87 | + (previous-sibling %node%) |
| 88 | + (funcall sibling-matcher (previous-sibling %node%))))) |
89 | 89 |
|
90 | 90 | (defun make-preceded-by-matcher (this-matcher sibling-matcher )
|
91 | 91 | (lambda (%node%)
|
92 | 92 | (and (funcall this-matcher %node%)
|
93 |
| - (iter (for n initially (previous-sibling %node%) |
94 |
| - then (previous-sibling n)) |
95 |
| - (while n) |
96 |
| - (thereis (funcall sibling-matcher n)))))) |
| 93 | + (iter (for n initially (previous-sibling %node%) |
| 94 | + then (previous-sibling n)) |
| 95 | + (while n) |
| 96 | + (thereis (funcall sibling-matcher n)))))) |
97 | 97 |
|
98 | 98 | (defun make-pseudo-matcher (pseudo submatcher)
|
99 | 99 | (lambda (%node%) (funcall pseudo %node% submatcher)))
|
|
103 | 103 |
|
104 | 104 | (defun make-matcher-aux (tree)
|
105 | 105 | (ecase (typecase tree
|
106 |
| - (atom tree) |
107 |
| - (list (car tree))) |
| 106 | + (atom tree) |
| 107 | + (list (car tree))) |
108 | 108 | (:or (make-or-matcher (rest tree) ))
|
109 | 109 | (:and (make-and-matcher (rest tree) ))
|
110 | 110 | (:class (make-class-matcher (second tree) ))
|
|
113 | 113 | (:everything (lambda (%node%) (declare (ignore %node%)) T))
|
114 | 114 | (:attribute
|
115 | 115 | (let ((attrib (second tree)))
|
116 |
| - (ecase (length tree) |
117 |
| - (2 (make-attrib-matcher attrib :exists nil )) |
118 |
| - (3 (destructuring-bind (match-type match-to) (third tree) |
119 |
| - (make-attrib-matcher attrib match-type match-to )))))) |
| 116 | + (ecase (length tree) |
| 117 | + (2 (make-attrib-matcher attrib :exists nil )) |
| 118 | + (3 (destructuring-bind (match-type match-to) (third tree) |
| 119 | + (make-attrib-matcher attrib match-type match-to )))))) |
120 | 120 | (:immediate-child
|
121 | 121 | (make-immediate-child-matcher
|
122 |
| - (make-matcher-aux (second tree)) |
123 |
| - (make-matcher-aux (third tree)) |
124 |
| - )) |
| 122 | + (make-matcher-aux (second tree)) |
| 123 | + (make-matcher-aux (third tree)) |
| 124 | + )) |
125 | 125 | (:child
|
126 | 126 | (make-child-matcher
|
127 |
| - (make-matcher-aux (second tree)) |
128 |
| - (make-matcher-aux (third tree)) |
129 |
| - )) |
| 127 | + (make-matcher-aux (second tree)) |
| 128 | + (make-matcher-aux (third tree)) |
| 129 | + )) |
130 | 130 | (:immediatly-preceded-by
|
131 | 131 | (make-immediatly-preceded-by-matcher
|
132 |
| - (make-matcher-aux (third tree)) |
133 |
| - (make-matcher-aux (second tree)) |
134 |
| - )) |
| 132 | + (make-matcher-aux (third tree)) |
| 133 | + (make-matcher-aux (second tree)) |
| 134 | + )) |
135 | 135 | (:preceded-by
|
136 | 136 | (make-preceded-by-matcher
|
137 |
| - (make-matcher-aux (third tree)) |
138 |
| - (make-matcher-aux (second tree)) |
139 |
| - )) |
| 137 | + (make-matcher-aux (third tree)) |
| 138 | + (make-matcher-aux (second tree)) |
| 139 | + )) |
140 | 140 | (:pseudo
|
141 | 141 | (destructuring-bind (pseudo name &optional subselector) tree
|
142 |
| - (declare (ignore pseudo )) |
143 |
| - (make-pseudo-matcher |
144 |
| - (fdefinition (intern (string-upcase name) :pseudo)) |
145 |
| - (when subselector |
146 |
| - (make-matcher-aux subselector )) |
147 |
| - ))) |
| 142 | + (declare (ignore pseudo )) |
| 143 | + (make-pseudo-matcher |
| 144 | + (fdefinition (intern (string-upcase name) :pseudo)) |
| 145 | + (when subselector |
| 146 | + (make-matcher-aux subselector )) |
| 147 | + ))) |
148 | 148 | (:nth-pseudo
|
149 | 149 | (destructuring-bind (pseudo name mul add) tree
|
150 |
| - (declare (ignore pseudo )) |
151 |
| - (make-nth-pseudo-matcher |
152 |
| - (fdefinition (intern (string-upcase name) :pseudo)) |
153 |
| - mul add ))))) |
| 150 | + (declare (ignore pseudo )) |
| 151 | + (make-nth-pseudo-matcher |
| 152 | + (fdefinition (intern (string-upcase name) :pseudo)) |
| 153 | + mul add ))))) |
154 | 154 |
|
155 | 155 | (defun make-node-matcher (expression)
|
156 | 156 | (make-matcher-aux
|
|
176 | 176 | `(%node-matches?
|
177 | 177 | ,node
|
178 | 178 | ,(if (constantp inp e)
|
179 |
| - `(load-time-value (compile-css-node-matcher ,inp)) |
180 |
| - inp))) |
| 179 | + `(load-time-value (compile-css-node-matcher ,inp)) |
| 180 | + inp))) |
181 | 181 |
|
182 | 182 | (defgeneric %do-query (matcher node &key first?)
|
183 | 183 | (:documentation "matches selector inp against the node
|
|
196 | 196 | (%query inp trees))
|
197 | 197 |
|
198 | 198 | (define-compiler-macro query (inp &optional (trees 'buildnode:*document*) &environment e)
|
199 |
| - `(%query |
| 199 | + `(%query |
200 | 200 | ,(if (constantp inp e)
|
201 |
| - `(load-time-value (compile-css-node-matcher ,inp)) |
202 |
| - inp) |
| 201 | + `(load-time-value (compile-css-node-matcher ,inp)) |
| 202 | + inp) |
203 | 203 | ,trees))
|
204 |
| - |
205 |
| - |
206 |
| - |
0 commit comments