|
92 | 92 | (defmethod match (pattern (state state) &key skipp) |
93 | 93 | (match-parser-state pattern state :skipp skipp)) |
94 | 94 |
|
| 95 | +(defmethod match ((pattern null) (state state) &key skipp) |
| 96 | + "Nil should not match a parse-tree (use an empty vector as pattern to |
| 97 | +match an empty parse tree." |
| 98 | + (declare (ignore skipp)) |
| 99 | + nil) |
| 100 | + |
95 | 101 | (defmethod match ((pattern symbol) (state state) &key skipp) |
96 | 102 | (declare (ignore skipp)) |
97 | 103 | ;; These should return nil because we're trying to match 1 symbol |
|
151 | 157 | (unless (donep node-iterator) |
152 | 158 | (breeze.pattern::make-binding pattern (copy-iterator node-iterator)))) |
153 | 159 |
|
154 | | -(defmethod match ((pattern repetition) (node-iterator node-iterator) &key skipp) |
155 | | - (when skipp (breeze.pattern::skip node-iterator skipp)) |
156 | | - (unless (donep node-iterator) |
| 160 | +(defmethod match ((pattern repetition) (iterator node-iterator) &key skipp) |
| 161 | + (when skipp (breeze.pattern::skip iterator skipp)) |
| 162 | + (unless (donep iterator) |
157 | 163 | (loop |
158 | | - :with bindings := t ;; (make-binding-set) |
| 164 | + ;; :with bindings := t ;; (make-binding-set) |
159 | 165 | :with $pattern := (make-pattern-iterator |
160 | 166 | (repetition-pattern pattern)) |
161 | 167 | ;; TODO update node-iterator on match |
162 | | - :with $input := (copy-iterator node-iterator) |
| 168 | + :with $input := (copy-iterator iterator) |
163 | 169 | :for $prev-input := (copy-iterator $input) |
164 | | - :then (copy-iterator $input $prev-input) |
| 170 | + :then (copy-iterator $input $prev-input) |
165 | 171 | :for i :from 0 :below 100 ;; TODO removve infinite loop guard |
166 | 172 |
|
167 | 173 | :for new-bindings = (progn |
168 | 174 | (reset $pattern) |
169 | 175 | (match $pattern $input :skipp skipp)) |
| 176 | + :when new-bindings |
| 177 | + :collect new-bindings :into bindings |
170 | 178 | :do |
171 | | - ;;(break) |
172 | 179 | ;; No more input or, no match |
173 | 180 | (when (or |
174 | 181 | ;; no more input |
|
183 | 190 | ;; (break "i: ~s new-bindings: ~s" i new-bindings) |
184 | 191 | (if (and (zerop i) (not new-bindings)) |
185 | 192 | t |
186 | | - (let (($start (copy-iterator node-iterator)) |
| 193 | + (let (($start (copy-iterator iterator)) |
187 | 194 | ($end |
188 | 195 | ;; if it was a match, include the current position, |
189 | 196 | ;; otherwise stop at the previous one. |
190 | 197 | (if new-bindings $input $prev-input))) |
191 | | - ;; update node-iterator |
192 | | - (copy-iterator $end node-iterator) |
193 | | - #++ (return bindings) |
| 198 | + ;; update iterator |
| 199 | + (copy-iterator $end iterator) |
194 | 200 | ;; TODO return an object (iterator-range? + |
195 | 201 | ;; binding-sets???) |
196 | | - (cons $start $end)))))) |
| 202 | + (make-binding |
| 203 | + pattern |
| 204 | + (list |
| 205 | + :bindings bindings |
| 206 | + :$start $start |
| 207 | + :$end $end |
| 208 | + :times i))))))) |
197 | 209 | #++ |
198 | 210 | (when new-bindings |
199 | 211 | ;; collect all the bindings |
|
0 commit comments