Add operands to syntax help message

This commit is contained in:
2024-09-16 04:17:24 -07:00
parent f9091ad7c1
commit 421eff906d
4 changed files with 69 additions and 31 deletions

View File

@ -197,19 +197,23 @@ are useful for use in things like syntax explanation messages.")
"Return whether OPER is a unary operator or not."
(eq oper 'not))
(defparameter *operand-symbol-table*
'((true "t" "true" "" "1")
(false "f" "false" "⊥" "0"))
"Alist mapping operand symbols (true and false) to their textual
representations.")
(defun interpret-operand (oper-str)
"Return a symbol representing OPER-STR, or the string itself if it represents
a variable."
(cond
((member oper-str '("t" "true" "" "1") :test 'equalp)
'true)
((member oper-str '("f" "false" "⊥" "0") :test 'equalp)
'false)
(t
(loop for char across oper-str
unless (symbol-char-p char)
do (return nil)
finally (return oper-str)))))
(dolist (entry *operand-symbol-table*)
(when (member oper-str (cdr entry) :test 'equalp)
(return-from interpret-operand (car entry))))
;; check if OPER-STR is a valid variable name
(if (or (zerop (length oper-str))
(find-if-not 'symbol-char-p oper-str))
nil
oper-str))
(defun string-first-char-safe (str)
"Return the first character of STR, or nil if it is empty."