More
author |
Steve Losh <steve@stevelosh.com> |
date |
Fri, 16 Feb 2024 14:12:21 -0500 |
parents |
91fbe5a6b164 |
children |
(none) |
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload
'(:adopt :losh :parenscript)
:silent t))
(defpackage :parens
(:use :cl :iterate :losh)
(:export :toplevel :*ui*))
(defpackage :parenscript-user
(:use :cl :parenscript))
(in-package :parens)
;;;; Run ----------------------------------------------------------------------
(defun compile-with-parenscript (in-stream out-stream)
(let ((parenscript:*parenscript-stream* out-stream))
(ps:ps-compile-stream in-stream)))
(defun run ()
(compile-with-parenscript *standard-input* *standard-output*))
;;;; User Interface -----------------------------------------------------------
(defparameter *option-help*
(adopt:make-option 'help
:help "Display help and exit."
:long "help"
:short #\h
:reduce (constantly t)))
(adopt:define-string *help-text*
"parens is a helper program to invoke the parenscript compiler for standalone ~
files, so you can just use parenscript without the Common Lisp bits.")
(defparameter *examples*
'(("Compile:" . "cat foo.lisp | parens > out.js")))
(defparameter *ui*
(adopt:make-interface
:name "parens"
:usage "[OPTIONS]"
:summary "standalone parenscript compiler"
:help *help-text*
:examples *examples*
:contents (list *option-help*)))
(defun toplevel ()
(multiple-value-bind (arguments options) (adopt:parse-options-or-exit *ui*)
(handler-case
(if (gethash 'help options)
(adopt:print-help-and-exit *ui*)
(progn (assert (null arguments))
(run)))
(error (e) (adopt:print-error-and-exit e)))))