mirror of
https://gitlab.com/vindarel/ciel.git
synced 2025-12-06 02:30:39 -08:00
REPL " ?" trick works with nested expressions
This commit is contained in:
parent
1eb751e9d2
commit
e472084ed6
3 changed files with 26 additions and 6 deletions
24
utils.lisp
Normal file
24
utils.lisp
Normal 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 ?"))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue