diff options
Diffstat (limited to 'rego-proofs/compiler/passes/read-and-parse.scm')
| -rw-r--r-- | rego-proofs/compiler/passes/read-and-parse.scm | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/rego-proofs/compiler/passes/read-and-parse.scm b/rego-proofs/compiler/passes/read-and-parse.scm deleted file mode 100644 index e25a7f5..0000000 --- a/rego-proofs/compiler/passes/read-and-parse.scm +++ /dev/null @@ -1,65 +0,0 @@ -;;; Copyright © 2023 Jakob L. Kreuze <zerodaysfordays@sdf.org> -;;; -;;; This program 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. -;;; -;;; This program 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 this program. If not, see -;;; <http://www.gnu.org/licenses/>. - -(define-module (compiler passes read-and-parse) - #:use-module (ice-9 popen) - #:use-module (ice-9 rdelim) - #:use-module (json) - #:use-module (rnrs base) - #:use-module (rnrs io ports) - #:export (read-and-parse - read-and-parse-string)) - -(define (call-command-with-output-error-to-string cmd) - "Invoke CMD, recording what it writes to `stdout' and `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)))) - (_ (setvbuf (car err-cons) 'block - (* 1024 1024 16))) - (result (read-delimited "" port))) - (close-port (cdr err-cons)) - (values - result - (read-delimited "" (car err-cons))))) - -(define (read-and-parse file-name) - "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)) - -(define (read-and-parse-string code) - "Pass to read the contents of FILE-NAME and output a syntax tree" - (define quoted (with-output-to-string (lambda () (write code)))) - (define-values (stdout stderr) - (call-command-with-output-error-to-string - (string-concatenate (list "echo -ne " quoted " | opa parse -f json /dev/stdin")))) - (unless (eof-object? stderr) - (display stderr)) - (assert (eof-object? stderr)) - (json-string->scm stdout)) |