Skip to content

Commit 671aa67

Browse files
committed
micros/walker: for-as-on-list
1 parent 7d0fb09 commit 671aa67

File tree

4 files changed

+2049
-1952
lines changed

4 files changed

+2049
-1952
lines changed

contrib/walker/example.lisp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,13 @@
140140
:for x :in '(1 2 3) :do (print x))
141141
(loop :with foo := nil
142142
:for x :in '(1 2 3) :do (print x))
143+
(loop :with fn := #'cddr :and a
144+
:for x :in (list a) :by fn :do (print x))
145+
146+
(loop :for x :on '(1 2 3) :do (print x))
147+
(loop :with foo
148+
:for x :on '(1 2 3) :do (print x))
149+
(loop :with foo := nil
150+
:for x :on '(1 2 3) :do (print x))
151+
(loop :with fn := #'cddr :and a
152+
:for x :on (list a) :by fn :do (print x))

contrib/walker/loop-form.lisp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@
5151
(defclass it-form (ast)
5252
())
5353

54-
(defclass for-as-in-list-clause (ast <with-binding-form>)
54+
(defclass <for-as-in-on-list-clause> (ast <with-binding-form>)
5555
((binding :initarg :binding
5656
:reader ast-binding)
57-
(in :initarg :in
58-
:reader ast-in)
57+
(in-on :initarg :in-on
58+
:reader ast-in-on)
5959
(by :initarg :by
6060
:reader ast-by)))
6161

62+
(defclass for-as-in-list-clause (<for-as-in-on-list-clause>) ())
63+
(defclass for-as-on-list-clause (<for-as-in-on-list-clause>) ())
64+
6265
(defun walk-d-var-spec (walker d-var-spec env path)
6366
(cond ((null d-var-spec)
6467
'())
@@ -194,7 +197,7 @@
194197
(cond ((accept :in)
195198
(for-as-in-list binding))
196199
((accept :on)
197-
(for-as-on-list))
200+
(for-as-on-list binding))
198201
((accept :=)
199202
(for-as-equals-then))
200203
((accept :across)
@@ -206,21 +209,23 @@
206209
;; TODO: error
207210
;; TODO: from, to, downfrom, downto, above, by
208211
)))))
209-
(for-as-in-list (binding)
212+
213+
(for-as-in-on-list (ast-class binding)
210214
(let* ((for-pos (- pos 2))
211215
(in (walk walker (next) env (cons (+ for-pos 3) path)))
212216
(by (when (accept :by)
213217
(walk walker (next) env (cons (+ for-pos 5) path)))))
214-
(push (make-instance 'for-as-in-list-clause
218+
(push (make-instance ast-class
215219
:path (cons (+ for-pos 1) path)
216220
:binding binding
217-
:in in
221+
:in-on in
218222
:by by)
219223
for-as-clauses)
220224
(setf env (extend-env env binding))))
221-
(for-as-on-list ()
222-
;; TODO
223-
)
225+
(for-as-in-list (binding)
226+
(for-as-in-on-list 'for-as-in-list-clause binding))
227+
(for-as-on-list (binding)
228+
(for-as-in-on-list 'for-as-on-list-clause binding))
224229
(for-as-equals-then ()
225230
;; TODO
226231
)
@@ -290,8 +295,8 @@
290295
(defmethod visit (visitor (ast it-form))
291296
nil)
292297

293-
(defmethod visit (visitor (ast for-as-in-list-clause))
294-
(visit visitor (ast-in ast))
298+
(defmethod visit (visitor (ast <for-as-in-on-list-clause>))
299+
(visit visitor (ast-in-on ast))
295300
(when (ast-by ast) (visit visitor (ast-by ast))))
296301

297302
(defmethod visit (visitor (ast simple-loop-form))

0 commit comments

Comments
 (0)