1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
;;; reader.scm -- Skribilo's front-end (aka. reader) interface.
;;; -*- coding: iso-8859-1 -*-
;;;
;;; Copyright 2005, 2009 Ludovic Court�s <ludo@gnu.org>
;;;
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;;; USA.
(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
*document-reader*
&reader-search-error reader-search-error?
reader-search-error:reader
define-reader define-public-reader reader?))
;;; Author: Ludovic Court�s
;;;
;;; Commentary:
;;;
;;; This module contains Skribilo's front-end (aka. ``reader'') interface.
;;; Skribilo's default reader is `(skribilo reader skribe)' which provides a
;;; reader for the Skribe syntax.
;;;
;;; Code:
(define-record-type <reader>
(%make-reader name version make)
reader?
(name reader:name reader:set-name!) ;; a symbol
(version reader:version reader:set-version!) ;; a string
(make reader:make reader:set-make!)) ;; a one-argument proc
;; that returns a reader
;; proc
(define-public reader:name
(getter-with-setter reader:name reader:set-name!))
(define-public reader:version
(getter-with-setter reader:version reader:set-version!))
(define-public reader:make
(getter-with-setter reader:make reader:set-make!))
(define-macro (define-reader name version make-proc)
`(define reader-specification
(%make-reader (quote ,name) ,version ,make-proc)))
(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.
(define (lookup-reader name)
"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 (false-if-exception
(resolve-module `(skribilo reader ,name)))))
(if (and (module? m)
(module-bound? m 'reader-specification))
(module-ref m 'reader-specification)
(raise (condition (&reader-search-error (reader name)))))))
(define (make-reader name)
"Look for reader @var{name} and instantiate it."
(let* ((spec (lookup-reader name))
(make (reader:make spec)))
(make)))
;;; Current document reader.
(define *document-reader* (make-parameter #f))
;;; reader.scm ends here
|