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

Implementing a back-end
Registering a back-end


Chapters

Defining new functions
Fontification
Common Classes
Scribe Library
Container numbering
Target format
Programming Back-ends
The HTML back end
Bibliography
Embedding Scribe into Bigloo
Scribe Apache module
Classes, Functions and Variables
Bibliography


Scribe

Home page:Scribe

Documentation:user
expert


A Scribe back-end is a Bigloo library that implements a code generator for a certain target format. The Scribe version 0.7 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
      ((procedure? obj)
       (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 %it:

(define-method (man obj::%it)
   (display "\\fI")
   (man (%it-body obj))
   (display "\\fR"))


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
Scribe page is generated by scribeinfo.
Last update Sun Feb 17 12:09:41 2002