7. Scribe User Manual -- Computer programs

7. Scribe User Manual -- Computer programs

Browsing

Home: Scribe User Manual

Previous chapter: Bibliography
Next chapter: Graphical User Interfaces

Computer programs

7.1 Prgm
7.2 From-file

Chapters

1. Getting Started
2. Syntax
3. Standard Library
4. Hyperlinks and References
5. Index
6. Bibliography
7. Computer programs
8. Graphical User Interfaces
9. Customization
10. Scribe style files
11. Editing Scribe Programs
12. Compiling Scribe programs
13. Compiling Texi documents
14. Using Bibtex databases
15. Functions and Variables

Scribe

Home page:Scribe

Documentation:user
expert
styles

It is common that some parts of a Scribe text represent other texts. For instance, for a document describing a computer programming language, it is frequent to include excerpt of programs. These embedded texts are frequently displayed in a specific font and with no justification but with a precise indentation. This indentation is important because it helps in understanding the text; it is thus desirable to preserve it in the Scribe text. The pre text layout already enables such a text formating. In this chapter we present a new Scribe function: prgm that is specially designed to represent computer programs in Scribe text.

A prgm function call preserves the indentation of the program. It may automatically introduce line numbers. It enables fontification. That is, some words of the program can be rendered using different colors or faces. This function is presented in this chapter.

7.1 Prgm

(prgm [:lnum integer] [:bg #f] [:frame #f] [:width 1.0] [:language procedure] [:colors list] . exp)Scribe function

argumentdescription
:lnumThe boolean value #f disables line numbering. An integer value enables line number. The number of the first line is the value of :lnum.
:bgThe color of the background of the computer program.
:frameEnables or disables a frame around the text of the program.
:widthThe width of the program. An integer value specifies a pixel width. A floating point value specifies a percentage of the text line width.
:languageThe name of a function implementing fontification for that text. The plain Scribe implementation comes with four predefined functions:
  • scribe that suits Scribe computer programs.
  • xml that suits XML texts.
  • bigloo that suits Scheme computer programs.
  • c that suits C computer programs.
New customized fontification functions can be defined. However, it is beyond the scope of this manual to explain how to proceed. This is documented in the Scribe Programming Manual.
:colorsA list of association representing the colors of the various tokens of the programs. Each element of the list is a list whose first elements is a symbol that is the "name" of color and the second elements a string denoting a color specification. Example:

'((type "#00ff00") (comment "#ffff00") (string "#ff0000"))

Here is a short description of the various names:
NameMeaning
commentComments
defineDefinitions
keywordKeywords
markupXML like markups
moduleModule declaration
preprocessorPre-processor directives
stringString literals
threadThread API
typeType annotations
expThe text of the computer program.

The first example uses no fontification:

(prgm :frame #t :bg "#dddddd" [
SCRIBE = scribe

all: demo.html demo.man

demo.html: demo.scr
        $(SCRIBE) demo.scr -o demo.html

demo.man: demo.scr
        $(SCRIBE) demo.scr -o demo.man
])
                

produces:

SCRIBE = scribe

all: demo.html demo.man

demo.html: demo.scr
	$(SCRIBE) demo.scr -o demo.html

demo.man: demo.scr
	$(SCRIBE) demo.scr -o demo.man

The second example uses some fontification and line numbering:

(prgm :language c :bg "#dddddd" :lnum 10 :colors '((string "#0077ff")) [
#include <stdio.h>

int main( int argc, char *argv,(char 91),(char 93) ) {
   printf( "Hello word: %d (%s)\n", argc, argv,(char 91) 0 ,(char 93) );
   return 0;
}])
                

produces:

 10:#include <stdio.h>
 11:
 12:int main( int argc, char *argv[] ) {
 13:   printf( "Hello word: %d (%s)\n", argc, argv[ 0 ] );
 14:   return 0;
 15:}

7.2 From-file

(from-file [:definition #f] [:start #f] [:stop #f] file)Scribe function

argumentdescription
:definitionA string denoting the definition name. This option is not implemented for all languages. Currently only Bigloo and Scribe languages implement it.
:startA line number where to start the text inclusion.
:stopA line number where to stop the text inclusion.
fileThe file to be included.

It is convenient not to embed the computer program text inside the Scribe document but leave it inside separate files. The Scribe function from-file enable inclusion inside a prgm call. An entire file or only some parts of the file can be included. The example:

(prgm :language scribe :lnum 1 [,(from-file "prgm.scr" :start 17 :stop 22)])

produces:

  1:It is common that some parts of a Scribe text represent other
  2:texts. For instance, for a document describing a computer programming
  3:language, it is frequent to include excerpt of programs. These
  4:embedded texts are frequently displayed in a specific font and with no
  5:justification but with a precise ,(emph "indentation"). This indentation is
  6:important because it helps in understanding the text;

The example:

(prgm :language bigloo [,(from-file :definition "fib" "prgm-fib.scm")])

produces:

(define (fib x)
   (if (< x 2)
       1
       (+ (fib (- x 1)) (fib (- x 2)))))


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