From b643ac23559f1457daec825cb8a2c01e682387f8 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Sun, 13 Nov 2022 22:57:15 -0600 Subject: [PATCH] compat: New 'read-line' shim. * gash/compat/rdelim.scm: New file. * Makefile.am (SOURCES): Add it. * gash/built-ins/read.scm: Use it. * gash/lexer.scm: Likewise. * gash/readline.scm: Likewise. * gash/repl.scm: Likewise. --- Makefile.am | 1 + gash/built-ins/read.scm | 2 +- gash/compat/rdelim.scm | 50 +++++++++++++++++++++++++++++++++++++++++ gash/lexer.scm | 2 +- gash/readline.scm | 2 +- gash/repl.scm | 1 - 6 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 gash/compat/rdelim.scm diff --git a/Makefile.am b/Makefile.am index c4deefa..9534e74 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,6 +63,7 @@ SOURCES = \ gash/built-ins/wait.scm \ gash/built-ins.scm \ gash/compat/hash-table.scm \ + gash/compat/rdelim.scm \ gash/compat/srfi-43.scm \ gash/compat/textual-ports.scm \ gash/compat.scm \ diff --git a/gash/built-ins/read.scm b/gash/built-ins/read.scm index b8a3047..5e916ac 100644 --- a/gash/built-ins/read.scm +++ b/gash/built-ins/read.scm @@ -18,10 +18,10 @@ (define-module (gash built-ins read) #:use-module (gash compat) + #:use-module (gash compat rdelim) #:use-module (gash compat textual-ports) #:use-module (gash environment) #:use-module (ice-9 match) - #:use-module (ice-9 rdelim) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26)) diff --git a/gash/compat/rdelim.scm b/gash/compat/rdelim.scm new file mode 100644 index 0000000..d99f027 --- /dev/null +++ b/gash/compat/rdelim.scm @@ -0,0 +1,50 @@ +;;; Gash -- Guile As SHell +;;; Copyright © 2022 Timothy Sample +;;; +;;; This file is part of Gash. +;;; +;;; Gash is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Gash is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Gash. If not, see . + +(define-module (gash compat rdelim) + #:use-module (gash compat textual-ports)) + +;;; Commentary +;;; +;;; This module provides a shim for 'read-line' on Mes. We need this to +;;; make sure that 'read-line' is aware of our soft port shim. +;;; +;;; Code: + +(cond-expand + (guile + (use-modules (ice-9 rdelim)) + (re-export read-line)) + (mes + (export read-line) + (define* (read-line #:optional (port (current-input-port)) + (handle-delim 'trim)) + (let loop ((acc '())) + (define c (get-char port)) + (cond + ((eof-object? c) + (if (null? acc) c (list->string (reverse! acc)))) + ((eq? c #\newline) + (case handle-delim + ((trim) (list->string (reverse! acc))) + ((concat) (list->string (reverse! (cons c acc)))) + ((peek) (begin (unget-char port c) (list->string (reverse! acc)))) + ((split) (cons (list->string (reverse! acc)) c)) + (else (error "read-line: Invalid handle-delim" handle-delim)))) + (else + (loop (cons c acc)))))))) diff --git a/gash/lexer.scm b/gash/lexer.scm index 7e0e1e1..cf17113 100644 --- a/gash/lexer.scm +++ b/gash/lexer.scm @@ -18,9 +18,9 @@ (define-module (gash lexer) #:use-module (gash compat) + #:use-module (gash compat rdelim) #:use-module (gash compat textual-ports) #:use-module (ice-9 match) - #:use-module (ice-9 rdelim) #:use-module (ice-9 receive) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) diff --git a/gash/readline.scm b/gash/readline.scm index df6aecc..c56ee74 100644 --- a/gash/readline.scm +++ b/gash/readline.scm @@ -24,7 +24,7 @@ ;;; Code: (define-module (gash readline) - #:use-module (ice-9 rdelim) + #:use-module (gash compat rdelim) #:export (add-history clear-history read-history diff --git a/gash/repl.scm b/gash/repl.scm index f7b550c..648e116 100644 --- a/gash/repl.scm +++ b/gash/repl.scm @@ -21,7 +21,6 @@ #:use-module (gash eval) #:use-module (gash parser) #:use-module (ice-9 match) - #:use-module (ice-9 rdelim) #:export (run-repl)) ;;; Commentary: