]> gitweb.factorcode.org Git - factor.git/blob - extra/help/help-docs.factor
f20ce89263dfc5857c085f41c8e1653a282ff6c3
[factor.git] / extra / help / help-docs.factor
1 USING: help.markup help.crossref help.stylesheet help.topics
2 help.syntax definitions io prettyprint inspector 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 "Related words can be cross-referenced:"
88 { $subsection related-words }
89 { $see-also "help.lint" } ;
90
91 ARTICLE: "help-impl" "Help system implementation"
92 "Help topic protocol:"
93 { $subsection article-name }
94 { $subsection article-title }
95 { $subsection article-content }
96 { $subsection article-parent }
97 { $subsection set-article-parent }
98 "Boilerplate word help can be automatically generated (for example, slot accessor help):"
99 { $subsection word-help }
100 { $subsection word-help* }
101 "Help article implementation:"
102 { $subsection article }
103 { $subsection articles }
104 "Links:"
105 { $subsection link }
106 { $subsection >link }
107 "Utilities for traversing markup element trees:"
108 { $subsection elements }
109 { $subsection collect-elements }
110 "Links and " { $link article } " instances implement the definition protocol; refer to " { $link "definitions" } "." ;
111
112 ARTICLE: "help" "Help system"
113 "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."
114 { $subsection "browsing-help" }
115 { $subsection "writing-help" }
116 { $vocab-subsection "Help lint tool" "help.lint" }
117 { $subsection "help-impl" } ;
118
119 IN: help
120 ABOUT: "help"
121
122 HELP: $title
123 { $values { "topic" "a help article name or a word" } }
124 { $description "Prints a help article's title, or a word's " { $link summary } ", depending on the type of " { $snippet "topic" } "." } ;
125
126 HELP: help
127 { $values { "topic" "an article name or a word" } }
128 { $description
129     "Displays a help article or documentation associated to a word on " { $link output-stream } "."
130 } ;
131
132 HELP: about
133 { $values { "vocab" "a vocabulary specifier" } }
134 { $description
135     "Displays the main help article for the vocabulary. The main help article is set with the " { $link POSTPONE: ABOUT: } " parsing word."
136 } ;
137
138 HELP: :help
139 { $description "Displays documentation for the most recent error." } ;
140
141 HELP: $subsection
142 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
143 { $description "Prints a large clickable link to the help topic named by the first string element of " { $snippet "element" } "." }
144 { $examples
145     { $code "{ $subsection \"sequences\" }" }
146 } ;
147
148 HELP: $index
149 { $values { "element" "a markup element containing one quotation with stack effect " { $snippet "( quot -- )" } } }
150 { $description "Calls the quotation to generate a sequence of help topics, and outputs a " { $link $subsection } " for each one." } ;
151
152 HELP: ($index)
153 { $values { "articles" "a sequence of help articles" } }
154 { $description "Writes a list of " { $link $subsection } " elements to " { $link output-stream } "." } ;
155
156 HELP: xref-help
157 { $description "Update help cross-referencing. Usually this is done automatically." } ;
158
159 HELP: sort-articles
160 { $values { "seq" "a sequence of help topics" } { "newseq" "a sequence of help topics" } }
161 { $description "Sorts a sequence of help topics." } ;
162
163 { article-children article-parent xref-help } related-words
164
165 HELP: $predicate
166 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
167 { $description "Prints the boilerplate description of a class membership predicate word such as " { $link array? } " or " { $link integer? } "." } ;
168
169 HELP: print-element
170 { $values { "element" "a markup element" } }
171 { $description "Prints a markup element to " { $link output-stream } "." } ;
172
173 HELP: print-content
174 { $values { "element" "a markup element" } }
175 { $description "Prints a top-level markup element to " { $link output-stream } "." } ;
176
177 HELP: simple-element
178 { $class-description "Class of simple elements, which are just arrays of elements." } ;
179
180 HELP: ($span)
181 { $values { "quot" "a quotation" } }
182 { $description "Prints an inline markup element." } ;
183
184 HELP: ($block)
185 { $values { "quot" "a quotation" } }
186 { $description "Prints a block markup element with newlines before and after." } ;
187
188 HELP: $heading
189 { $values { "element" "a markup element" } }
190 { $description "Prints a markup element, usually a string, as a block with the " { $link heading-style } "." }
191 { $examples
192     { $markup-example { $heading "What remains to be discovered" } }
193 } ;
194
195 HELP: $subheading
196 { $values { "element" "a markup element of the form " { $snippet "{ title content }" } } }
197 { $description "Prints a markup element, usually a string, as a block with the " { $link strong-style } "." }
198 { $examples
199     { $markup-example { $subheading "Developers, developers, developers!" } }
200 } ;
201
202 HELP: $code
203 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
204 { $description "Prints code examples, as seen in many help articles. The markup element must be an array of strings." }
205 { $notes
206     "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."
207     $nl
208     "If you want to show code along with sample output, use the " { $link $example } " element."
209 }
210 { $examples
211     { $markup-example { $code "2 2 + ." } }
212 } ;
213
214 HELP: $vocabulary
215 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
216 { $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." } ;
217
218 HELP: $description
219 { $values { "element" "a markup element" } }
220 { $description "Prints the description subheading found on the help page of most words." } ;
221
222 HELP: $contract
223 { $values { "element" "a markup element" } }
224 { $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." }
225 { $examples
226     { $markup-example { $contract "Methods of this generic word must always crash." } }
227 } ;
228
229 HELP: $examples
230 { $values { "element" "a markup element" } }
231 { $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." }
232 { $examples
233     { $markup-example { $examples { $example "USING: math prettyprint ;" "2 2 + ." "4" } } }
234 } ;
235
236 HELP: $example
237 { $values { "element" "a markup element of the form " { $snippet "{ inputs... output }" } } }
238 { $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." }
239 { $examples
240     "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:"
241     { $markup-example { $unchecked-example "2 2 +" "4" } }
242     "However the following is right:"
243     { $markup-example { $example "USING: math prettyprint ;" "2 2 + ." "4" } }
244     "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."
245 } ;
246
247 HELP: $markup-example
248 { $values { "element" "a markup element" } }
249 { $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." }
250 { $examples
251     { $markup-example { $markup-example { $emphasis "Hi" } } }
252 } ;
253
254 HELP: $warning
255 { $values { "element" "a markup element" } }
256 { $description "Prints an element inset in a block styled as so to draw the reader's attention towards it." }
257 { $examples
258     { $markup-example { $warning "Incorrect use of this product may cause serious injury or death." } }
259 } ;
260
261 HELP: $link
262 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
263 { $description "Prints a link to a help article or word." }
264 { $examples
265     { $markup-example { $link "dlists" } }
266     { $markup-example { $link + } }
267 } ;
268
269 HELP: textual-list
270 { $values { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } }
271 { $description "Applies the quotation to each element of the sequence, printing a comma between each pair of elements." }
272 { $examples
273     { $example "USING: help.markup io ;" "{ \"fish\" \"chips\" \"salt\" } [ write ] textual-list" "fish, chips, salt" }
274 } ;
275
276 HELP: $links
277 { $values { "topics" "a sequence of article names or words" } }
278 { $description "Prints a series of links to help articles or word documentation." }
279 { $notes "This markup element is used to implement " { $link $links } "." }
280 { $examples
281     { $markup-example { $links + - * / } }
282 } ;
283
284 HELP: $see-also
285 { $values { "topics" "a sequence of article names or words" } }
286 { $description "Prints a heading followed by a series of links." }
287 { $examples
288     { $markup-example { $see-also "graphs" "dlists" } }
289 } ;
290
291 { $see-also $related related-words } related-words
292
293 HELP: $table
294 { $values { "element" "an array of arrays of markup elements" } }
295 { $description "Prints a table given as an array of rows, where each row must have the same number of columns." }
296 { $examples
297     { $markup-example
298         { $table
299             { "a" "b" "c" }
300             { "d" "e" "f" }
301         }
302     }
303 } ;
304
305 HELP: $values
306 { $values { "element" "an array of pairs of markup elements" } }
307 { $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." } ;
308
309 HELP: $list
310 { $values { "element" "an array of markup elements" } }
311 { $description "Prints a bulleted list of markup elements." }
312 { $notes
313     "A common mistake is that if an item consists of more than just a string, it will be broken up as several items:"
314     { $markup-example
315         { $list
316             "First item"
317             "Second item " { $emphasis "with emphasis" }
318         }
319     }
320     "The fix is easy; just group the two markup elements making up the second item into one markup element:"
321     { $markup-example
322         { $list
323             "First item"
324             { "Second item " { $emphasis "with emphasis" } }
325         }
326     }
327 } ;
328
329 HELP: $errors
330 { $values { "element" "a markup element" } }
331 { $description "Prints the errors subheading found on the help page of some words. This section should document any errors thrown by the word." }
332 { $examples
333     { $markup-example { $errors "I/O errors, network errors, hardware errors... oh my!" } }
334 } ;
335
336 HELP: $side-effects
337 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
338 { $description "Prints a heading followed by a list of input values or variables which are modified by the word being documented." }
339 { $examples
340     { $markup-example
341         { { $values { "seq" "a mutable sequence" } } { $side-effects "seq" } }
342     }
343 } ;
344
345 HELP: $notes
346 { $values { "element" "a markup element" } }
347 { $description "Prints the notes subheading found on the help page of some words. This section should document usage tips and pitfalls." } ;
348
349 HELP: $see
350 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
351 { $description "Prints the definition of " { $snippet "word" } " by calling " { $link see } "." }
352 { $examples
353     { $markup-example { "Here is a word definition:" { $see reverse } } }
354 } ;
355
356 HELP: $definition
357 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
358 { $description "Prints a heading followed by the definition of " { $snippet "word" } " by calling " { $link see } "." } ;
359
360 HELP: $curious
361 { $values { "element" "a markup element" } }
362 { $description "Prints a heading followed by a markup element." }
363 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
364
365 HELP: $references
366 { $values { "element" "a markup element of the form " { $snippet "{ topic... }" } } }
367 { $description "Prints a heading followed by a series of links." }
368 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
369
370 HELP: HELP:
371 { $syntax "HELP: word content... ;" }
372 { $values { "word" "a word" } { "content" "markup elements" } }
373 { $description "Defines documentation for a word." }
374 { $examples
375     { $code
376         ": foo 2 + ;"
377         "HELP: foo"
378         "{ $values { \"m\" \"an integer\" } { \"n\" \"an integer\" } }"
379         "{ $description \"Increments a value by 2.\" } ;"
380         "\\ foo help"
381     }
382 } ;
383
384 HELP: ARTICLE:
385 { $syntax "ARTICLE: topic title content... ;" }
386 { $values { "topic" "an object" } { "title" "a string" } { "content" "markup elements" } }
387 { $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\" }" } "." }
388 { $examples
389     { $code
390         "ARTICLE: \"example\" \"An example article\""
391         "\"Hello world.\" ;"
392     }
393 } ;
394
395 HELP: ABOUT:
396 { $syntax "MAIN: article" }
397 { $values { "article" "a help article" } }
398 { $description "Defines the main documentation article for the current vocabulary." } ;
399
400 HELP: vocab-help
401 { $values { "vocab" "a vocabulary specifier" } { "help" "a help article" } }
402 { $description "Outputs the main help article for a vocabulary. The main help article can be set with " { $link POSTPONE: ABOUT:  } "." } ;