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