git.fiddlerwoaroof.com
Browse code

Adjustments to make it actually load

fiddlerwoaroof authored on 06/12/2016 01:00:40
Showing 5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+Copyright (c) 2016 Edward Langley
2
+All rights reserved.
3
+
4
+Redistribution and use in source and binary forms, with or without
5
+modification, are permitted provided that the following conditions
6
+are met:
7
+
8
+Redistributions of source code must retain the above copyright notice,
9
+this list of conditions and the following disclaimer.
10
+
11
+Redistributions in binary form must reproduce the above copyright
12
+notice, this list of conditions and the following disclaimer in the
13
+documentation and/or other materials provided with the distribution.
14
+
15
+Neither the name of the project's author nor the names of its
16
+contributors may be used to endorse or promote products derived from
17
+this software without specific prior written permission.
18
+
19
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  INCLUDING, BUT NOT LIMITED
25
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
... ...
@@ -6,13 +6,21 @@ A simple package implementing a DSL for generating format strings.
6 6
 
7 7
 # Introduction
8 8
 
9
+## Hello World
10
+
11
+```lisp
12
+CL-USER> (define-message hello (name)
13
+           "Hello " :str)
14
+CL-USER> (hello "world")
15
+Hello world
16
+NIL
17
+```
18
+
9 19
 ```lisp
10 20
 
11 21
 (make-format-string '(:str)) #| ==> "~a" |#
12 22
 (make-format-string '((:map () :str))) #| ==> "~{~a~}" |#
13 23
 
14
-(define-message hello (name)
15
-  "Hello " :str)
16 24
 (define-message print-comma-separated (values)
17 25
   (:map () :str))
18 26
 
... ...
@@ -1,7 +1,7 @@
1 1
 ;;;; format-string-builder.asd
2 2
 
3 3
 (asdf:defsystem #:format-string-builder
4
-  :description "Describe format-string-builder here"
4
+  :description "A DSL wrapping cl:format's syntax with something more lispy."
5 5
   :author "fiddlerwoaroof"
6 6
   :license "MIT"
7 7
   :depends-on (:alexandria
... ...
@@ -87,9 +87,6 @@
87 87
       (null "")
88 88
       (t modifier))))
89 89
 
90
-(#-dev defvar
91
- #+dev defparameter *format-string-registry* (make-hash-table))
92
-
93 90
 (defun generate-function-defs ()
94 91
   (loop for name being the hash-keys in *format-string-registry* using (hash-value spec)
95 92
         collect `(,name (&key colon-p at-p)
... ...
@@ -105,24 +102,28 @@
105 102
      (setf (contents command) (mapcar #'form-step contents))
106 103
      command)))
107 104
 
108
-(defun form-step (form)
109
-  (flet ((dispatch-keyword (keyword &optional args)
110
-           (if-let ((spec (gethash keyword *format-string-registry*)))
111
-             (let ((result (apply #'make-instance spec)))
112
-               (when args
113
-                 (dispatch-command result args))
114
-               result))))
115
-    (etypecase form
116
-      (list (cond ((null form) nil)
117
-                  ((keywordp (car form)) (dispatch-keyword (car form) (cdr form)))))
118
-      ((or character string) form)
119
-      (keyword (dispatch-keyword form)))))
120
-
121
-(defun make-format-string (forms)
122
-  (with-output-to-string (*format-stream*)
123
-    (print-format-representation
124
-      (mapcar #'form-step (macroexpand forms))
125
-      *format-stream*)))
105
+(eval-when (:compile-toplevel :load-toplevel :execute)
106
+  (#-dev defvar #+dev defparameter
107
+	 *format-string-registry* (make-hash-table))
108
+
109
+  (defun form-step (form)
110
+    (flet ((dispatch-keyword (keyword &optional args)
111
+	     (if-let ((spec (gethash keyword *format-string-registry*)))
112
+	       (let ((result (apply #'make-instance spec)))
113
+		 (when args
114
+		   (dispatch-command result args))
115
+		 result))))
116
+      (etypecase form
117
+	(list (cond ((null form) nil)
118
+		    ((keywordp (car form)) (dispatch-keyword (car form) (cdr form)))))
119
+	((or character string) form)
120
+	(keyword (dispatch-keyword form)))))
121
+
122
+  (defun make-format-string (forms)
123
+    (with-output-to-string (*format-stream*)
124
+      (print-format-representation
125
+       (mapcar #'form-step (macroexpand forms))
126
+       *format-stream*))))
126 127
 
127 128
 (defun define-simple-format-char (name format-char &key at-p colon-p)
128 129
   (setf (gethash (intern (string name) :keyword)
... ...
@@ -257,9 +258,11 @@ spec passed as the body."
257 258
     (:ensure-line (#\&))
258 259
     (:new-line (#\%))))
259 260
 
260
-(define-message hello (stream name)
261
-  (:titlecase () "hello" #\space :str))
261
+#+null
262
+(progn
263
+  (define-message hello (stream name)
264
+    (:titlecase () "hello" #\space :str))
262 265
 
263
-(define-message print-comma-separated (stream)
264
-  (:own-line ()
265
-   (:rest () :str :exit ", ")))
266
+  (define-message print-comma-separated (stream)
267
+    (:own-line ()
268
+	       (:rest () :str :exit ", "))))
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 (defpackage #:format-string-builder
4 4
   (:use #:cl #:alexandria)
5
-  (:import #:serapeum #:intersperse #:op)
5
+  (:import-from #:serapeum #:intersperse #:op)
6 6
   (:export #:make-format-string
7 7
            #:define-message))
8 8