diff options
author | Arun Isaac | 2025-08-17 03:21:08 +0100 |
---|---|---|
committer | Arun Isaac | 2025-08-17 03:24:44 +0100 |
commit | d9fc9074cbf4064b855801589a03159256a49bc8 (patch) | |
tree | 3b645a633ba7ae8c429bd181355e2126779f4d0b | |
parent | a8e9c907708d4e842919b0c1c865be552a53a07b (diff) | |
download | ravanan-d9fc9074cbf4064b855801589a03159256a49bc8.tar.gz ravanan-d9fc9074cbf4064b855801589a03159256a49bc8.tar.lz ravanan-d9fc9074cbf4064b855801589a03159256a49bc8.zip |
reader: Add read-json-file.
read-json-file is a wrapper around call-with-input-file and json->scm. It raises the relevant exceptions when it fails.
-rw-r--r-- | ravanan/reader.scm | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/ravanan/reader.scm b/ravanan/reader.scm index 731ed92..8b8ac50 100644 --- a/ravanan/reader.scm +++ b/ravanan/reader.scm @@ -17,6 +17,8 @@ ;;; along with ravanan. If not, see <https://www.gnu.org/licenses/>. (define-module (ravanan reader) + #:use-module (rnrs conditions) + #:use-module (rnrs exceptions) #:use-module (rnrs io ports) #:use-module (srfi srfi-26) #:use-module (ice-9 filesystem) @@ -310,3 +312,12 @@ array of array of @code{File}s, etc. Else, return @code{#f}" val (string->number val))) (else val))) + +(define (read-json-file file) + "Read JSON @var{file} and return scheme tree." + (guard (c (else + (raise-exception + (condition (make-who-condition 'read-json-file) + c)))) + (call-with-input-file file + json->scm))) |