blob: a9194687976ddad17e813ec5d8c94f65e9acbb83 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. highlightlang:: rest
2
3Additional Markup Constructs
4============================
5
6Sphinx adds a lot of new directives and interpreted text roles to standard reST
7markup. This section contains the reference material for these facilities.
8Documentation for "standard" reST constructs is not included here, though
9they are used in the Python documentation.
10
Benjamin Petersonf608c612008-11-16 18:33:53 +000011.. note::
Georg Brandl116aa622007-08-15 14:28:22 +000012
Benjamin Petersonf608c612008-11-16 18:33:53 +000013 This is just an overview of Sphinx' extended markup capabilities; full
14 coverage can be found in `its own documentation
15 <http://sphinx.pocoo.org/contents.html>`_.
Georg Brandl116aa622007-08-15 14:28:22 +000016
17
18Meta-information markup
19-----------------------
20
21.. describe:: sectionauthor
22
23 Identifies the author of the current section. The argument should include
24 the author's name such that it can be used for presentation (though it isn't)
25 and email address. The domain name portion of the address should be lower
26 case. Example::
27
28 .. sectionauthor:: Guido van Rossum <guido@python.org>
29
30 Currently, this markup isn't reflected in the output in any way, but it helps
31 keep track of contributions.
32
33
34Module-specific markup
35----------------------
36
37The markup described in this section is used to provide information about a
38module being documented. Each module should be documented in its own file.
39Normally this markup appears after the title heading of that file; a typical
40file might start like this::
41
42 :mod:`parrot` -- Dead parrot access
43 ===================================
44
45 .. module:: parrot
46 :platform: Unix, Windows
47 :synopsis: Analyze and reanimate dead parrots.
48 .. moduleauthor:: Eric Cleese <eric@python.invalid>
49 .. moduleauthor:: John Idle <john@python.invalid>
50
51As you can see, the module-specific markup consists of two directives, the
52``module`` directive and the ``moduleauthor`` directive.
53
54.. describe:: module
55
Brett Cannondf501062009-01-20 02:09:18 +000056 This directive marks the beginning of the description of a module, package,
57 or submodule. The name should be fully qualified (i.e. including the
58 package name for submodules).
Georg Brandl116aa622007-08-15 14:28:22 +000059
60 The ``platform`` option, if present, is a comma-separated list of the
61 platforms on which the module is available (if it is available on all
62 platforms, the option should be omitted). The keys are short identifiers;
63 examples that are in use include "IRIX", "Mac", "Windows", and "Unix". It is
64 important to use a key which has already been used when applicable.
65
66 The ``synopsis`` option should consist of one sentence describing the
67 module's purpose -- it is currently only used in the Global Module Index.
68
Guido van Rossumda27fd22007-08-17 00:24:54 +000069 The ``deprecated`` option can be given (with no value) to mark a module as
70 deprecated; it will be designated as such in various locations then.
71
Georg Brandl116aa622007-08-15 14:28:22 +000072.. describe:: moduleauthor
73
74 The ``moduleauthor`` directive, which can appear multiple times, names the
75 authors of the module code, just like ``sectionauthor`` names the author(s)
76 of a piece of documentation. It too does not result in any output currently.
77
Georg Brandl116aa622007-08-15 14:28:22 +000078.. note::
79
80 It is important to make the section title of a module-describing file
81 meaningful since that value will be inserted in the table-of-contents trees
82 in overview files.
83
84
85Information units
86-----------------
87
88There are a number of directives used to describe specific features provided by
89modules. Each directive requires one or more signatures to provide basic
90information about what is being described, and the content should be the
91description. The basic version makes entries in the general index; if no index
92entry is desired, you can give the directive option flag ``:noindex:``. The
93following example shows all of the features of this directive type::
94
95 .. function:: spam(eggs)
96 ham(eggs)
97 :noindex:
98
99 Spam or ham the foo.
100
101The signatures of object methods or data attributes should always include the
102type name (``.. method:: FileInput.input(...)``), even if it is obvious from the
103context which type they belong to; this is to enable consistent
104cross-references. If you describe methods belonging to an abstract protocol,
105such as "context managers", include a (pseudo-)type name too to make the
106index entries more informative.
107
108The directives are:
109
110.. describe:: cfunction
111
112 Describes a C function. The signature should be given as in C, e.g.::
113
114 .. cfunction:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
115
116 This is also used to describe function-like preprocessor macros. The names
117 of the arguments should be given so they may be used in the description.
118
119 Note that you don't have to backslash-escape asterisks in the signature,
120 as it is not parsed by the reST inliner.
121
122.. describe:: cmember
123
124 Describes a C struct member. Example signature::
125
126 .. cmember:: PyObject* PyTypeObject.tp_bases
127
128 The text of the description should include the range of values allowed, how
129 the value should be interpreted, and whether the value can be changed.
130 References to structure members in text should use the ``member`` role.
131
132.. describe:: cmacro
133
134 Describes a "simple" C macro. Simple macros are macros which are used
135 for code expansion, but which do not take arguments so cannot be described as
136 functions. This is not to be used for simple constant definitions. Examples
137 of its use in the Python documentation include :cmacro:`PyObject_HEAD` and
138 :cmacro:`Py_BEGIN_ALLOW_THREADS`.
139
140.. describe:: ctype
141
142 Describes a C type. The signature should just be the type name.
143
144.. describe:: cvar
145
146 Describes a global C variable. The signature should include the type, such
147 as::
148
149 .. cvar:: PyObject* PyClass_Type
150
151.. describe:: data
152
153 Describes global data in a module, including both variables and values used
154 as "defined constants." Class and object attributes are not documented
155 using this environment.
156
157.. describe:: exception
158
159 Describes an exception class. The signature can, but need not include
160 parentheses with constructor arguments.
161
162.. describe:: function
163
164 Describes a module-level function. The signature should include the
165 parameters, enclosing optional parameters in brackets. Default values can be
166 given if it enhances clarity. For example::
167
168 .. function:: Timer.repeat([repeat=3[, number=1000000]])
169
170 Object methods are not documented using this directive. Bound object methods
171 placed in the module namespace as part of the public interface of the module
172 are documented using this, as they are equivalent to normal functions for
173 most purposes.
174
175 The description should include information about the parameters required and
176 how they are used (especially whether mutable objects passed as parameters
177 are modified), side effects, and possible exceptions. A small example may be
178 provided.
179
180.. describe:: class
181
182 Describes a class. The signature can include parentheses with parameters
183 which will be shown as the constructor arguments.
184
185.. describe:: attribute
186
187 Describes an object data attribute. The description should include
188 information about the type of the data to be expected and whether it may be
189 changed directly.
190
191.. describe:: method
192
193 Describes an object method. The parameters should not include the ``self``
194 parameter. The description should include similar information to that
195 described for ``function``.
196
197.. describe:: opcode
198
Georg Brandl9afde1c2007-11-01 20:32:30 +0000199 Describes a Python :term:`bytecode` instruction.
200
201.. describe:: cmdoption
202
203 Describes a command line option or switch. Option argument names should be
204 enclosed in angle brackets. Example::
205
206 .. cmdoption:: -m <module>
207
208 Run a module as a script.
209
210.. describe:: envvar
211
212 Describes an environment variable that Python uses or defines.
Georg Brandl116aa622007-08-15 14:28:22 +0000213
214
215There is also a generic version of these directives:
216
217.. describe:: describe
218
219 This directive produces the same formatting as the specific ones explained
220 above but does not create index entries or cross-referencing targets. It is
221 used, for example, to describe the directives in this document. Example::
222
223 .. describe:: opcode
224
225 Describes a Python bytecode instruction.
226
227
228Showing code examples
229---------------------
230
231Examples of Python source code or interactive sessions are represented using
232standard reST literal blocks. They are started by a ``::`` at the end of the
233preceding paragraph and delimited by indentation.
234
235Representing an interactive session requires including the prompts and output
236along with the Python code. No special markup is required for interactive
237sessions. After the last line of input or output presented, there should not be
238an "unused" primary prompt; this is an example of what *not* to do::
239
240 >>> 1 + 1
241 2
242 >>>
243
244Syntax highlighting is handled in a smart way:
245
246* There is a "highlighting language" for each source file. Per default,
247 this is ``'python'`` as the majority of files will have to highlight Python
248 snippets.
249
250* Within Python highlighting mode, interactive sessions are recognized
251 automatically and highlighted appropriately.
252
253* The highlighting language can be changed using the ``highlightlang``
254 directive, used as follows::
255
256 .. highlightlang:: c
257
258 This language is used until the next ``highlightlang`` directive is
259 encountered.
260
Benjamin Petersonf608c612008-11-16 18:33:53 +0000261* The values normally used for the highlighting language are:
Georg Brandl116aa622007-08-15 14:28:22 +0000262
263 * ``python`` (the default)
264 * ``c``
265 * ``rest``
266 * ``none`` (no highlighting)
267
268* If highlighting with the current language fails, the block is not highlighted
269 in any way.
270
271Longer displays of verbatim text may be included by storing the example text in
272an external file containing only plain text. The file may be included using the
273``literalinclude`` directive. [1]_ For example, to include the Python source file
274:file:`example.py`, use::
275
276 .. literalinclude:: example.py
277
278The file name is relative to the current file's path. Documentation-specific
279include files should be placed in the ``Doc/includes`` subdirectory.
280
281
282Inline markup
283-------------
284
285As said before, Sphinx uses interpreted text roles to insert semantic markup in
286documents.
287
Benjamin Petersonaa069002009-01-23 03:26:36 +0000288Names of local variables, such as function/method arguments, are an exception,
289they should be marked simply with ``*var*``.
Georg Brandl116aa622007-08-15 14:28:22 +0000290
291For all other roles, you have to write ``:rolename:`content```.
292
Guido van Rossumf10aa982007-08-17 18:30:38 +0000293.. note::
294
295 For all cross-referencing roles, if you prefix the content with ``!``, no
296 reference/hyperlink will be created.
297
Georg Brandl116aa622007-08-15 14:28:22 +0000298The following roles refer to objects in modules and are possibly hyperlinked if
299a matching identifier is found:
300
301.. describe:: mod
302
303 The name of a module; a dotted name may be used. This should also be used for
304 package names.
305
306.. describe:: func
307
308 The name of a Python function; dotted names may be used. The role text
Christian Heimesa342c012008-04-20 21:01:16 +0000309 should not include trailing parentheses to enhance readability. The
310 parentheses are stripped when searching for identifiers.
Georg Brandl116aa622007-08-15 14:28:22 +0000311
312.. describe:: data
313
Benjamin Petersonaa069002009-01-23 03:26:36 +0000314 The name of a module-level variable or constant.
Georg Brandl116aa622007-08-15 14:28:22 +0000315
316.. describe:: const
317
318 The name of a "defined" constant. This may be a C-language ``#define``
319 or a Python variable that is not intended to be changed.
320
321.. describe:: class
322
323 A class name; a dotted name may be used.
324
325.. describe:: meth
326
327 The name of a method of an object. The role text should include the type
Christian Heimesa342c012008-04-20 21:01:16 +0000328 name and the method name. A dotted name may be used.
Georg Brandl116aa622007-08-15 14:28:22 +0000329
330.. describe:: attr
331
332 The name of a data attribute of an object.
333
334.. describe:: exc
335
336 The name of an exception. A dotted name may be used.
337
338The name enclosed in this markup can include a module name and/or a class name.
339For example, ``:func:`filter``` could refer to a function named ``filter`` in
340the current module, or the built-in function of that name. In contrast,
341``:func:`foo.filter``` clearly refers to the ``filter`` function in the ``foo``
342module.
343
Guido van Rossumda27fd22007-08-17 00:24:54 +0000344Normally, names in these roles are searched first without any further
345qualification, then with the current module name prepended, then with the
346current module and class name (if any) prepended. If you prefix the name with a
347dot, this order is reversed. For example, in the documentation of the
348:mod:`codecs` module, ``:func:`open``` always refers to the built-in function,
349while ``:func:`.open``` refers to :func:`codecs.open`.
350
Georg Brandl116aa622007-08-15 14:28:22 +0000351A similar heuristic is used to determine whether the name is an attribute of
352the currently documented class.
353
354The following roles create cross-references to C-language constructs if they
355are defined in the API documentation:
356
357.. describe:: cdata
358
359 The name of a C-language variable.
360
361.. describe:: cfunc
362
363 The name of a C-language function. Should include trailing parentheses.
364
365.. describe:: cmacro
366
367 The name of a "simple" C macro, as defined above.
368
369.. describe:: ctype
370
371 The name of a C-language type.
372
373
374The following role does possibly create a cross-reference, but does not refer
375to objects:
376
377.. describe:: token
378
379 The name of a grammar token (used in the reference manual to create links
380 between production displays).
381
Guido van Rossumf10aa982007-08-17 18:30:38 +0000382
383The following role creates a cross-reference to the term in the glossary:
384
385.. describe:: term
386
387 Reference to a term in the glossary. The glossary is created using the
388 ``glossary`` directive containing a definition list with terms and
389 definitions. It does not have to be in the same file as the ``term``
390 markup, in fact, by default the Python docs have one global glossary
391 in the ``glossary.rst`` file.
392
393 If you use a term that's not explained in a glossary, you'll get a warning
394 during build.
395
Georg Brandl116aa622007-08-15 14:28:22 +0000396---------
397
398The following roles don't do anything special except formatting the text
399in a different style:
400
401.. describe:: command
402
403 The name of an OS-level command, such as ``rm``.
404
405.. describe:: dfn
406
407 Mark the defining instance of a term in the text. (No index entries are
408 generated.)
409
410.. describe:: envvar
411
412 An environment variable. Index entries are generated.
413
414.. describe:: file
415
416 The name of a file or directory. Within the contents, you can use curly
417 braces to indicate a "variable" part, for example::
418
419 ... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
420
421 In the built documentation, the ``x`` will be displayed differently to
422 indicate that it is to be replaced by the Python minor version.
423
424.. describe:: guilabel
425
426 Labels presented as part of an interactive user interface should be marked
427 using ``guilabel``. This includes labels from text-based interfaces such as
428 those created using :mod:`curses` or other text-based libraries. Any label
429 used in the interface should be marked with this role, including button
430 labels, window titles, field names, menu and menu selection names, and even
431 values in selection lists.
432
433.. describe:: kbd
434
435 Mark a sequence of keystrokes. What form the key sequence takes may depend
436 on platform- or application-specific conventions. When there are no relevant
437 conventions, the names of modifier keys should be spelled out, to improve
438 accessibility for new users and non-native speakers. For example, an
439 *xemacs* key sequence may be marked like ``:kbd:`C-x C-f```, but without
440 reference to a specific application or platform, the same sequence should be
441 marked as ``:kbd:`Control-x Control-f```.
442
443.. describe:: keyword
444
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000445 The name of a keyword in Python.
Georg Brandl116aa622007-08-15 14:28:22 +0000446
447.. describe:: mailheader
448
449 The name of an RFC 822-style mail header. This markup does not imply that
450 the header is being used in an email message, but can be used to refer to any
451 header of the same "style." This is also used for headers defined by the
452 various MIME specifications. The header name should be entered in the same
453 way it would normally be found in practice, with the camel-casing conventions
454 being preferred where there is more than one common usage. For example:
455 ``:mailheader:`Content-Type```.
456
457.. describe:: makevar
458
459 The name of a :command:`make` variable.
460
461.. describe:: manpage
462
463 A reference to a Unix manual page including the section,
464 e.g. ``:manpage:`ls(1)```.
465
466.. describe:: menuselection
467
468 Menu selections should be marked using the ``menuselection`` role. This is
469 used to mark a complete sequence of menu selections, including selecting
470 submenus and choosing a specific operation, or any subsequence of such a
471 sequence. The names of individual selections should be separated by
472 ``-->``.
473
474 For example, to mark the selection "Start > Programs", use this markup::
475
476 :menuselection:`Start --> Programs`
477
478 When including a selection that includes some trailing indicator, such as the
479 ellipsis some operating systems use to indicate that the command opens a
480 dialog, the indicator should be omitted from the selection name.
481
482.. describe:: mimetype
483
484 The name of a MIME type, or a component of a MIME type (the major or minor
485 portion, taken alone).
486
487.. describe:: newsgroup
488
489 The name of a Usenet newsgroup.
490
491.. describe:: option
492
493 A command-line option to an executable program. The leading hyphen(s) must
494 be included.
495
496.. describe:: program
497
498 The name of an executable program. This may differ from the file name for
499 the executable for some platforms. In particular, the ``.exe`` (or other)
500 extension should be omitted for Windows programs.
501
502.. describe:: regexp
503
504 A regular expression. Quotes should not be included.
505
506.. describe:: samp
507
508 A piece of literal text, such as code. Within the contents, you can use
509 curly braces to indicate a "variable" part, as in ``:file:``.
510
511 If you don't need the "variable part" indication, use the standard
Georg Brandl48310cd2009-01-03 21:18:54 +0000512 ````code```` instead.
Georg Brandl116aa622007-08-15 14:28:22 +0000513
514.. describe:: var
515
516 A Python or C variable or parameter name.
517
518
519The following roles generate external links:
520
521.. describe:: pep
522
523 A reference to a Python Enhancement Proposal. This generates appropriate
524 index entries. The text "PEP *number*\ " is generated; in the HTML output,
525 this text is a hyperlink to an online copy of the specified PEP.
526
527.. describe:: rfc
528
529 A reference to an Internet Request for Comments. This generates appropriate
530 index entries. The text "RFC *number*\ " is generated; in the HTML output,
531 this text is a hyperlink to an online copy of the specified RFC.
532
533
534Note that there are no special roles for including hyperlinks as you can use
535the standard reST markup for that purpose.
536
537
538.. _doc-ref-role:
539
540Cross-linking markup
541--------------------
542
543To support cross-referencing to arbitrary sections in the documentation, the
544standard reST labels are "abused" a bit: Every label must precede a section
545title; and every label name must be unique throughout the entire documentation
546source.
547
548You can then reference to these sections using the ``:ref:`label-name``` role.
549
550Example::
551
552 .. _my-reference-label:
553
554 Section to cross-reference
555 --------------------------
556
557 This is the text of the section.
558
559 It refers to the section itself, see :ref:`my-reference-label`.
560
561The ``:ref:`` invocation is replaced with the section title.
562
563
564Paragraph-level markup
565----------------------
566
567These directives create short paragraphs and can be used inside information
568units as well as normal text:
569
570.. describe:: note
571
572 An especially important bit of information about an API that a user should be
573 aware of when using whatever bit of API the note pertains to. The content of
574 the directive should be written in complete sentences and include all
575 appropriate punctuation.
576
577 Example::
578
579 .. note::
580
581 This function is not suitable for sending spam e-mails.
582
583.. describe:: warning
584
585 An important bit of information about an API that a user should be very aware
586 of when using whatever bit of API the warning pertains to. The content of
587 the directive should be written in complete sentences and include all
588 appropriate punctuation. This differs from ``note`` in that it is recommended
589 over ``note`` for information regarding security.
590
591.. describe:: versionadded
592
593 This directive documents the version of Python which added the described
594 feature to the library or C API. When this applies to an entire module, it
595 should be placed at the top of the module section before any prose.
596
597 The first argument must be given and is the version in question; you can add
598 a second argument consisting of a *brief* explanation of the change.
599
600 Example::
601
Georg Brandl277a1502009-01-04 00:28:14 +0000602 .. versionadded:: 3.1
Georg Brandl36ab1ef2009-01-03 21:17:04 +0000603 The *spam* parameter.
Georg Brandl116aa622007-08-15 14:28:22 +0000604
605 Note that there must be no blank line between the directive head and the
606 explanation; this is to make these blocks visually continuous in the markup.
607
608.. describe:: versionchanged
609
610 Similar to ``versionadded``, but describes when and what changed in the named
611 feature in some way (new parameters, changed side effects, etc.).
612
613--------------
614
615.. describe:: seealso
616
617 Many sections include a list of references to module documentation or
618 external documents. These lists are created using the ``seealso`` directive.
619
620 The ``seealso`` directive is typically placed in a section just before any
621 sub-sections. For the HTML output, it is shown boxed off from the main flow
622 of the text.
623
624 The content of the ``seealso`` directive should be a reST definition list.
625 Example::
626
627 .. seealso::
628
629 Module :mod:`zipfile`
630 Documentation of the :mod:`zipfile` standard module.
631
632 `GNU tar manual, Basic Tar Format <http://link>`_
633 Documentation for tar archive files, including GNU tar extensions.
634
635.. describe:: rubric
636
637 This directive creates a paragraph heading that is not used to create a
638 table of contents node. It is currently used for the "Footnotes" caption.
639
640.. describe:: centered
641
642 This directive creates a centered boldfaced paragraph. Use it as follows::
643
644 .. centered::
645
646 Paragraph contents.
647
648
649Table-of-contents markup
650------------------------
651
652Since reST does not have facilities to interconnect several documents, or split
653documents into multiple output files, Sphinx uses a custom directive to add
654relations between the single files the documentation is made of, as well as
655tables of contents. The ``toctree`` directive is the central element.
656
657.. describe:: toctree
658
659 This directive inserts a "TOC tree" at the current location, using the
660 individual TOCs (including "sub-TOC trees") of the files given in the
661 directive body. A numeric ``maxdepth`` option may be given to indicate the
662 depth of the tree; by default, all levels are included.
663
664 Consider this example (taken from the library reference index)::
665
666 .. toctree::
667 :maxdepth: 2
668
669 intro.rst
670 strings.rst
671 datatypes.rst
672 numeric.rst
673 (many more files listed here)
674
675 This accomplishes two things:
676
677 * Tables of contents from all those files are inserted, with a maximum depth
678 of two, that means one nested heading. ``toctree`` directives in those
679 files are also taken into account.
680 * Sphinx knows that the relative order of the files ``intro.rst``,
681 ``strings.rst`` and so forth, and it knows that they are children of the
682 shown file, the library index. From this information it generates "next
683 chapter", "previous chapter" and "parent chapter" links.
684
685 In the end, all files included in the build process must occur in one
686 ``toctree`` directive; Sphinx will emit a warning if it finds a file that is
687 not included, because that means that this file will not be reachable through
688 standard navigation.
689
690 The special file ``contents.rst`` at the root of the source directory is the
691 "root" of the TOC tree hierarchy; from it the "Contents" page is generated.
692
693
694Index-generating markup
695-----------------------
696
697Sphinx automatically creates index entries from all information units (like
698functions, classes or attributes) like discussed before.
699
700However, there is also an explicit directive available, to make the index more
701comprehensive and enable index entries in documents where information is not
702mainly contained in information units, such as the language reference.
703
704The directive is ``index`` and contains one or more index entries. Each entry
705consists of a type and a value, separated by a colon.
706
707For example::
708
709 .. index::
Thomas Wouters89d996e2007-09-08 17:39:28 +0000710 single: execution; context
Georg Brandl116aa622007-08-15 14:28:22 +0000711 module: __main__
712 module: sys
713 triple: module; search; path
714
715This directive contains five entries, which will be converted to entries in the
716generated index which link to the exact location of the index statement (or, in
717case of offline media, the corresponding page number).
718
719The possible entry types are:
720
721single
722 Creates a single index entry. Can be made a subentry by separating the
Thomas Wouters89d996e2007-09-08 17:39:28 +0000723 subentry text with a semicolon (this notation is also used below to describe
724 what entries are created).
Georg Brandl116aa622007-08-15 14:28:22 +0000725pair
726 ``pair: loop; statement`` is a shortcut that creates two index entries,
727 namely ``loop; statement`` and ``statement; loop``.
728triple
729 Likewise, ``triple: module; search; path`` is a shortcut that creates three
730 index entries, which are ``module; search path``, ``search; path, module`` and
731 ``path; module search``.
732module, keyword, operator, object, exception, statement, builtin
733 These all create two index entries. For example, ``module: hashlib`` creates
734 the entries ``module; hashlib`` and ``hashlib; module``.
735
Thomas Wouters89d996e2007-09-08 17:39:28 +0000736For index directives containing only "single" entries, there is a shorthand
737notation::
738
739 .. index:: BNF, grammar, syntax, notation
740
741This creates four index entries.
742
Georg Brandl116aa622007-08-15 14:28:22 +0000743
744Grammar production displays
745---------------------------
746
747Special markup is available for displaying the productions of a formal grammar.
748The markup is simple and does not attempt to model all aspects of BNF (or any
749derived forms), but provides enough to allow context-free grammars to be
750displayed in a way that causes uses of a symbol to be rendered as hyperlinks to
751the definition of the symbol. There is this directive:
752
753.. describe:: productionlist
754
755 This directive is used to enclose a group of productions. Each production is
756 given on a single line and consists of a name, separated by a colon from the
757 following definition. If the definition spans multiple lines, each
758 continuation line must begin with a colon placed at the same column as in the
759 first line.
760
761 Blank lines are not allowed within ``productionlist`` directive arguments.
762
763 The definition can contain token names which are marked as interpreted text
Georg Brandl36ab1ef2009-01-03 21:17:04 +0000764 (e.g. ``unaryneg ::= "-" `integer```) -- this generates cross-references
Georg Brandl116aa622007-08-15 14:28:22 +0000765 to the productions of these tokens.
766
767 Note that no further reST parsing is done in the production, so that you
768 don't have to escape ``*`` or ``|`` characters.
769
770
Georg Brandl48310cd2009-01-03 21:18:54 +0000771.. XXX describe optional first parameter
Georg Brandl116aa622007-08-15 14:28:22 +0000772
773The following is an example taken from the Python Reference Manual::
774
775 .. productionlist::
776 try_stmt: try1_stmt | try2_stmt
777 try1_stmt: "try" ":" `suite`
778 : ("except" [`expression` ["," `target`]] ":" `suite`)+
779 : ["else" ":" `suite`]
780 : ["finally" ":" `suite`]
781 try2_stmt: "try" ":" `suite`
782 : "finally" ":" `suite`
783
784
785Substitutions
786-------------
787
788The documentation system provides three substitutions that are defined by default.
Benjamin Petersonf608c612008-11-16 18:33:53 +0000789They are set in the build configuration file :file:`conf.py`.
Georg Brandl116aa622007-08-15 14:28:22 +0000790
791.. describe:: |release|
792
793 Replaced by the Python release the documentation refers to. This is the full
794 version string including alpha/beta/release candidate tags, e.g. ``2.5.2b3``.
795
796.. describe:: |version|
797
798 Replaced by the Python version the documentation refers to. This consists
799 only of the major and minor version parts, e.g. ``2.5``, even for version
800 2.5.1.
801
802.. describe:: |today|
803
804 Replaced by either today's date, or the date set in the build configuration
805 file. Normally has the format ``April 14, 2007``.
806
807
808.. rubric:: Footnotes
809
810.. [1] There is a standard ``.. include`` directive, but it raises errors if the
811 file is not found. This one only emits a warning.