Skip to content

Commit

Permalink
Remove copyright notice and untabify.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-strandh committed Sep 24, 2020
1 parent c87f9f7 commit aa012ed
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 262 deletions.
68 changes: 28 additions & 40 deletions Code/Loop/for-as-clause.lisp
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
;;;; Copyright (c) 2014
;;;;
;;;; Robert Strandh ([email protected])
;;;;
;;;; all rights reserved.
;;;;
;;;; Permission is hereby granted to use this software for any
;;;; purpose, including using, modifying, and redistributing it.
;;;;
;;;; The software is provided "as-is" with no warranty. The user of
;;;; this software assumes any responsibility of the consequences.

(cl:in-package #:sicl-loop)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -60,8 +48,8 @@

(defmethod bound-variables ((clause for-as-clause))
(reduce #'append
(mapcar #'bound-variables (subclauses clause))
:from-end t))
(mapcar #'bound-variables (subclauses clause))
:from-end t))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
Expand All @@ -77,30 +65,30 @@

(defun for-as-subclause-parser (tokens)
(loop for parser in *for-as-subclause-parsers*
do (multiple-value-bind (successp result rest)
(funcall parser tokens)
(when successp
(return (values t result rest))))
finally (return (values nil nil tokens))))
do (multiple-value-bind (successp result rest)
(funcall parser tokens)
(when successp
(return (values t result rest))))
finally (return (values nil nil tokens))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Parse a FOR-AS clause.

(define-parser for-as-clause-parser
(consecutive (lambda (for subclause more-subclauses)
(declare (ignore for))
(make-instance 'for-as-clause
:subclauses (cons subclause more-subclauses)))
(alternative (keyword-parser 'for)
(keyword-parser 'as))
'for-as-subclause-parser
(repeat* #'list
(consecutive (lambda (and subclause)
(declare (ignore and))
subclause)
(keyword-parser 'and)
'for-as-subclause-parser))))
(declare (ignore for))
(make-instance 'for-as-clause
:subclauses (cons subclause more-subclauses)))
(alternative (keyword-parser 'for)
(keyword-parser 'as))
'for-as-subclause-parser
(repeat* #'list
(consecutive (lambda (and subclause)
(declare (ignore and))
subclause)
(keyword-parser 'and)
'for-as-subclause-parser))))

(add-clause-parser 'for-as-clause-parser)

Expand All @@ -114,46 +102,46 @@

(defmethod initial-bindings ((clause for-as-clause))
(reduce #'append (mapcar #'initial-bindings (subclauses clause))
:from-end t))
:from-end t))

(defmethod final-bindings ((clause for-as-clause))
(reduce #'append (mapcar #'final-bindings (subclauses clause))
:from-end t))
:from-end t))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Compute the declarations.

(defmethod declarations ((clause for-as-clause))
(reduce #'append (mapcar #'declarations (subclauses clause))
:from-end t))
:from-end t))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Compute the prologue-form.

(defmethod prologue-form ((clause for-as-clause) end-tag)
`(progn ,@(mapcar (lambda (subclause)
(prologue-form subclause end-tag))
(subclauses clause))))
(prologue-form subclause end-tag))
(subclauses clause))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Compute the termination-form.

(defmethod termination-form ((clause for-as-clause) end-tag)
`(progn ,@(mapcar (lambda (subclause)
(termination-form subclause end-tag))
(subclauses clause))))
(termination-form subclause end-tag))
(subclauses clause))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Compute the body-form.

(defmethod body-form ((clause for-as-clause) end-tag)
`(progn ,@(mapcar (lambda (clause)
(body-form clause end-tag))
(subclauses clause))))
(body-form clause end-tag))
(subclauses clause))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
Expand Down
82 changes: 35 additions & 47 deletions Code/Loop/for-as-equals-then-clause.lisp
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
;;;; Copyright (c) 2014
;;;;
;;;; Robert Strandh ([email protected])
;;;;
;;;; all rights reserved.
;;;;
;;;; Permission is hereby granted to use this software for any
;;;; purpose, including using, modifying, and redistributing it.
;;;;
;;;; The software is provided "as-is" with no warranty. The user of
;;;; this software assumes any responsibility of the consequences.

(cl:in-package #:sicl-loop)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -22,41 +10,41 @@

(defmethod bound-variables ((subclause for-as-equals-then))
(mapcar #'car
(extract-variables (var-spec subclause) nil)))
(extract-variables (var-spec subclause) nil)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Parsers.

(define-parser for-as-equals-then-parser-1
(consecutive (lambda (var-spec type-spec = form1 then form2)
(declare (ignore = then))
(make-instance 'for-as-equals-then
:var-spec var-spec
:type-spec type-spec
:initial-form form1
:subsequent-form form2))
;; Accept anything for now. Analyze later.
'anything-parser
'optional-type-spec-parser
(keyword-parser '=)
'anything-parser
(keyword-parser 'then)
'anything-parser))
(declare (ignore = then))
(make-instance 'for-as-equals-then
:var-spec var-spec
:type-spec type-spec
:initial-form form1
:subsequent-form form2))
;; Accept anything for now. Analyze later.
'anything-parser
'optional-type-spec-parser
(keyword-parser '=)
'anything-parser
(keyword-parser 'then)
'anything-parser))

(define-parser for-as-equals-then-parser-2
(consecutive (lambda (var-spec type-spec = form1)
(declare (ignore =))
(make-instance 'for-as-equals-then
:var-spec var-spec
:type-spec type-spec
:initial-form form1
:subsequent-form form1))
;; Accept anything for now. Analyze later.
'anything-parser
'optional-type-spec-parser
(keyword-parser '=)
'anything-parser))
(declare (ignore =))
(make-instance 'for-as-equals-then
:var-spec var-spec
:type-spec type-spec
:initial-form form1
:subsequent-form form1))
;; Accept anything for now. Analyze later.
'anything-parser
'optional-type-spec-parser
(keyword-parser '=)
'anything-parser))

;;; Make sure parser 1 is tried first. For that, it must be added
;;; last.
Expand All @@ -69,19 +57,19 @@

(defmethod initial-bindings ((clause for-as-equals-then))
(loop with d-var-spec = (var-spec clause)
with d-type-spec = (type-spec clause)
for (variable) in (extract-variables d-var-spec d-type-spec)
collect `(,variable nil)))
with d-type-spec = (type-spec clause)
for (variable) in (extract-variables d-var-spec d-type-spec)
collect `(,variable nil)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Compute the declarations.

(defmethod declarations ((clause for-as-equals-then))
(loop with d-var-spec = (var-spec clause)
with d-type-spec = (type-spec clause)
for (variable type) in (extract-variables d-var-spec d-type-spec)
collect `(cl:type (or null ,type) ,variable)))
with d-type-spec = (type-spec clause)
for (variable type) in (extract-variables d-var-spec d-type-spec)
collect `(cl:type (or null ,type) ,variable)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
Expand All @@ -93,8 +81,8 @@
(fresh-variables (var-spec clause))
`(let* ,(destructure-variables temp-tree (initial-form clause))
(setq ,@(loop for (original . temp) in dictionary
collect original
collect temp)))))
collect original
collect temp)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
Expand All @@ -105,5 +93,5 @@
(fresh-variables (var-spec clause))
`(let* ,(destructure-variables temp-tree (subsequent-form clause))
(setq ,@(loop for (original . temp) in dictionary
collect original
collect temp)))))
collect original
collect temp)))))
Loading

0 comments on commit aa012ed

Please sign in to comment.