]> gitweb.factorcode.org Git - factor.git/blob - basis/help/help-docs.factor
merge project-euler.factor
[factor.git] / basis / 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 strings see ;
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 { $subsections
9     print-element
10     print-content
11 } ;
12
13 ARTICLE: "span-elements" "Span elements"
14 { $subsections
15     $emphasis
16     $strong
17     $link
18     $vocab-link
19     $snippet
20     $slot
21     $url
22 } ;
23
24 ARTICLE: "block-elements" "Block elements"
25 "Paragraph break:"
26 { $subsections $nl }
27 "Standard headings for word documentation:"
28 { $subsections
29     $values
30     $description
31     $class-description
32     $error-description
33     $var-description
34     $contract
35     $examples
36     $warning
37     $notes
38     $side-effects
39     $errors
40     $see-also
41 }
42 "Elements used in " { $link $values } " forms:"
43 { $subsections
44     $instance
45     $maybe
46     $or
47     $quotation
48 }
49 "Boilerplate paragraphs:"
50 { $subsections
51     $low-level-note
52     $io-error
53 }
54 "Some additional elements:"
55 { $subsections
56     $code
57     $curious
58     $example
59     $heading
60     $links
61     $list
62     $markup-example
63     $references
64     $see
65     $subsection
66     $table
67 } ;
68
69 ARTICLE: "markup-utils" "Markup element utilities"
70 "Utility words to assist in defining new elements:"
71 { $subsections
72     simple-element
73     ($span)
74     ($block)
75 } ;
76
77 ARTICLE: "element-types" "Element types"
78 "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."
79 { $subsections
80     "span-elements"
81     "block-elements"
82     "markup-utils"
83 } ;
84
85 IN: help.markup
86 ABOUT: "element-types"
87
88 ARTICLE: "writing-help" "Writing documentation"
89 "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" } "."
90 $nl
91 "A pair of parsing words are used to define free-standing articles and to associate documentation with words:"
92 { $subsections
93     POSTPONE: ARTICLE:
94     POSTPONE: HELP:
95 }
96 "A parsing word defines the main help article for a vocabulary:"
97 { $subsections POSTPONE: ABOUT: }
98 "The " { $emphasis "content" } " in both cases is a " { $emphasis "markup element" } ", a recursive structure taking one of the following forms:"
99 { $list
100     { "a string," }
101     { "an array of markup elements," }
102     { "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" }
103 }
104 "Here is a more formal schema for the help markup language:"
105 { $code
106 "<element> ::== <string> | <simple-element> | <fancy-element>"
107 "<simple-element> ::== { <element>* }"
108 "<fancy-element> ::== { <type> <element> }"
109 }
110 { $subsections
111     "element-types"
112     "printing-elements"
113 }
114 "Related words can be cross-referenced:"
115 { $subsections related-words }
116 { $see-also "help.lint" } ;
117
118 ARTICLE: "help-impl" "Help system implementation"
119 "Help topic protocol:"
120 { $subsections
121     article-name
122     article-title
123     article-content
124     article-parent
125     set-article-parent
126 }
127 "Boilerplate word help can be automatically generated (for example, slot accessor help):"
128 { $subsections
129     word-help
130     word-help*
131 }
132 "Help article implementation:"
133 { $subsections
134     article
135     articles
136 }
137 "Links:"
138 { $subsections
139     link
140     >link
141 }
142 "Utilities for traversing markup element trees:"
143 { $subsections
144     elements
145     collect-elements
146 }
147 "Links and " { $link article } " instances implement the definition protocol; refer to " { $link "definitions" } "." ;
148
149 ARTICLE: "help" "Help system"
150 "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."
151 { $subsections
152     "browsing-help"
153     "writing-help"
154     "help.lint"
155     "tips-of-the-day"
156     "help-impl"
157 } ;
158
159 IN: help
160 ABOUT: "help"
161
162 HELP: $title
163 { $values { "topic" "a help article name or a word" } }
164 { $description "Prints a help article's title, or a word's " { $link summary } ", depending on the type of " { $snippet "topic" } "." } ;
165
166 HELP: print-topic
167 { $values { "topic" "an article name or a word" } }
168 { $description
169     "Displays a help topic on " { $link output-stream } "."
170 } ;
171
172 HELP: help
173 { $values { "topic" "an article name or a word" } }
174 { $description
175     "Displays a help topic."
176 } ;
177
178 HELP: :help
179 { $description "Displays documentation for the most recent error." } ;
180
181 HELP: $subsection
182 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
183 { $description "Prints a large clickable link to the help topic named by the first item in " { $snippet "element" } ". The link is printed along with its associated definition icon." }
184 { $examples
185     { $markup-example { $subsections "sequences" } }
186     { $markup-example { $subsections nth } }
187     { $markup-example { $subsections each } }
188 } ;
189
190 HELP: $subsections
191 { $values { "children" "a " { $link sequence } " of one or more " { $link topic } "s or, in the case of a help article, the article's string name." } }
192 { $description "Prints a large clickable link for each of the listed help topics in " { $snippet "children" } ". The link is printed along with its associated definition icon." }
193 { $examples
194     { $markup-example { $subsections "sequences" nth each } }
195 } ;
196
197 { $subsection $subsections $link } related-words
198
199 HELP: $vocab-subsection
200 { $values { "element" "a markup element of the form " { $snippet "{ title vocab }" } } }
201 { $description "Prints a large clickable link for " { $snippet "vocab" } ". If " { $snippet "vocab" } " has a main help article, the link will point at that article and the " { $snippet "title" } " input will be ignored. Otherwise, the link text will be taken from " { $snippet "title" } " and point to " { $snippet "vocab" } "'s automatically generated documentation."
202 $nl
203 "The link will be printed along with its associated definition icon." }
204 { $examples
205     { $markup-example { $vocab-subsection "SQLite" "db.sqlite" } }
206     { $markup-example { $vocab-subsection "Alien" "alien" } }
207 } ;
208
209 HELP: $index
210 { $values { "element" "a markup element containing one quotation with stack effect " { $snippet "( quot -- )" } } }
211 { $description "Calls the quotation to generate a sequence of help topics, and outputs a " { $link $subsection } " for each one." } ;
212
213 HELP: ($index)
214 { $values { "articles" "a sequence of help articles" } }
215 { $description "Writes a list of " { $link $subsection } " elements to " { $link output-stream } "." } ;
216
217 HELP: xref-help
218 { $description "Update help cross-referencing. Usually this is done automatically." } ;
219
220 HELP: sort-articles
221 { $values { "seq" "a sequence of help topics" } { "newseq" "a sequence of help topics" } }
222 { $description "Sorts a sequence of help topics." } ;
223
224 { article-children article-parent xref-help } related-words
225
226 HELP: $predicate
227 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
228 { $description "Prints the boilerplate description of a class membership predicate word such as " { $link array? } " or " { $link integer? } "." } ;
229
230 HELP: print-element
231 { $values { "element" "a markup element" } }
232 { $description "Prints a markup element to " { $link output-stream } "." } ;
233
234 HELP: print-content
235 { $values { "element" "a markup element" } }
236 { $description "Prints a top-level markup element to " { $link output-stream } "." } ;
237
238 HELP: simple-element
239 { $class-description "Class of simple elements, which are just arrays of elements." } ;
240
241 HELP: ($span)
242 { $values { "quot" "a quotation" } }
243 { $description "Prints an inline markup element." } ;
244
245 HELP: ($block)
246 { $values { "quot" "a quotation" } }
247 { $description "Prints a block markup element with newlines before and after." } ;
248
249 HELP: $heading
250 { $values { "element" "a markup element" } }
251 { $description "Prints a markup element, usually a string, as a block with the " { $link heading-style } "." }
252 { $examples
253     { $markup-example { $heading "What remains to be discovered" } }
254 } ;
255
256 HELP: $subheading
257 { $values { "element" "a markup element of the form " { $snippet "{ title content }" } } }
258 { $description "Prints a markup element, usually a string, as a block with the " { $link strong-style } "." }
259 { $examples
260     { $markup-example { $subheading "Developers, developers, developers!" } }
261 } ;
262
263 HELP: $code
264 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
265 { $description "Prints code examples, as seen in many help articles. The markup element must be an array of strings." }
266 { $notes
267     "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."
268     $nl
269     "If you want to show code along with sample output, use the " { $link $example } " element."
270 }
271 { $examples
272     { $markup-example { $code "2 2 + ." } }
273 } ;
274
275 HELP: $nl
276 { $values { "children" "unused parameter" } }
277 { $description "Prints a paragraph break. The parameter is unused." } ;
278
279 HELP: $snippet
280 { $values { "children" "markup elements" } }
281 { $description "Prints a key word or otherwise notable snippet of text, such as a type or a word input parameter. To document slot names, use " { $link $slot } "." } ;
282
283 HELP: $slot
284 { $values { "children" "markup elements" } }
285 { $description "Prints a tuple slot name in the same way as a snippet. The help tool can check that there exists an accessor with this name." } ;
286
287 HELP: $vocabulary
288 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
289 { $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." } ;
290
291 HELP: $description
292 { $values { "element" "a markup element" } }
293 { $description "Prints the description subheading found on the help page of most words." } ;
294
295 HELP: $contract
296 { $values { "element" "a markup element" } }
297 { $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." }
298 { $examples
299     { $markup-example { $contract "Methods of this generic word must always crash." } }
300 } ;
301
302 HELP: $examples
303 { $values { "element" "a markup element" } }
304 { $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." }
305 { $examples
306     { $markup-example { $examples { $example "USING: math prettyprint ;" "2 2 + ." "4" } } }
307 } ;
308
309 HELP: $example
310 { $values { "element" "a markup element of the form " { $snippet "{ inputs... output }" } } }
311 { $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." }
312 { $examples
313     "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:"
314     { $markup-example { $unchecked-example "2 2 +" "4" } }
315     "However the following is right:"
316     { $markup-example { $example "USING: math prettyprint ;" "2 2 + ." "4" } }
317     "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."
318 } ;
319
320 HELP: $markup-example
321 { $values { "element" "a markup element" } }
322 { $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." }
323 { $examples
324     { $markup-example { $markup-example { $emphasis "Hi" } } }
325 } ;
326
327 HELP: $warning
328 { $values { "element" "a markup element" } }
329 { $description "Prints an element inset in a block styled as so to draw the reader's attention towards it." }
330 { $examples
331     { $markup-example { $warning "Incorrect use of this product may cause serious injury or death." } }
332 } ;
333
334 HELP: $link
335 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
336 { $description "Prints a link to a help article or word." }
337 { $examples
338     { $markup-example { $link "dlists" } }
339     { $markup-example { $link + } }
340 } ;
341
342 HELP: textual-list
343 { $values { "seq" "a sequence" } { "quot" { $quotation "( elt -- )" } } }
344 { $description "Applies the quotation to each element of the sequence, printing a comma between each pair of elements." }
345 { $examples
346     { $example "USING: help.markup io namespaces ;" "last-element off" "{ \"fish\" \"chips\" \"salt\" } [ write ] textual-list" "fish, chips, salt" }
347 } ;
348
349 HELP: $links
350 { $values { "topics" "a sequence of article names or words" } }
351 { $description "Prints a series of links to help articles or word documentation." }
352 { $notes "This markup element is used to implement " { $link $links } "." }
353 { $examples
354     { $markup-example { $links + - * / } }
355 } ;
356
357 HELP: $see-also
358 { $values { "topics" "a sequence of article names or words" } }
359 { $description "Prints a heading followed by a series of links." }
360 { $examples
361     { $markup-example { $see-also "graphs" "dlists" } }
362 } ;
363
364 { $see-also $related related-words } related-words
365
366 HELP: $table
367 { $values { "element" "an array of arrays of markup elements" } }
368 { $description "Prints a table given as an array of rows, where each row must have the same number of columns." }
369 { $examples
370     { $markup-example
371         { $table
372             { "a" "b" "c" }
373             { "d" "e" "f" }
374         }
375     }
376 } ;
377
378 HELP: $values
379 { $values { "element" "an array of pairs of markup elements" } }
380 { $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 is either a single class word, or an element. If it is a class word " { $snippet "class" } ", it is inserted as if it were shorthand for " { $snippet "{ $instance class }" } "." }
381 { $see-also $maybe $instance $quotation } ;
382
383 HELP: $instance
384 { $values { "element" "an array with shape " { $snippet "{ class }" } } }
385 { $description
386     "Produces the text “a " { $emphasis "class" } "” or “an " { $emphasis "class" } "”, depending on the first letter of " { $emphasis "class" } "."
387 }
388 { $examples
389     { $markup-example { $instance string } }
390     { $markup-example { $instance integer } }
391     { $markup-example { $instance f } }
392 } ;
393
394 HELP: $maybe
395 { $values { "element" "an array with shape " { $snippet "{ class }" } } }
396 { $description
397     "Produces the text “a " { $emphasis "class" } " or f” or “an " { $emphasis "class" } " or f”, depending on the first letter of " { $emphasis "class" } "."
398 }
399 { $examples
400     { $markup-example { $maybe string } }
401 } ;
402
403 HELP: $quotation
404 { $values { "element" "an array with shape " { $snippet "{ effect }" } } }
405 { $description
406     "Produces the text “a quotation with stack effect " { $emphasis "effect" } "”."
407 }
408 { $examples
409     { $markup-example { $quotation "( obj -- )" } }
410 } ;
411
412 HELP: $list
413 { $values { "element" "an array of markup elements" } }
414 { $description "Prints a bulleted list of markup elements." }
415 { $notes
416     "A common mistake is that if an item consists of more than just a string, it will be broken up as several items:"
417     { $markup-example
418         { $list
419             "First item"
420             "Second item " { $emphasis "with emphasis" }
421         }
422     }
423     "The fix is easy; just group the two markup elements making up the second item into one markup element:"
424     { $markup-example
425         { $list
426             "First item"
427             { "Second item " { $emphasis "with emphasis" } }
428         }
429     }
430 } ;
431
432 HELP: $errors
433 { $values { "element" "a markup element" } }
434 { $description "Prints the errors subheading found on the help page of some words. This section should document any errors thrown by the word." }
435 { $examples
436     { $markup-example { $errors "I/O errors, network errors, hardware errors... oh my!" } }
437 } ;
438
439 HELP: $side-effects
440 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
441 { $description "Prints a heading followed by a list of input values or variables which are modified by the word being documented." }
442 { $examples
443     { $markup-example
444         { { $values { "seq" "a mutable sequence" } } { $side-effects "seq" } }
445     }
446 } ;
447
448 HELP: $notes
449 { $values { "element" "a markup element" } }
450 { $description "Prints the notes subheading found on the help page of some words. This section should document usage tips and pitfalls." } ;
451
452 HELP: $see
453 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
454 { $description "Prints the definition of " { $snippet "word" } " by calling " { $link see } "." }
455 { $examples
456     { $markup-example { "Here is a word definition:" { $see reverse } } }
457 } ;
458
459 HELP: $definition
460 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
461 { $description "Prints a heading followed by the definition of " { $snippet "word" } " by calling " { $link see } "." } ;
462
463 HELP: $curious
464 { $values { "element" "a markup element" } }
465 { $description "Prints a heading followed by a markup element." }
466 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
467
468 HELP: $references
469 { $values { "element" "a markup element of the form " { $snippet "{ topic... }" } } }
470 { $description "Prints a heading followed by a series of links." }
471 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
472
473 HELP: HELP:
474 { $syntax "HELP: word content... ;" }
475 { $values { "word" "a word" } { "content" "markup elements" } }
476 { $description "Defines documentation for a word." }
477 { $examples
478     { $code
479         ": foo 2 + ;"
480         "HELP: foo"
481         "{ $values { \"m\" \"an integer\" } { \"n\" \"an integer\" } }"
482         "{ $description \"Increments a value by 2.\" } ;"
483         "\\ foo help"
484     }
485 } ;
486
487 HELP: ARTICLE:
488 { $syntax "ARTICLE: topic title content... ;" }
489 { $values { "topic" "an object" } { "title" "a string" } { "content" "markup elements" } }
490 { $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\" }" } "." }
491 { $examples
492     { $code
493         "ARTICLE: \"example\" \"An example article\""
494         "\"Hello world.\" ;"
495     }
496 } ;
497
498 HELP: ABOUT:
499 { $syntax "ABOUT: article" }
500 { $values { "article" "a help article" } }
501 { $description "Defines the main documentation article for the current vocabulary." } ;
502
503 HELP: vocab-help
504 { $values { "vocab-spec" "a vocabulary specifier" } { "help" "a help article" } }
505 { $description "Outputs the main help article for a vocabulary. The main help article can be set with " { $link POSTPONE: ABOUT:  } "." } ;