lisp/parens.lisp @ 4f28fbfd7d63

More
author Steve Losh <steve@stevelosh.com>
date Tue, 09 Apr 2024 09:20:04 -0400
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)))))