REPL " ?" trick works with nested expressions

This commit is contained in:
vindarel 2020-10-28 12:02:27 +01:00
parent 1eb751e9d2
commit e472084ed6
3 changed files with 26 additions and 6 deletions

24
utils.lisp Normal file
View file

@ -0,0 +1,24 @@
(in-package :sbcli)
(defun last-nested-expr (s/sexp)
"From an input with nested parens (or none), return the most nested
function call (or the first thing at the prompt).
(hello (foo (bar:qux *zz* ?
=>
bar:qux
"
(let* ((input (str:trim s/sexp))
(last-parens-token (first (last (str:split #\( input)))))
(first (str:words last-parens-token))))
#+or(nil)
(progn
(assert (string= "baz:qux"
(last-nested-expr "(hello (foo bar (baz:qux zz ?")))
(assert (string= "baz:qux"
(last-nested-expr "(baz:qux zz ?")))
(assert (string= "qux"
(last-nested-expr "(baz (qux ?")))
(assert (string= "sym"
(last-nested-expr "sym ?"))))