unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#30600: repl metacommands do not discard remaining input after syntax error in an expression
@ 2018-02-24 23:31 dikbekulo
  2021-05-18 16:19 ` Taylan Kammer
  0 siblings, 1 reply; 2+ messages in thread
From: dikbekulo @ 2018-02-24 23:31 UTC (permalink / raw)
  To: 30600

Hello!

When using meta-commands in the repl (without readline support), if 
reading an expression parameter fails, the rest of the input gets read 
in anyway. An example interaction:

--8<---------------cut here---------------start------------->8---
GNU Guile 2.2.3
Copyright (C) 1995-2017 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> ,trace "\m"
Throw to key `read-error' while reading argument `form' of command 
`trace':
In procedure scm_lreadr: #<unknown port>:1:11: illegal character in 
escape sequence: #\m
"
$1 = "\n"
scheme@(guile-user)> ,trace "\m123
Throw to key `read-error' while reading argument `form' of command 
`trace':
In procedure scm_lreadr: #<unknown port>:2:11: illegal character in 
escape sequence: #\m
$2 = 123
--8<---------------cut here---------------end--------------->8---

Since Geiser uses meta-commands with multi-line expressions to 
communicate with Guile it can get very confusing if you have syntax 
errors in your code.





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#30600: repl metacommands do not discard remaining input after syntax error in an expression
  2018-02-24 23:31 bug#30600: repl metacommands do not discard remaining input after syntax error in an expression dikbekulo
@ 2021-05-18 16:19 ` Taylan Kammer
  0 siblings, 0 replies; 2+ messages in thread
From: Taylan Kammer @ 2021-05-18 16:19 UTC (permalink / raw)
  To: 30600

[-- Attachment #1: Type: text/plain, Size: 51 bytes --]

Attached is a small patch to fix this.

-- 
Taylan

[-- Attachment #2: 0001-Better-REPL-behavior-on-syntax-errors-in-meta-comman.patch --]
[-- Type: text/plain, Size: 2868 bytes --]

From 0ba67891624647105e0dbdc33b0079cba655cec1 Mon Sep 17 00:00:00 2001
From: Taylan Kammer <taylan.kammer@gmail.com>
Date: Tue, 18 May 2021 18:15:08 +0200
Subject: [PATCH] Better REPL behavior on syntax errors in meta commands.

* module/system/repl/command.scm (define-meta-command): Flush all
remaining input after handling a read error.
* module/system/repl/common.scm (flush-all-input): New public procedure.
* module/system/repl/repl.scm: Remove local flush-all-input definition.
---
 module/system/repl/command.scm | 5 ++++-
 module/system/repl/common.scm  | 9 ++++++++-
 module/system/repl/repl.scm    | 7 -------
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/module/system/repl/command.scm b/module/system/repl/command.scm
index ac1fa0933..c0649b60b 100644
--- a/module/system/repl/command.scm
+++ b/module/system/repl/command.scm
@@ -230,7 +230,10 @@
                                  (lp (cons x out)))))))
                      (lambda (k . args)
                        (handle-read-error #f k args)))))
-           (lambda (k) #f)))))           ; the abort handler
+           ;; The abort handler:
+           (lambda (k)
+             (flush-all-input)
+             #f)))))
 
     ((_ ((name category) repl . datums) docstring b0 b1 ...)
      (define-meta-command ((name category) repl () . datums)
diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm
index 29ae104c5..51bf783e7 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -35,7 +35,7 @@
             repl-expand repl-optimize
             repl-parse repl-print repl-option-ref repl-option-set!
             repl-default-option-set! repl-default-prompt-set!
-            puts ->string user-error
+            puts ->string user-error flush-all-input
             *warranty* *copying* *version*))
 
 (define *version*
@@ -286,3 +286,10 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
 
 (define (user-error msg . args)
   (throw 'user-error #f msg args #f))
+
+(define (flush-all-input)
+  (if (and (char-ready?)
+           (not (eof-object? (peek-char))))
+      (begin
+        (read-char)
+        (flush-all-input))))
diff --git a/module/system/repl/repl.scm b/module/system/repl/repl.scm
index 5b27125f1..859ac444a 100644
--- a/module/system/repl/repl.scm
+++ b/module/system/repl/repl.scm
@@ -96,13 +96,6 @@
                  *unspecified*)
                 (else ((language-reader lang) port env))))))))
         
-(define (flush-all-input)
-  (if (and (char-ready?)
-           (not (eof-object? (peek-char))))
-      (begin
-        (read-char)
-        (flush-all-input))))
-
 ;; repl-reader is a function defined in boot-9.scm, and is replaced by
 ;; something else if readline has been activated. much of this hoopla is
 ;; to be able to re-use the existing readline machinery.
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-18 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-24 23:31 bug#30600: repl metacommands do not discard remaining input after syntax error in an expression dikbekulo
2021-05-18 16:19 ` Taylan Kammer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).