From 7dce8a1e0927554c05196467d0d81c9a06f596ab Mon Sep 17 00:00:00 2001 From: Jeronimo Pellegrini Date: Sun, 29 Sep 2024 10:34:17 -0300 Subject: [PATCH 1/2] Add configurable char flushing at REPL end of lines When a line is intered int the REPL, STklos will flush the characters in the list contained in the parameter obejct `repl-flushed-characters`. The default value is `(#\space #\tab)`. Newlines and end-of-file are always flushed. ``` stklos> (read-char) <= no character after the closing parenthesis 4 <= user input #\4 <= return value stklos> (read-char) <= a space after the closing parenthesis 4 <= user input #\4 <= return value stklos> (read-char)3 <= '3' after closing parenthesis #\3 <= return value stklos> (read-char) 3 <= space and '3' after closing parenthesis #\3 <= return value stklos> (read-char)35 <= '35' after closing parenthesis #\3 <= return value 5 <= next return value (repl-flushed-characters '()) stklos> (read-char) <= no character after the closing parenthesis 4 <= user input #\4 <= return value stklos> (read-char) <= a space after the closing parenthesis #\space <= return value (the space was not skipped) stklos> (read-char)3 <= '3' after closing parenthesis #\3 <= return value stklos> (read-char) 3 <= space and '3' after closing parenthesis #\space <= return value (the space was not skipped) #\3 <= next return value stklos> (read-char)35 <= '35' after closing parenthesis #\3 <= return value 5 <= next return value ``` --- lib/repl.stk | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/lib/repl.stk b/lib/repl.stk index 8296c9f2..752d747e 100644 --- a/lib/repl.stk +++ b/lib/repl.stk @@ -34,6 +34,7 @@ (export main-repl repl repl-prompt repl-make-prompt repl-display-prompt repl-prompt-use-color? repl-change-default-ports main-repl-hook repl-theme get-repl-color repl-show-startup-message + repl-flushed-characters repl-add-command @ @1 @2 @3 @4 @5 @*) @@ -48,6 +49,50 @@ (define default-out (current-output-port)) (define default-err (current-error-port)) +#| + (read-char) <= no character after the closing parenthesis + * 4 <= user input + * #\4 <= return value + * stklos> (read-char) <= a space after the closing parenthesis + * 4 <= user input + * #\4 <= return value + * stklos> (read-char)3 <= '3' after closing parenthesis + * #\3 <= return value + * stklos> (read-char) 3 <= space and '3' after closing parenthesis + * #\3 <= return value + * stklos> (read-char)35 <= '35' after closing parenthesis + * #\3 <= return value + * 5 <= next return value + * + * (repl-flushed-characters '()) + * stklos> (read-char) <= no character after the closing parenthesis + * 4 <= user input + * #\4 <= return value + * stklos> (read-char) <= a space after the closing parenthesis + * #\space <= return value (the space was not skipped) + * stklos> (read-char)3 <= '3' after closing parenthesis + * #\3 <= return value + * stklos> (read-char) 3 <= space and '3' after closing parenthesis + * #\space <= return value (the space was not skipped) + * #\3 <= next return value + * stklos> (read-char)35 <= '35' after closing parenthesis + * #\3 <= return value + * 5 <= next return value + * @end lisp +doc> +|# +(define repl-flushed-characters (make-parameter '(#\space #\tab))) + (define @1 #void) (define @2 #void) (define @3 #void) @@ -488,6 +533,20 @@ doc> (system (substring all 1 (string-length all))))) (else + ;; Flush spaces, tabs and newlines (by default), or + ;; whatever is contained in the list stored in the + ;; parameter repl-flushed-characters. If we type + ;; (read-char) in the REPL, we'll be able to enter a + ;; character. If we enter (read-char)3456, the + ;; character #\3 will be read, and '456' will be + ;; considered the next token. + (let loop ((c (peek-char in))) + (if (memq c '(#\newline #eof)) + (read-char in) + (when (memq c (repl-flushed-characters)) + (read-char in) + (loop (peek-char in))))) + (call-with-values (lambda () (eval e)) (lambda v From 2b48372de19b95af7170737dfe093f528f7c005b Mon Sep 17 00:00:00 2001 From: Jeronimo Pellegrini Date: Sun, 29 Sep 2024 10:42:58 -0300 Subject: [PATCH 2/2] Document repl-flushed-characters --- doc/refman/custom.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/refman/custom.adoc b/doc/refman/custom.adoc index 29577cb7..9737816d 100644 --- a/doc/refman/custom.adoc +++ b/doc/refman/custom.adoc @@ -129,3 +129,4 @@ The following parameter objects can be used to customize the REPL: {{insertdoc 'repl-theme}} {{insertdoc 'repl-show-startup-message}} +{{insertdoc 'repl-flushed-characters}}