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.
This commit is contained in:
Timothy Sample 2022-11-13 22:57:15 -06:00
parent 469cdb60fc
commit b643ac2355
6 changed files with 54 additions and 4 deletions

View File

@ -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 \

View File

@ -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))

50
gash/compat/rdelim.scm Normal file
View File

@ -0,0 +1,50 @@
;;; Gash -- Guile As SHell
;;; Copyright © 2022 Timothy Sample <samplet@ngyro.com>
;;;
;;; 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 <http://www.gnu.org/licenses/>.
(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))))))))

View File

@ -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)

View File

@ -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

View File

@ -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: