X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/4ee476bc29b80fca2faabb4bd286ca70c98f7a44..fddbedf7b1b4b19add30eeb62281748cc77e6955:/src/pset-impl.lisp diff --git a/src/pset-impl.lisp b/src/pset-impl.lisp index 60674ff..42049db 100644 --- a/src/pset-impl.lisp +++ b/src/pset-impl.lisp @@ -74,12 +74,33 @@ (error "Symbol `~A' not external in package `~A'" name (package-name package))))))))) +(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." + (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 @@ -114,6 +135,20 @@ ((value symbol) (type (eql :symbol)) (wanted (eql :id))) (frob-identifier (symbol-name value))) +;;; Boolean. + +(defmethod coerce-property-value + ((value symbol) (type (eql :symbol)) (wanted (eql :boolean))) + value) + +(defmethod coerce-property-value + ((value string) (type (eql :id)) (wanted (eql :boolean))) + (truishp value)) + +(defmethod coerce-property-value + ((value integer) (type (eql :int)) (wanted (eql :boolean))) + (not (zerop value))) + ;;; Types. (defmethod coerce-property-value