Add operands to syntax help message
This commit is contained in:
24
parse.lisp
24
parse.lisp
@ -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."
|
||||
|
Reference in New Issue
Block a user