From 77f1210c86000ca8f2aa40cb148820d3e0eb3ca8 Mon Sep 17 00:00:00 2001 From: Ludovic Court`es Date: Mon, 23 Jan 2006 10:32:29 +0000 Subject: Preliminary support for multiple reader front-ends. * src/guile/skribilo.scm: Use `(skribilo reader)'. (skribilo-options): Added `--reader'. (skribilo): Read `--reader', parameterize `*document-reader*'. * src/guile/skribilo/evaluator.scm (evaluate-document-from-port): Have READER default to `*document-reader*'. (include-document): Likewise. * src/guile/skribilo/reader.scm: Load SRFIs 34, 35, and 39, as well as `(skribilo condition)'. Export `*document-reader*'. (&reader-search-error): New. (lookup-reader): Raise a `&reader-search-error' condition if NAME is not found. (*document-reader*): New. git-archimport-id: lcourtes@laas.fr--2004-libre/skribilo--devel--1.2--patch-32 --- src/guile/skribilo.scm | 10 +++++++++- src/guile/skribilo/evaluator.scm | 7 +++---- src/guile/skribilo/reader.scm | 30 ++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/guile/skribilo.scm b/src/guile/skribilo.scm index 43885ee..285a92d 100644 --- a/src/guile/skribilo.scm +++ b/src/guile/skribilo.scm @@ -38,6 +38,7 @@ exec ${GUILE-guile} --debug -l $0 -c "(apply $main (cdr (command-line)))" "$@" (define-module (skribilo) :autoload (skribilo module) (make-run-time-module) :autoload (skribilo engine) (*current-engine*) + :autoload (skribilo reader) (*document-reader*) :use-module (skribilo utils syntax)) (use-modules (skribilo evaluator) @@ -80,6 +81,8 @@ specifications." `(define ,binding (quote ,(raw-options->getopt-long options)))) (define-options skribilo-options + (("reader" :alternate "R" :arg reader + (nothing))) (("target" :alternate "t" :arg target :help "sets the output format to ") (set! engine (string->symbol target))) @@ -194,6 +197,8 @@ specifications." Processes a Skribilo/Skribe source file and produces its output. + --reader=READER Use READER to parse the input file (by default, + the `skribe' reader is used) --target=ENGINE Use ENGINE as the underlying engine --help Give this help list @@ -381,6 +386,8 @@ Processes a Skribilo/Skribe source file and produces its output. (define-public (skribilo . args) (let* ((options (getopt-long (cons "skribilo" args) skribilo-options)) + (reader-name (string->symbol + (option-ref options 'reader "skribe"))) (engine (string->symbol (option-ref options 'target "html"))) (output-file (option-ref options 'output #f)) @@ -412,7 +419,8 @@ Processes a Skribilo/Skribe source file and produces its output. (lambda (file) (format #t "~~ loading `~a'...~%" file)))) - (parameterize ((*current-engine* engine) + (parameterize ((*document-reader* (make-reader reader-name)) + (*current-engine* engine) (*document-path* (cons load-path (*document-path*))) (*bib-path* (cons bib-path (*bib-path*))) (*source-path* (cons source-path diff --git a/src/guile/skribilo/evaluator.scm b/src/guile/skribilo/evaluator.scm index 002ca54..df5e6a7 100644 --- a/src/guile/skribilo/evaluator.scm +++ b/src/guile/skribilo/evaluator.scm @@ -27,7 +27,7 @@ :autoload (skribilo location) () :autoload (skribilo ast) (ast? markup?) :autoload (skribilo engine) (engine? find-engine engine-ident) - :autoload (skribilo reader) (%default-reader) + :autoload (skribilo reader) (*document-reader*) :autoload (skribilo verify) (verify) :autoload (skribilo resolve) (resolve!)) @@ -91,7 +91,7 @@ ;;; (define* (evaluate-document-from-port port engine :key (env '()) - (reader %default-reader)) + (reader (*document-reader*))) (with-debug 2 'evaluate-document-from-port (debug-item "engine=" engine) (debug-item "reader=" reader) @@ -173,8 +173,7 @@ ;;; INCLUDE-DOCUMENT ;;; (define* (include-document file :key (path (*document-path*)) - (reader %default-reader)) - ;; FIXME: We should default to `*skribilo-current-reader*'. + (reader (*document-reader*))) (unless (every string? path) (raise (condition (&invalid-argument-error (proc-name 'include-document) (argument path))))) diff --git a/src/guile/skribilo/reader.scm b/src/guile/skribilo/reader.scm index 27c740b..95e545b 100644 --- a/src/guile/skribilo/reader.scm +++ b/src/guile/skribilo/reader.scm @@ -21,8 +21,15 @@ (define-module (skribilo reader) :use-module (srfi srfi-9) ;; records :use-module (srfi srfi-17) ;; generalized `set!' + :use-module (srfi srfi-39) ;; parameter objects + :use-module (skribilo condition) + :autoload (srfi srfi-34) (raise) + :use-module (srfi srfi-35) :export (%make-reader lookup-reader make-reader - %default-reader) + %default-reader *document-reader* + + &reader-search-error reader-search-error? + reader-search-error:reader) :export-syntax (define-reader define-public-reader)) ;;; Author: Ludovic Courtès @@ -60,6 +67,13 @@ (define-macro (define-public-reader name version make-proc) `(define-reader ,name ,version ,make-proc)) + +;;; Error condition. + +(define-condition-type &reader-search-error &skribilo-error + reader-search-error? + (reader reader-search-error:reader)) + ;;; The mechanism below is inspired by Guile-VM code written by K. Nishida. @@ -68,10 +82,12 @@ "Look for a reader named @var{name} (a symbol) in the @code{(skribilo reader)} module hierarchy. If no such reader was found, an error is raised." - (let ((m (resolve-module `(skribilo reader ,name)))) - (if (module-bound? m 'reader-specification) + (let ((m (false-if-exception + (resolve-module `(skribilo reader ,name))))) + (if (and (module? m) + (module-bound? m 'reader-specification)) (module-ref m 'reader-specification) - (error "no such reader" name)))) + (raise (condition (&reader-search-error (reader name))))))) (define (make-reader name) "Look for reader @var{name} and instantiate it." @@ -81,4 +97,10 @@ raised." (define %default-reader (make-reader 'skribe)) + +;;; Current document reader. + +(define *document-reader* (make-parameter %default-reader)) + + ;;; reader.scm ends here -- cgit v1.2.3