213 lines
14 KiB
HTML
213 lines
14 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="../../coverage.css"/> <title> beowulf/reader/macros.clj </title>
|
|
</head>
|
|
<body>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
001 (ns beowulf.reader.macros
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
002 "Can I implement reader macros? let's see!
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
003
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
004 We don't need (at least, in the Clojure reader) to rewrite forms like
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
005 `'FOO`, because that's handled by the parser. But we do need to rewrite
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
006 things which don't evaluate their arguments, like `SETQ`, because (unless
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
007 LABEL does it, which I'm not yet sure of) we're not yet able to implement
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
008 things which don't evaluate arguments.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
009
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
010 TODO: at this stage, the following should probably also be read macros:
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
011 DEFINE"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
012 (:require [beowulf.cons-cell :refer [make-beowulf-list]]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
013 [beowulf.host :refer [CONS LIST]]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
014 [clojure.string :refer [join]]))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
015
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
017 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
018 ;;; We don't need (at least, in the Clojure reader) to rewrite forms like
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
019 ;;; "'FOO", because that's handled by the parser. But we do need to rewrite
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
020 ;;; things which don't evaluate their arguments, like `SETQ`, because (unless
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
021 ;;; LABEL does it, which I'm not yet sure of) we're not yet able to implement
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
022 ;;; things which don't evaluate arguments.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
023 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
024 ;;; TODO: at this stage, the following should probably also be read macros:
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
025 ;;; DEFINE
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
026 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
028 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
029 ;;; Copyright (C) 2022-2023 Simon Brooke
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
030 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
031 ;;; This program is free software; you can redistribute it and/or
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
032 ;;; modify it under the terms of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
033 ;;; as published by the Free Software Foundation; either version 2
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
034 ;;; of the License, or (at your option) any later version.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
035 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
036 ;;; This program is distributed in the hope that it will be useful,
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
037 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
038 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
039 ;;; GNU General Public License for more details.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
040 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
041 ;;; You should have received a copy of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
042 ;;; along with this program; if not, write to the Free Software
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
043 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
044 ;;;
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
046
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
047 (def ^:dynamic *readmacros*
|
|
</span><br/>
|
|
<span class="covered" title="6 out of 6 forms covered">
|
|
048 {:car {'DEFUN (fn [f]
|
|
</span><br/>
|
|
<span class="covered" title="9 out of 9 forms covered">
|
|
049 (LIST 'SET (LIST 'QUOTE (second f))
|
|
</span><br/>
|
|
<span class="covered" title="11 out of 11 forms covered">
|
|
050 (LIST 'QUOTE (CONS 'LAMBDA (rest (rest f))))))
|
|
</span><br/>
|
|
<span class="covered" title="13 out of 13 forms covered">
|
|
051 'SETQ (fn [f] (LIST 'SET (LIST 'QUOTE (second f)) (nth f 2)))}})
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
052
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
053 (defn expand-macros
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
054 [form]
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
055 (try
|
|
</span><br/>
|
|
<span class="covered" title="19 out of 19 forms covered">
|
|
056 (if-let [car (when (and (coll? form) (symbol? (first form)))
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
057 (first form))]
|
|
</span><br/>
|
|
<span class="covered" title="10 out of 10 forms covered">
|
|
058 (if-let [macro (-> *readmacros* :car car)]
|
|
</span><br/>
|
|
<span class="covered" title="8 out of 8 forms covered">
|
|
059 (make-beowulf-list (apply macro (list form)))
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
060 form)
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
061 form)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
062 (catch Exception any
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
063 (println (join "\n"
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
064 ["# ERROR while expanding macro:"
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
065 (str "# Form: " form)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
066 (str "# Error class: " (.getName (.getClass any)))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
067 (str "# Message: " (.getMessage any))]))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 1 forms covered">
|
|
068 form)))
|
|
</span><br/>
|
|
</body>
|
|
</html>
|