aboutsummaryrefslogtreecommitdiff
path: root/doc/user/prgm.skb
blob: 1ad8814144c4ac8714b5d29c4cc708dbc19934a5 (about) (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
;;; prgm.skb  --  Computer programs
;;;
;;; Copyright 2008  Ludovic Court�s <ludo@gnu.org>
;;; Copyright 2001, 2002, 2003, 2004  Manuel Serrano
;;;
;;;
;;; 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.

;*---------------------------------------------------------------------*/
;*    fib ...                                                          */
;*---------------------------------------------------------------------*/
(define (fib x) ;!fib
   (if (< x 2)
       1
       (+ (fib (- x 1)) (fib (- x 2)))))

;*---------------------------------------------------------------------*/
;*    Computer programs                                                */
;*---------------------------------------------------------------------*/
(chapter :title "Computer Programs" 
         :ident "programs"

(p [In a document describing a computer programming language, it is
common to include excerpt of programs.  Program code is typically
typeset in a specific font, with no justification, and with a precise
,(emph "indentation").  Indentation is important because it helps
understand the code,(begin ";") it is thus desirable to preserve
indentation in program text.  The ,(markup-ref "pre") text layout
already allows indentation to be preserved.  This chapter presents two
new functions that complement it: ,(markup-ref "prog") and ,(markup-ref
"source"), both of which are specially designed to represent computer
programs in text.])

;*---------------------------------------------------------------------*/
;*    Programs ... @label prog@                                        */
;*---------------------------------------------------------------------*/
(section :title "Program"

(p [A ,(code "prog") function call preserves the indentation of the
program. It may automatically introduce line numbers.])

(doc-markup 'prog
	    `((:line ,[Enables/disables automatic line numbering. An integer
               value enables the line number and specifies the number of
               the first line of the program. A value of ,(code "#f") disables
               the line numbering.])
	      (:linedigit ,[The number of digit for representing line
               numbers.])
	      (:mark ,[A string or the boolean ,(code "#f"). If this option 
               is a string, that string is the prefix 
               of line marks. These marks can be used in the 
               ,(markup-ref "ref") reference. A mark
               identifier is defined by the regular expression:
               ,(code [,(char "[")_a-zA-Z,(char "]"),(char "[")_a-zA-Z0-9,(char "]")*]). The prefix and the mark are removed from the output program.]))
	    :force-engines *api-engines*
	    :see-also '(source pre ref))

(example-produce 
 (example :legend "A program" (prgm :file "src/prgm1.skb"))
 (disp (include "src/prgm1.skb"))))

;*---------------------------------------------------------------------*/
;*    Source code ... @label source@                                   */
;*---------------------------------------------------------------------*/
(section :title "Source Code"

(p [The ,(code "source") function extracts part of the source code and
enables ,(emph "fontification"). That is, some words of the program
can be rendered using different colors or faces.])

;!source-start
(doc-markup 'source
	    `((:language ,[The ,(markup-ref "language") of the source code.])
	      (:file ,[The file containing the actual source code. The file
               is searched in the ,(markup-ref "*source-path*") path.])
	      (:start [A start line number or a start marker.])
	      (:stop [A stop line number or a stop marker.])
	      (:definition [The identifier of the definition to extract.])
	      (:tab [The tabulation width.]))
	    :common-args '()
	    :force-engines *api-engines*
	    :see-also '(prog language ref *source-path*))
;!source-stop

(linebreak)
(example-produce 
 (example :legend "The source markup" (prgm :file "src/prgm2.skb"))
 (disp (include "src/prgm2.skb")))
   
(p [Note that even awful programming languages of the C family can be
highlighted!])

(linebreak)
(example-produce 
 (example :legend "The source markup for C" (prgm :file "src/prgm4.skb"))
 (disp (include "src/prgm4.skb")))
   
(p [You would highlight Java,(symbol "tm") code in a similar way, i.e.,
with ,(tt [:language java]).])

(mark "*source-path*")
(p [Files passed as the ,(tt [:file]) argument of ,(markup-ref "source")
are searched in the current ,(emph [source path]), which is defined by the
,(tt [*source-path*]) ,(srfi-ref 39) parameter.  This parameter contains
a list of directories and its value can be obtained using ,(code
[(*source-path*)]).  Its value can be altered using the ,(tt [-S])
command-line option of the ,(tt [skribilo]) compiler (see ,(numref :text
[Chapter] :ident "compiler") for details).])
   
(p [The ,(param :language) parameter of ,(markup-ref "source") takes a
,(tt [language]) object, which performs the actual source highlighting.
Several programming languages are currently supported: the ,(tt
[(skribilo source lisp)]) module provides ,(tt [skribe]), ,(tt [scheme]),
,(tt [stklos]), ,(tt [bigloo]) and ,(tt [lisp]), which implement source
highlighting for the corresponding lispy dialects, while the ,(tt
[(skribilo source c)]) module provides ,(tt [c]) and ,(tt [java]).
Thus, you need to import the relevant module to get the right language,
for instance by adding ,(code [(use-modules (skribilo source c))]) at
the beginning of your document.  Additional languages can be created
using the ,(markup-ref "language") function (see below).]))

;*---------------------------------------------------------------------*/
;*    Language ... @label language@                                    */
;*---------------------------------------------------------------------*/
(section :title "Language"
(index "source" :note "fontification")
(index "fontification")

(p [The ,(code "language") function builds a language that can be used
in ,(markup-ref "source") function call.])

(doc-markup 'language
	    `((:name [A string which denotes the name of the language.])
	      (:fontifier [A function of one argument (a string), that
               colorizes a line source code.])
	      (:extractor [A function of three arguments: an input port,
               an identifier, a tabulation size. This function ,(emph "scans")
               in the input port the definition is looks for.]))
	    :common-args '()
	    :force-engines *api-engines*
	    :see-also '(prog source ref))

; **** FIXME:
(cond-expand
   (bigloo
    (example-produce 
     (example :legend "An ad-hoc fontification"
	      (prgm :file "src/prgm3.skb"))
     (disp (include "src/prgm3.skb"))))
   (else
    '()))))

;;; Local Variables:
;;; coding: latin-1
;;; ispell-local-dictionary: "american"
;;; End: