aboutsummaryrefslogtreecommitdiff
path: root/src/guile/skribilo/evaluator.scm
diff options
context:
space:
mode:
Diffstat (limited to 'src/guile/skribilo/evaluator.scm')
-rw-r--r--src/guile/skribilo/evaluator.scm124
1 files changed, 70 insertions, 54 deletions
diff --git a/src/guile/skribilo/evaluator.scm b/src/guile/skribilo/evaluator.scm
index c1b378d..002ca54 100644
--- a/src/guile/skribilo/evaluator.scm
+++ b/src/guile/skribilo/evaluator.scm
@@ -1,7 +1,7 @@
;;; eval.scm -- Skribilo evaluator.
;;;
;;; Copyright 2003-2004 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
-;;; Copyright 2005 Ludovic Courtès <ludovic.courtes@laas.fr>
+;;; Copyright 2005,2006 Ludovic Courtès <ludovic.courtes@laas.fr>
;;;
;;;
;;; This program is free software; you can redistribute it and/or modify
@@ -21,8 +21,8 @@
(define-module (skribilo evaluator)
- :export (skribe-eval skribe-eval-port skribe-load skribe-load-options
- skribe-include)
+ :export (evaluate-document evaluate-document-from-port
+ load-document include-document *load-options*)
:autoload (skribilo parameters) (*verbose* *document-path*)
:autoload (skribilo location) (<location>)
:autoload (skribilo ast) (ast? markup?)
@@ -34,26 +34,30 @@
(use-modules (skribilo utils syntax)
+ (skribilo condition)
(skribilo debug)
(skribilo output)
(skribilo lib)
(ice-9 optargs)
(oop goops)
+ (srfi srfi-1)
(srfi srfi-13)
- (srfi srfi-1))
+ (srfi srfi-34)
+ (srfi srfi-35)
+ (srfi srfi-39))
(fluid-set! current-reader %skribilo-module-reader)
-(define *skribe-loaded* '()) ;; List of already loaded files
-(define *skribe-load-options* '())
-
;;;
;;; %EVALUATE
;;;
(define (%evaluate expr)
+ ;; Evaluate EXPR, an arbitrary S-expression that may contain calls to the
+ ;; markup functions defined in `(skribilo skribe api)', e.g., `(bold
+ ;; "hello")'.
(let ((result (eval expr (current-module))))
(if (ast? result)
@@ -68,12 +72,13 @@
-
;;;
-;;; SKRIBE-EVAL
+;;; EVALUATE-DOCUMENT
;;;
-(define* (skribe-eval a e :key (env '()))
- (with-debug 2 'skribe-eval
+(define* (evaluate-document a e :key (env '()))
+ ;; Argument A must denote an AST of something like that, not just an
+ ;; S-exp.
+ (with-debug 2 'evaluate-document
(debug-item "a=" a " e=" (engine-ident e))
(let ((a2 (resolve! a e env)))
(debug-item "resolved a=" a)
@@ -82,36 +87,38 @@
(output a3 e)))))
;;;
-;;; SKRIBE-EVAL-PORT
+;;; EVALUATE-DOCUMENT-FROM-PORT
;;;
-(define* (skribe-eval-port port engine :key (env '())
- (reader %default-reader))
- (with-debug 2 'skribe-eval-port
+(define* (evaluate-document-from-port port engine
+ :key (env '())
+ (reader %default-reader))
+ (with-debug 2 'evaluate-document-from-port
(debug-item "engine=" engine)
(debug-item "reader=" reader)
(let ((e (if (symbol? engine) (find-engine engine) engine)))
(debug-item "e=" e)
(if (not (engine? e))
- (skribe-error 'skribe-eval-port "cannot find engine" engine)
+ (skribe-error 'evaluate-document-from-port "cannot find engine" engine)
(let loop ((exp (reader port)))
- (with-debug 10 'skribe-eval-port
+ (with-debug 10 'evaluate-document-from-port
(debug-item "exp=" exp))
(unless (eof-object? exp)
- (skribe-eval (%evaluate exp) e :env env)
+ (evaluate-document (%evaluate exp) e :env env)
(loop (reader port))))))))
+
;;;
-;;; SKRIBE-LOAD
+;;; LOAD-DOCUMENT
;;;
-;;; FIXME: Use a fluid for that.
-(define *skribe-load-options* '())
+;; Options that may make sense to a specific back-end or package.
+(define-public *load-options* (make-parameter '()))
-(define (skribe-load-options)
- *skribe-load-options*)
+;; List of the names of files already loaded.
+(define *loaded-files* (make-parameter '()))
-(define* (skribe-load file :key (engine #f) (path #f) :rest opt)
+(define* (load-document file :key (engine #f) (path #f) :rest opt)
(with-debug 4 'skribe-load
(debug-item " engine=" engine)
(debug-item " path=" path)
@@ -122,7 +129,9 @@
((not path) (*document-path*))
((string? path) (list path))
((not (and (list? path) (every? string? path)))
- (skribe-error 'skribe-load "illegal path" path))
+ (raise (condition (&invalid-argument-error
+ (proc-name 'load-document)
+ (argument path)))))
(else path))
%load-path))
(filep (or (search-path path file)
@@ -135,44 +144,51 @@
".scm")
file))))))
- (set! *skribe-load-options* opt)
-
(unless (and (string? filep) (file-exists? filep))
- (skribe-error 'skribe-load
- (string-append "cannot find `" file "' in path")
- path))
-
- ;; Load this file if not already done
- (unless (member filep *skribe-loaded*)
- (cond
- ((> (*verbose*) 1)
- (format (current-error-port) " [loading file: ~S ~S]\n" filep opt))
- ((> (*verbose*) 0)
- (format (current-error-port) " [loading file: ~S]\n" filep)))
- ;; Load it
- (with-input-from-file filep
- (lambda ()
- (skribe-eval-port (current-input-port) ei)))
- (set! *skribe-loaded* (cons filep *skribe-loaded*))))))
+ (raise (condition (&file-search-error
+ (file-name file)
+ (path path)))))
+
+ ;; Pass the additional options to the back-end and/or packages being
+ ;; used.
+ (parameterize ((*load-options* opt))
+
+ ;; Load this file if not already done
+ ;; FIXME: Shouldn't we remove this logic? -- Ludo'.
+ (unless (member filep (*loaded-files*))
+ (cond
+ ((> (*verbose*) 1)
+ (format (current-error-port) " [loading file: ~S ~S]\n" filep opt))
+ ((> (*verbose*) 0)
+ (format (current-error-port) " [loading file: ~S]\n" filep)))
+
+ ;; Load it
+ (with-input-from-file filep
+ (lambda ()
+ (evaluate-document-from-port (current-input-port) ei)))
+
+ (*loaded-files* (cons filep (*loaded-files*))))))))
;;;
-;;; SKRIBE-INCLUDE
+;;; INCLUDE-DOCUMENT
;;;
-(define* (skribe-include file :key (path (*document-path*))
- (reader %default-reader))
+(define* (include-document file :key (path (*document-path*))
+ (reader %default-reader))
;; FIXME: We should default to `*skribilo-current-reader*'.
(unless (every string? path)
- (skribe-error 'skribe-include "illegal path" path))
+ (raise (condition (&invalid-argument-error (proc-name 'include-document)
+ (argument path)))))
+
+ (let ((full-path (search-path path file)))
+ (unless (and (string? full-path) (file-exists? full-path))
+ (raise (condition (&file-search-error
+ (file-name file)
+ (path path)))))
- (let ((path (search-path path file)))
- (unless (and (string? path) (file-exists? path))
- (skribe-error 'skribe-load
- (format #t "cannot find ~S in path" file)
- path))
(when (> (*verbose*) 0)
- (format (current-error-port) " [including file: ~S]\n" path))
+ (format (current-error-port) " [including file: ~S]\n" full-path))
- (with-input-from-file path
+ (with-input-from-file full-path
(lambda ()
(let Loop ((exp (reader (current-input-port)))
(res '()))