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

@ -84,36 +84,63 @@ functions involved in evaluating and typesetting."
do (return-from ascii-string-p))
t)
(defun format-syntax-string (syntax-list &key ascii-only)
"Format SYNTAX-LIST into a string suitable for printing in a table in
`print-syntax-help'."
(format nil "~{~a~^, ~}"
(sort (copy-list
(if ascii-only
(remove-if-not 'ascii-string-p
syntax-list)
syntax-list))
'string<)))
(defun print-syntax-help (ascii-only)
"Print the syntax help message."
(loop
for ((sym (name . nicks) desc examples) . rest-desc)
= *operator-descriptions* then rest-desc
for ((_sym . syntax) . rest-st) = *operator-symbol-table* then rest-st
for syntax-str = (format nil "~{~a~^, ~}"
(sort (copy-list
(if ascii-only
(remove-if-not 'ascii-string-p
syntax)
syntax))
'string<))
for syntax-str = (format-syntax-string syntax :ascii-only ascii-only)
while sym
maximize (length name) into name-col-len
maximize (length syntax-str) into syntax-col-len
collect syntax-str into syntax-entries
finally
(let ((col-widths (list name-col-len syntax-col-len))
(box-lookup-table (if ascii-only
*table-border-ascii-alist*
*table-border-unicode-alist*)))
(with-draw-table (t col-widths box-lookup-table
:padding 1 :align :left)
(:row (list "Operator" "Syntax"))
(:seperator)
(loop for (sym (name . nicks) desct) in *operator-descriptions*
for syntax-str in syntax-entries do
(:row (list name syntax-str))))))
(format t "~%~%~a~%Example:~% abc|d = ~a~%"
(setq name-col-len (max name-col-len (length "Operator"))
syntax-col-len (max syntax-col-len (length "Syntax")))
(with-draw-table (t (list name-col-len syntax-col-len)
(if ascii-only
*table-border-ascii-alist*
*table-border-unicode-alist*)
:padding 1 :align :left)
(:row '("Operator" "Syntax"))
(:seperator)
(loop for (sym (name . nicks) desct) in *operator-descriptions*
for syntax-str in syntax-entries do
(:row (list name syntax-str)))))
(terpri)
(loop for (sym . syntax) in *operand-symbol-table*
for name = (symbol-name sym)
for syntax-str = (format-syntax-string syntax :ascii-only ascii-only)
collect (string-downcase name) into names
maximize (length name) into name-col-len
collect syntax-str into syntax-strs
maximize (length syntax-str) into syntax-col-len
finally
(setq name-col-len (max name-col-len (length "Operand"))
syntax-col-len (max syntax-col-len (length "Syntax")))
(with-draw-table (t (list name-col-len syntax-col-len)
(if ascii-only
*table-border-ascii-alist*
*table-border-unicode-alist*)
:padding 1 :align :left)
(:row '("Operand" "Syntax"))
(:seperator)
(loop for name in names
for syntax-str in syntax-strs
do (:row (list name syntax-str)))))
(format t "~%~a~%Example:~% abc|d = ~a~%"
(word-wrap-string "Two operands next to each other is treated as an
'implicit and' (unless this feature is disabled).")
(typeset-proposition '(or (and "a" "b" "c") "d")