From d9bd7c90250b7563be98f105d0a53ce66d559ea0 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 4 Aug 2019 19:04:10 +0100 Subject: [PATCH] frontend.lisp: Add hooks for extensions to add new command-line options. It seems rather pointless to document the option parser and then fail to provide any way for extensions to make use of it. Not that I've actually documented it yet... --- doc/SYMBOLS | 1 + doc/misc.tex | 5 ++++- src/frontend.lisp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/doc/SYMBOLS b/doc/SYMBOLS index 40aa3f5..26d1a70 100644 --- a/doc/SYMBOLS +++ b/doc/SYMBOLS @@ -1611,6 +1611,7 @@ vtmsgs-subclass Package `sod-frontend' frontend.lisp + augment-options function main function Classes: diff --git a/doc/misc.tex b/doc/misc.tex index b1ade39..ec0fe59 100644 --- a/doc/misc.tex +++ b/doc/misc.tex @@ -862,7 +862,7 @@ The following definitions are useful when working with conditions. %%%-------------------------------------------------------------------------- \section{Option parser} \label{sec:misc.optparse} -These symbols are defined in the @|optparse| package. +Most of these symbols are defined in the @|optparse| package. \begin{describe}{fun}{exit \&optional (@ 0) \&key :abrupt} \end{describe} @@ -1066,6 +1066,9 @@ These symbols are defined in the @|optparse| package. @
^*) @}^*} \end{describe} +\begin{describe}{fun}{augment-options @} +\end{describe} + %%%-------------------------------------------------------------------------- \section{Property sets} \label{sec:misc.pset} diff --git a/src/frontend.lisp b/src/frontend.lisp index 06311a3..2d20fbc 100644 --- a/src/frontend.lisp +++ b/src/frontend.lisp @@ -77,6 +77,15 @@ (defun update-usage () (setf *usage* (simple-usage *options* "SOURCES..."))) +(export 'augment-options) +(defun augment-options (options) + "Add OPTIONS to the program's options list." + (asetf *options* (append it options)) + (setf (op-options *option-parser*) *options*) + (update-usage)) + +(use-package "SOD-FRONTEND" "SOD-USER") + (export 'main) (defun main () @@ -110,6 +119,32 @@ (#\d "directory" (:arg "DIR") ("Write output files to DIR.") (dirpath output-path)) + (#\e "eval" (:arg "LISP") + ("Evaluate raw Lisp code.") + (lambda (lisp) + (handler-case + (let ((*package* (find-package "SOD-USER"))) + (eval (read-from-string lisp))) + (error (error) + (option-parse-error "~A" error))))) + (#\l "load" (:arg "FILE") + ("Load a file of Lisp code.") + (lambda (file) + (let ((file (merge-pathnames file + (make-pathname + :type "LISP" + :case :common)))) + (handler-case + (let ((*package* (find-package "SOD-USER"))) + (find-file *default-pathname-defaults* file + "Lisp file" + (lambda (path true) + (declare (ignore path)) + (load true + :verbose nil + :print nil)))) + (error (error) + (option-parse-error "~A" error)))))) (#\p "stdout" ("Write output files to standard output.") (set stdoutp)) -- 2.11.0