src/pset-impl.lisp: Accept `yup' and `nope' as booleans.
[sod] / src / pset-impl.lisp
index e6986a5..42049db 100644 (file)
                 (error "Symbol `~A' not external in package `~A'"
                        name (package-name package)))))))))
 
-(let ((truish '("true" "t" "yes" "verily"))
-      (falsish '("false" "nil" "no" "nowise")))
+(let ((truth-map (make-hash-table :test #'equalp)))
+  (dolist (string '("true" "t" "yes" "on" "yup" "verily"))
+    (setf (gethash string truth-map) t))
+  (dolist (string '("false" "nil" "no" "off" "nope" "nowise"))
+    (setf (gethash string truth-map) nil))
   (defun truishp (string)
     "Convert STRING to a boolean."
-    (cond ((member string truish :test #'string=) t)
-         ((member string falsish :test #'string=) nil)
-         (t (error "Unrecognized boolean value `~A'" string)))))
+    (multiple-value-bind (val foundp) (gethash string truth-map)
+      (if foundp val
+         (error "Unrecognized boolean value `~A'" string)))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Property representation.
 (defmethod file-location ((prop property))
   (file-location (p-location prop)))
 
+;;; Input conversions.
+
+(defmethod decode-property ((raw symbol)) (values :symbol raw))
+(defmethod decode-property ((raw integer)) (values :int raw))
+(defmethod decode-property ((raw string)) (values :string raw))
+(defmethod decode-property ((raw character)) (values :char raw))
+(defmethod decode-property ((raw function)) (values :func raw))
+(defmethod decode-property ((raw c-type)) (values :type raw))
+(defmethod decode-property ((raw c-fragment)) (values :c-fragment raw))
+
 ;;; Keywords.
 
 (defmethod coerce-property-value