7. Scribe Programming Manual -- Programming Back-ends

7. Scribe Programming Manual -- Programming Back-ends

Browsing

Home: Scribe Programming Manual

Previous chapter: Target format
Next chapter: The HTML back end

Programming Back-ends

7.1 Implementing a back-end
7.2 Registering a back-end

Chapters

1. Defining new functions
2. Fontification
3. Common Classes
4. Scribe Library
5. Container numbering
6. Target format
7. Programming Back-ends
8. The HTML back end
9. The LaTeX back end
10. The MAN back end
11. Bibliography
12. Embedding Scribe into Bigloo
13. Scribe Apache module
14. Classes, Functions and Variables
15. Bibliography

Scribe

Home page:Scribe

Documentation:user
expert
styles

A Scribe back-end is a Bigloo library that implements a code generator for a certain target format. The Scribe version 1.1b provides back-ends for the following formats:
  • HTML
  • TeX
  • Ascii
  • Man (nroff)
  • Info

This chapter explains how to implement new back-ends. It pre-supposes the capacity to implement, compile and install Bigloo libraries.

7.1 Implementing a back-end

A Scribe back-end is implemented by the means of a Bigloo function that accepts Scribe values and that write on the current output channel the target file.

A Scribe value is either

a
procedure
of zero argument
It belongs to the back-end to apply the function and re-process the result of this application.
a text
string
It belongs to the back-end to handle escape sequences. For instance, the HTML back-end intercepts the character "<" and replaces with the appropriate HTML characters sequence.
a
number
a
character
a
list
of Scribe values
The back-end must process in sequence the contained values.
an instance of the
%node
class
The back-end must dispatch over that class hierarchy in order to decide how to handle the node. For this, it is recommended to implement the back-end by the means of a generic function.
All other values should be ignored.

For the sake of the example, here is the definition of the function implementing the Man back-end.

(define-generic (man obj::obj)
   (cond
      ((and (procedure? obj) (correct-arity? obj 0))
       (man (obj)))
      ((string? obj)
       (display obj))
      ((number? obj)
       (display (number->string obj)))
      ((char? obj)
       (display obj))
      ((eq? obj #unspecified)
       obj)
      ((list? obj)
       (for-each man obj))
      ((or (symbol? obj) (boolean? obj))
       "")
      (else
       (with-access::%node obj (loc)
          (error/location "man"
                       "Can't find method for node"
                       (find-runtime-type obj)
                       (car loc)
                       (cdr loc))))))

And here is the implementation of the generic function man for the instances of class %pre:

(define-method (man obj::%pre)
   (newline)
   (print ".Sp\n.nf")
   (man (%pre-body obj))
   (newline)
   (print ".Sp\n.fi"))

7.2 Registering a back-end

Once implemented a Bigloo function implementing a back-end must registered in order to enable Scribe to use it.
(register-backend! ::symbol ::procedure)Scribe function
Registers the procedure under the name symbol. That is, when Scribe is to compile a Scribe source file for a target format, it searches a back-end has been recorded under the name of the format. For instance, to register the man back-end, the implementation of the Bigloo library, contains the following top-level call:

(register-backend! 'man man)


This page has been generated by Scribe.
Last update Wed Dec 18 09:23:03 2002