]> gitweb.factorcode.org Git - factor.git/blob - extra/help/help-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / extra / help / help-docs.factor
1 USING: help.markup help.crossref help.stylesheet help.topics
2 help.syntax definitions io prettyprint summary arrays math
3 sequences vocabs ;
4 IN: help
5
6 ARTICLE: "printing-elements" "Printing markup elements"
7 "When writing documentation, it is useful to be able to print markup elements for testing purposes. Markup elements which are strings or arrays of elements are printed in the obvious way. Markup elements of the form " { $snippet "{ $directive content... }" } " are printed by executing the " { $snippet "$directive" } " word with the element content on the stack."
8 { $subsection print-element }
9 { $subsection print-content } ;
10
11 ARTICLE: "span-elements" "Span elements"
12 { $subsection $emphasis }
13 { $subsection $strong }
14 { $subsection $link }
15 { $subsection $vocab-link }
16 { $subsection $snippet }
17 { $subsection $url } ;
18
19 ARTICLE: "block-elements" "Block elements"
20 "Paragraph break:"
21 { $subsection $nl }
22 "Standard headings for word documentation:"
23 { $subsection $values }
24 { $subsection $description }
25 { $subsection $class-description }
26 { $subsection $error-description }
27 { $subsection $var-description }
28 { $subsection $contract }
29 { $subsection $examples }
30 { $subsection $warning }
31 { $subsection $notes }
32 { $subsection $side-effects }
33 { $subsection $errors }
34 { $subsection $see-also }
35 "Boilerplate paragraphs:"
36 { $subsection $low-level-note }
37 { $subsection $io-error }
38 "Some additional elements:"
39 { $subsection $code }
40 { $subsection $curious }
41 { $subsection $example }
42 { $subsection $heading }
43 { $subsection $links }
44 { $subsection $list }
45 { $subsection $markup-example }
46 { $subsection $references }
47 { $subsection $see }
48 { $subsection $subsection }
49 { $subsection $table } ;
50
51 ARTICLE: "markup-utils" "Markup element utilities"
52 "Utility words to assist in defining new elements:"
53 { $subsection simple-element }
54 { $subsection ($span) }
55 { $subsection ($block) } ;
56
57 ARTICLE: "element-types" "Element types"
58 "Markup elements can be classified into two broad categories, block elements and span elements. Block elements are inset with newlines before and after, whereas span elements flow with the paragraph text."
59 { $subsection "span-elements" }
60 { $subsection "block-elements" }
61 { $subsection "markup-utils" } ;
62
63 IN: help.markup
64 ABOUT: "element-types"
65
66 ARTICLE: "browsing-help" "Browsing documentation"
67 "The easiest way to browse the help is from the help browser tool in the UI, however you can also display help topics in the listener. Help topics are identified by article name strings, or words. You can request a specific help topic:"
68 { $subsection help }
69 "You can also display the main help article for a vocabulary:"
70 { $subsection about } ;
71
72 ARTICLE: "writing-help" "Writing documentation"
73 "By convention, documentation is written in files whose names end with " { $snippet "-docs.factor" } ". Vocabulary documentation should be placed in the same directory as the vocabulary source code; see " { $link "vocabs.loader" } "."
74 $nl
75 "A pair of parsing words are used to define free-standing articles and to associate documentation with words:"
76 { $subsection POSTPONE: ARTICLE: }
77 { $subsection POSTPONE: HELP: }
78 "A parsing word defines the main help article for a vocabulary:"
79 { $subsection POSTPONE: ABOUT: }
80 "The " { $emphasis "content" } " in both cases is a " { $emphasis "markup element" } ", a recursive structure taking one of the following forms:"
81 { $list
82     { "a string," }
83     { "an array of markup elements," }
84     { "or an array of the form " { $snippet "{ $directive content... }" } ", where " { $snippet "$directive" } " is a markup word whose name starts with " { $snippet "$" } ", and " { $snippet "content..." } " is a series of markup elements" }
85 }
86 { $subsection "element-types" }
87 { $subsection "printing-elements" }
88 "Related words can be cross-referenced:"
89 { $subsection related-words }
90 { $see-also "help.lint" } ;
91
92 ARTICLE: "help-impl" "Help system implementation"
93 "Help topic protocol:"
94 { $subsection article-name }
95 { $subsection article-title }
96 { $subsection article-content }
97 { $subsection article-parent }
98 { $subsection set-article-parent }
99 "Boilerplate word help can be automatically generated (for example, slot accessor help):"
100 { $subsection word-help }
101 { $subsection word-help* }
102 "Help article implementation:"
103 { $subsection article }
104 { $subsection articles }
105 "Links:"
106 { $subsection link }
107 { $subsection >link }
108 "Utilities for traversing markup element trees:"
109 { $subsection elements }
110 { $subsection collect-elements }
111 "Links and " { $link article } " instances implement the definition protocol; refer to " { $link "definitions" } "." ;
112
113 ARTICLE: "help" "Help system"
114 "The help system maintains documentation written in a simple markup language, along with cross-referencing and search. Documentation can either exist as free-standing " { $emphasis "articles" } " or be associated with words."
115 { $subsection "browsing-help" }
116 { $subsection "writing-help" }
117 { $vocab-subsection "Help lint tool" "help.lint" }
118 { $subsection "help-impl" } ;
119
120 IN: help
121 ABOUT: "help"
122
123 HELP: $title
124 { $values { "topic" "a help article name or a word" } }
125 { $description "Prints a help article's title, or a word's " { $link summary } ", depending on the type of " { $snippet "topic" } "." } ;
126
127 HELP: help
128 { $values { "topic" "an article name or a word" } }
129 { $description
130     "Displays a help article or documentation associated to a word on " { $link output-stream } "."
131 } ;
132
133 HELP: about
134 { $values { "vocab" "a vocabulary specifier" } }
135 { $description
136     "Displays the main help article for the vocabulary. The main help article is set with the " { $link POSTPONE: ABOUT: } " parsing word."
137 } ;
138
139 HELP: :help
140 { $description "Displays documentation for the most recent error." } ;
141
142 HELP: $subsection
143 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
144 { $description "Prints a large clickable link to the help topic named by the first string element of " { $snippet "element" } "." }
145 { $examples
146     { $code "{ $subsection \"sequences\" }" }
147 } ;
148
149 HELP: $index
150 { $values { "element" "a markup element containing one quotation with stack effect " { $snippet "( quot -- )" } } }
151 { $description "Calls the quotation to generate a sequence of help topics, and outputs a " { $link $subsection } " for each one." } ;
152
153 HELP: ($index)
154 { $values { "articles" "a sequence of help articles" } }
155 { $description "Writes a list of " { $link $subsection } " elements to " { $link output-stream } "." } ;
156
157 HELP: xref-help
158 { $description "Update help cross-referencing. Usually this is done automatically." } ;
159
160 HELP: sort-articles
161 { $values { "seq" "a sequence of help topics" } { "newseq" "a sequence of help topics" } }
162 { $description "Sorts a sequence of help topics." } ;
163
164 { article-children article-parent xref-help } related-words
165
166 HELP: $predicate
167 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
168 { $description "Prints the boilerplate description of a class membership predicate word such as " { $link array? } " or " { $link integer? } "." } ;
169
170 HELP: print-element
171 { $values { "element" "a markup element" } }
172 { $description "Prints a markup element to " { $link output-stream } "." } ;
173
174 HELP: print-content
175 { $values { "element" "a markup element" } }
176 { $description "Prints a top-level markup element to " { $link output-stream } "." } ;
177
178 HELP: simple-element
179 { $class-description "Class of simple elements, which are just arrays of elements." } ;
180
181 HELP: ($span)
182 { $values { "quot" "a quotation" } }
183 { $description "Prints an inline markup element." } ;
184
185 HELP: ($block)
186 { $values { "quot" "a quotation" } }
187 { $description "Prints a block markup element with newlines before and after." } ;
188
189 HELP: $heading
190 { $values { "element" "a markup element" } }
191 { $description "Prints a markup element, usually a string, as a block with the " { $link heading-style } "." }
192 { $examples
193     { $markup-example { $heading "What remains to be discovered" } }
194 } ;
195
196 HELP: $subheading
197 { $values { "element" "a markup element of the form " { $snippet "{ title content }" } } }
198 { $description "Prints a markup element, usually a string, as a block with the " { $link strong-style } "." }
199 { $examples
200     { $markup-example { $subheading "Developers, developers, developers!" } }
201 } ;
202
203 HELP: $code
204 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
205 { $description "Prints code examples, as seen in many help articles. The markup element must be an array of strings." }
206 { $notes
207     "The code becomes clickable if the output stream supports it, and clicking it opens a listener window with the text inserted at the input prompt."
208     $nl
209     "If you want to show code along with sample output, use the " { $link $example } " element."
210 }
211 { $examples
212     { $markup-example { $code "2 2 + ." } }
213 } ;
214
215 HELP: $vocabulary
216 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
217 { $description "Prints a word's vocabulary. This markup element is automatically output by the help system, so help descriptions of parsing words should not call it." } ;
218
219 HELP: $description
220 { $values { "element" "a markup element" } }
221 { $description "Prints the description subheading found on the help page of most words." } ;
222
223 HELP: $contract
224 { $values { "element" "a markup element" } }
225 { $description "Prints a heading followed by a contract, found on the help page of generic words. Every generic word should document a contract which specifies method behavior that callers can rely upon, and implementations must obey." }
226 { $examples
227     { $markup-example { $contract "Methods of this generic word must always crash." } }
228 } ;
229
230 HELP: $examples
231 { $values { "element" "a markup element" } }
232 { $description "Prints a heading followed by some examples. Word documentation should include examples, at least if the usage of the word is not entirely obvious." }
233 { $examples
234     { $markup-example { $examples { $example "USING: math prettyprint ;" "2 2 + ." "4" } } }
235 } ;
236
237 HELP: $example
238 { $values { "element" "a markup element of the form " { $snippet "{ inputs... output }" } } }
239 { $description "Prints a clickable example with sample output. The markup element must be an array of strings. All but the last string are joined by newlines and taken as the input text, and the last string is the output. The example becomes clickable if the output stream supports it, and clicking it opens a listener window with the input text inserted at the input prompt." }
240 { $examples
241     "The input text must contain a correct " { $link POSTPONE: USING: } " declaration, and output text should be a string of what the input prints when executed, not the final stack contents or anything like that. So the following is an incorrect example:"
242     { $markup-example { $unchecked-example "2 2 +" "4" } }
243     "However the following is right:"
244     { $markup-example { $example "USING: math prettyprint ;" "2 2 + ." "4" } }
245     "Examples can incorporate a call to " { $link .s } " to show multiple output values; the convention is that you may assume the stack is empty before the example evaluates."
246 } ;
247
248 HELP: $markup-example
249 { $values { "element" "a markup element" } }
250 { $description "Prints a clickable example showing the prettyprinted source text of " { $snippet "element" } " followed by rendered output. The example becomes clickable if the output stream supports it." }
251 { $examples
252     { $markup-example { $markup-example { $emphasis "Hi" } } }
253 } ;
254
255 HELP: $warning
256 { $values { "element" "a markup element" } }
257 { $description "Prints an element inset in a block styled as so to draw the reader's attention towards it." }
258 { $examples
259     { $markup-example { $warning "Incorrect use of this product may cause serious injury or death." } }
260 } ;
261
262 HELP: $link
263 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
264 { $description "Prints a link to a help article or word." }
265 { $examples
266     { $markup-example { $link "dlists" } }
267     { $markup-example { $link + } }
268 } ;
269
270 HELP: textual-list
271 { $values { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } }
272 { $description "Applies the quotation to each element of the sequence, printing a comma between each pair of elements." }
273 { $examples
274     { $example "USING: help.markup io ;" "{ \"fish\" \"chips\" \"salt\" } [ write ] textual-list" "fish, chips, salt" }
275 } ;
276
277 HELP: $links
278 { $values { "topics" "a sequence of article names or words" } }
279 { $description "Prints a series of links to help articles or word documentation." }
280 { $notes "This markup element is used to implement " { $link $links } "." }
281 { $examples
282     { $markup-example { $links + - * / } }
283 } ;
284
285 HELP: $see-also
286 { $values { "topics" "a sequence of article names or words" } }
287 { $description "Prints a heading followed by a series of links." }
288 { $examples
289     { $markup-example { $see-also "graphs" "dlists" } }
290 } ;
291
292 { $see-also $related related-words } related-words
293
294 HELP: $table
295 { $values { "element" "an array of arrays of markup elements" } }
296 { $description "Prints a table given as an array of rows, where each row must have the same number of columns." }
297 { $examples
298     { $markup-example
299         { $table
300             { "a" "b" "c" }
301             { "d" "e" "f" }
302         }
303     }
304 } ;
305
306 HELP: $values
307 { $values { "element" "an array of pairs of markup elements" } }
308 { $description "Prints the description of arguments and values found on every word help page. The first element of a pair is the argument name and is output with " { $link $snippet } ". The remainder can be an element of any form." } ;
309
310 HELP: $list
311 { $values { "element" "an array of markup elements" } }
312 { $description "Prints a bulleted list of markup elements." }
313 { $notes
314     "A common mistake is that if an item consists of more than just a string, it will be broken up as several items:"
315     { $markup-example
316         { $list
317             "First item"
318             "Second item " { $emphasis "with emphasis" }
319         }
320     }
321     "The fix is easy; just group the two markup elements making up the second item into one markup element:"
322     { $markup-example
323         { $list
324             "First item"
325             { "Second item " { $emphasis "with emphasis" } }
326         }
327     }
328 } ;
329
330 HELP: $errors
331 { $values { "element" "a markup element" } }
332 { $description "Prints the errors subheading found on the help page of some words. This section should document any errors thrown by the word." }
333 { $examples
334     { $markup-example { $errors "I/O errors, network errors, hardware errors... oh my!" } }
335 } ;
336
337 HELP: $side-effects
338 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
339 { $description "Prints a heading followed by a list of input values or variables which are modified by the word being documented." }
340 { $examples
341     { $markup-example
342         { { $values { "seq" "a mutable sequence" } } { $side-effects "seq" } }
343     }
344 } ;
345
346 HELP: $notes
347 { $values { "element" "a markup element" } }
348 { $description "Prints the notes subheading found on the help page of some words. This section should document usage tips and pitfalls." } ;
349
350 HELP: $see
351 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
352 { $description "Prints the definition of " { $snippet "word" } " by calling " { $link see } "." }
353 { $examples
354     { $markup-example { "Here is a word definition:" { $see reverse } } }
355 } ;
356
357 HELP: $definition
358 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
359 { $description "Prints a heading followed by the definition of " { $snippet "word" } " by calling " { $link see } "." } ;
360
361 HELP: $curious
362 { $values { "element" "a markup element" } }
363 { $description "Prints a heading followed by a markup element." }
364 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
365
366 HELP: $references
367 { $values { "element" "a markup element of the form " { $snippet "{ topic... }" } } }
368 { $description "Prints a heading followed by a series of links." }
369 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
370
371 HELP: HELP:
372 { $syntax "HELP: word content... ;" }
373 { $values { "word" "a word" } { "content" "markup elements" } }
374 { $description "Defines documentation for a word." }
375 { $examples
376     { $code
377         ": foo 2 + ;"
378         "HELP: foo"
379         "{ $values { \"m\" \"an integer\" } { \"n\" \"an integer\" } }"
380         "{ $description \"Increments a value by 2.\" } ;"
381         "\\ foo help"
382     }
383 } ;
384
385 HELP: ARTICLE:
386 { $syntax "ARTICLE: topic title content... ;" }
387 { $values { "topic" "an object" } { "title" "a string" } { "content" "markup elements" } }
388 { $description "Defines a help article. String topic names are reserved for core documentation. Contributed modules should name articles by arrays, where the first element of an array identifies the module; for example, " { $snippet "{ \"httpd\" \"intro\" }" } "." }
389 { $examples
390     { $code
391         "ARTICLE: \"example\" \"An example article\""
392         "\"Hello world.\" ;"
393     }
394 } ;
395
396 HELP: ABOUT:
397 { $syntax "MAIN: article" }
398 { $values { "article" "a help article" } }
399 { $description "Defines the main documentation article for the current vocabulary." } ;
400
401 HELP: vocab-help
402 { $values { "vocab" "a vocabulary specifier" } { "help" "a help article" } }
403 { $description "Outputs the main help article for a vocabulary. The main help article can be set with " { $link POSTPONE: ABOUT:  } "." } ;