Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable char flushing at REPL end of lines #693

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/refman/custom.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
59 changes: 59 additions & 0 deletions lib/repl.stk
Original file line number Diff line number Diff line change
Expand Up @@ -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 @*)

Expand All @@ -48,6 +49,50 @@
(define default-out (current-output-port))
(define default-err (current-error-port))

#|
<doc EXT repl-flushed-characters
* (repl-flushed-characters)
* (repl-flushed-characters lst)
*
* 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.
*
* @lisp
* 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
* @end lisp
doc>
|#
(define repl-flushed-characters (make-parameter '(#\space #\tab)))

(define @1 #void)
(define @2 #void)
(define @3 #void)
Expand Down Expand Up @@ -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
Expand Down