|
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.
(prgm [:lnum integer] [:bg #f] [:frame #f] [:width 1.0] [:language procedure] [:colors list] . exp) | Scribe function |
argument | description |
:lnum | The boolean value #f disables line numbering.
An integer value enables line number. The number of the first line
is the value of :lnum. |
:bg | The color of the background of the computer program. |
:frame | Enables or disables a frame around the text of the program. |
:width | The width of the program. An integer value specifies a pixel
width. A floating point value specifies a percentage of the text line width. |
:language | The 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. |
:colors | A 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:
Name | Meaning |
comment | Comments |
define | Definitions |
keyword | Keywords |
markup | XML like markups |
module | Module declaration |
preprocessor | Pre-processor directives |
string | String literals |
thread | Thread API |
type | Type annotations |
|
exp | The 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:} |
|
(from-file [:definition #f] [:start #f] [:stop #f] file) | Scribe function |
argument | description |
:definition | A string denoting the definition name. This option
is not implemented for all languages. Currently only Bigloo and
Scribe languages implement it. |
:start | A line number where to start the text inclusion. |
:stop | A line number where to stop the text inclusion. |
file | The 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))))) |
|