5. Roles¶
5.1. Semantic Markup¶
The following module demonstrates how to use roles in docstrings.
The general Waterloo notation inside docstrings is
|role|`par`, that is, the role name in pipe delimiters followed
by a string-valued parameter enclosed in backticks.
Preamble |
normative sections
|
Definitions |
Unicorn A sample definition we need for demonstrating the |
Contract |
general
|
Notes |
Attribute
Class
Command
Definition
File
Function
Key
Label
Literal
Module
Normativity token
Operator
Notes
Package
Tag
Term
Type
URL
Value
Variable
Variable and type
|
| «Module» | doc_roles |
|---|
The Waterloo renderer converts these roles into ordinary reST roles. You can also use these roles in running text. Some of them overlap conceptually with the standard Sphinx role set. It is up to the author to choose the roles that best express the intended meaning. For machine readability, the important part is simply that the Waterloo notation is used inside docstrings.
Rendered |
Code |
|---|---|
|
|
|
|
|
|
abc, ABC |
|
|
|
|
|
|
|
abc, ABC |
|
|
|
|
|
Should, must |
|
|
|
|
|
|
|
|
|
Unicorn |
|
|
|
|
|
|
|
|
|
use_color: bool |
|
5.2. Normativity and value tokens¶
The Waterloo Docstring format offers a fixed set of normativity keywords inspired by RFC 2119. MAY NOT is intentionally omitted because it is semantically ambiguous in this context. The format also defines a small set of values in tokenized form. The following module rendering gives a compact overview of these tokens.
Preamble |
normative sections
|
Contract |
general
|
Description |
Section Description is marked as normative, so that normativity tokens can be demonstrated in regular prose.
|
Notes |
Boolean value tokens
None value token
Self value token
Empty value token
|
| «Module» | doc_normativity_and_value_tokens |
|---|
5.3. Cross referencing¶
The following classes from the module doc_cross_referencing in
${REPO}/examples-python demonstrate the different forms of
cross-references.
- References to other objects within the module
By identifier
By qualified identifier (module + object)
- References to other objects outside the module
By fully qualified identifier (package + module + object)
- References to labels in the surrounding Sphinx document
in the same file
in a different file
References to web pages (HTTP / HTTPS)
References to non-existent targets
Pay attention to how the reference target is written:
|ref|`Label <wtrl://...>`– usewtrl://for Waterloo docstring objects.|ref|`label <http[s]://...>`– usehttp://orhttps://for web pages.|ref|`Label <...>`– omit the scheme for references within the project.
Preamble |
normative sections
|
Contract |
general
constructor |
Notes |
Reference to a documented object (same module)
Reference to a documented object (different module)
Reference to a non-existing object
Reference to a web page
|
| «Class» | A |
|---|
Preamble |
normative sections
|
Contract |
general
constructor |
Notes |
Reference to a documented object
Reference to a location in the document (same source file)
Reference to a non-existing location in the document
Reference to a location in the document (different source file)
|
| «Class» | B |
|---|