diff options
| author | Jakob L. Kreuze | 2023-04-27 18:08:29 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze | 2023-04-27 18:08:29 -0400 |
| commit | 5865808cf7cb918c8b2b08dc04dca25997b6eee5 (patch) | |
| tree | e87c78fe07f646b534a865ca7321abbe904b585d | |
| parent | f9a5fed54e0a2ac71e11e5dbfac9bc791dcf7fc1 (diff) | |
Refactor read-and-parse.scm
| -rw-r--r-- | compiler/main.scm | 1 | ||||
| -rw-r--r-- | compiler/passes/read-and-parse.scm | 11 |
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/main.scm b/compiler/main.scm index 97e4638..44d7ac5 100644 --- a/compiler/main.scm +++ b/compiler/main.scm @@ -24,7 +24,6 @@ #:use-module (compiler passes preprocess-policy) #:use-module (compiler passes read-and-parse) #:use-module (compiler utilities) - #:use-module (ice-9 pretty-print) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:export (main)) diff --git a/compiler/passes/read-and-parse.scm b/compiler/passes/read-and-parse.scm index ec36c74..2f2c8c2 100644 --- a/compiler/passes/read-and-parse.scm +++ b/compiler/passes/read-and-parse.scm @@ -23,10 +23,11 @@ #:export (read-and-parse)) (define (call-command-with-output-error-to-string cmd) - "Invoke `cmd', recording what it writes to `stdout' and `stderr' + "Invoke CMD, recording what it writes to `stdout' and `stderr' -Multi-valued return. The first value is a string containing the content of -`stdout', and the second value is a string containing the content of `stderr'." +Multi-valued return. The first value is a string or `eof-object?' +containing the content of `stdout', and the second value is a string or +`eof-object?' containing the content of `stderr'." (let* ((err-cons (pipe)) (port (with-error-to-port (cdr err-cons) (λ() (open-input-pipe cmd)))) @@ -39,12 +40,14 @@ Multi-valued return. The first value is a string containing the content of (read-delimited "" (car err-cons))))) (define (read-and-parse file-name) - "Pass to read the contents of `file-name' and output an AST" + "Pass to read the contents of FILE-NAME and output a syntax tree" (define-values (stdout stderr) (call-command-with-output-error-to-string (string-concatenate (list "opa parse -f json " file-name)))) ;; Fail if anything was written to stdout. + (unless (eof-object? stderr) + (display stderr)) (assert (eof-object? stderr)) (json-string->scm stdout)) |