rdelim.scm 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ;;; Guile delimited read/write
  2. ;;; Copyright (C) 2024 David Thompson <dave@spritely.institute>
  3. ;;;
  4. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  5. ;;; you may not use this file except in compliance with the License.
  6. ;;; You may obtain a copy of the License at
  7. ;;;
  8. ;;; http://www.apache.org/licenses/LICENSE-2.0
  9. ;;;
  10. ;;; Unless required by applicable law or agreed to in writing, software
  11. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  12. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ;;; See the License for the specific language governing permissions and
  14. ;;; limitations under the License.
  15. ;;; Commentary:
  16. ;;;
  17. ;;; Guile delimited read/write module.
  18. ;;;
  19. ;;; Code:
  20. (define-module (ice-9 rdelim)
  21. #:use-module (hoot errors)
  22. #:export (read-line
  23. read-line!
  24. read-delimited
  25. read-delimited!
  26. read-string
  27. read-string!
  28. %read-delimited!
  29. %read-line
  30. write-line))
  31. (define* (%read-line #:optional (port (current-input-port)))
  32. "Read a newline-terminated line from @var{port}, allocating storage as
  33. necessary. The newline terminator (if any) is removed from the
  34. string, and a pair consisting of the line and its delimiter is
  35. returned. The delimiter may be either a newline or the
  36. @var{eof-object}. If @code{%read-line} is called at the end of file,
  37. it returns the pair @code{(#<eof> . #<eof>)}."
  38. (raise (make-unimplemented-error '%read-line)))
  39. (define* (read-line #:optional (port (current-input-port)) (handle-delim 'trim))
  40. (raise (make-unimplemented-error 'read-line)))
  41. (define* (read-line! str #:optional (port (current-input-port)))
  42. (raise (make-unimplemented-error 'read-line!)))
  43. (define* (%read-delimited! delims str gobble #:optional
  44. (port (current-input-port))
  45. start end)
  46. (raise (make-unimplemented-error '%read-delimited!)))
  47. (define* (read-delimited delims #:optional (port (current-input-port))
  48. (handle-delim 'trim))
  49. (raise (make-unimplemented-error 'read-delimited)))
  50. (define* (read-delimited! delims buf #:optional
  51. (port (current-input-port)) (handle-delim 'trim)
  52. (start 0) (end (string-length buf)))
  53. (raise (make-unimplemented-error 'read-delimited!)))
  54. (define* (read-string . args)
  55. (raise (make-unimplemented-error 'read-string)))
  56. (define* (read-string! buf #:optional
  57. (port (current-input-port))
  58. (start 0) (end (string-length buf)))
  59. (raise (make-unimplemented-error 'read-string!)))
  60. (define* (write-line obj #:optional (port (current-output-port)))
  61. "Display @var{obj} and a newline character to @var{port}. If
  62. @var{port} is not specified, @code{(current-output-port)} is used."
  63. (display obj port)
  64. (newline port))