Gnatdoc
Gnatdoc
Gnatdoc
Release 22.0w
AdaCore
1 Introduction 3
1.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Launching GNATdoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Command line interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Configuration 13
3.1 Output directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Ignore subprojects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Images directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Documentation pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.5 Custom tags definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.6 HTML output customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
i
ii
GNATdoc User Guide, Release 22.0w
Contents:
CONTENTS 1
GNATdoc User Guide, Release 22.0w
2 CONTENTS
CHAPTER
ONE
INTRODUCTION
GNATdoc is a documentation tool for Ada which processes source files, extracts documentation directly from the
sources, and generates annotated HTML files. It is based on the source cross-reference information (e.g. generated by
GNAT for Ada files). This means that you should ensure that cross-reference information has been generated before
generating the documentation. It also relies on standard comments that it extracts from the source code. The engine in
charge of extracting them coupled with the cross-reference engine gives GNATdoc all the flexibility needed to generate
accurate documentation, and report errors in case of wrong documentation.
1.1 Installation
GNATdoc is shipped as part of the GNAT Studio package. To install it, simply launch the GNAT Studio installer.
After the installation place <gnatstudio_installation_prefix>/bin/ in your PATH environment vari-
able.
GNATdoc is based on the source cross-reference information (e.g. generated by GNAT for Ada files). This means that
you should ensure that cross-reference information has been generated before generating the documentation. For this
purpose, before launching the tool compile your project.
GNATdoc requires your project hierarchy to be described via GNAT project files (.gpr).
To launch GNATdoc, execute:
gnatdoc -P<your_project>
where <your_project> is the .gpr file at the root of your project hierarchy (your root project).
GNATdoc generates an HTML report in the gnatdoc directory of the object directory of the main project.
A brief description of the supported switches is available through the switch –help:
$ gnatdoc --help
GNATdoc command line interface
Usage: gnatdoc [switches] [arguments]
3
GNATdoc User Guide, Release 22.0w
Project (-P)
Specify the path name of the main project file. The space between -P and the project file name is optional.
External reference (-X)
Specify an external reference in the project.
Preserve formatting of comments (–preserve-source-formatting)
When this switch is used, the line breaks and spaces present in the source comments will be preserved in
the HTML output. @format tag may be used to reenable text formatting.
Regular expression (-R)
Regular expression used to select comments containing documentation. If not specified then all the com-
ments found in the specification of the compilation units of the project are used to document the project;
if specified then only those comments matching the specified regular expression are used to generate the
documentation. The leading comment delimiters “–” are stripped before applying the regular expression.
For example, the regular expression “^-” can be used to select the documentation of the following subpro-
gram and skip the internal comment:
function Set_Alarm
(Message : String;
Minutes : Natural) return Boolean;
--- Display a message after the given time.
-- TODO: what is the unit for Minutes?
--- @return True iff the alarm was successfully registered
4 Chapter 1. Introduction
GNATdoc User Guide, Release 22.0w
6 Chapter 1. Introduction
CHAPTER
TWO
GNATdoc extracts documentation directly from the comments present in source files for your project. Special tags
present in the comments are interpreted by GNATdoc.
The documentation attached to each package is the block of comment directly preceding the package declaration.
The following tags are supported in package comments:
@summary
a summary of the package
@description
a detailed description of the package
For example:
-- @summary
-- Drawing routines.
--
-- @description
-- This package provides routines for drawing basic shapes and Bézier curves.
--
package Drawing is
The documentation attached to each enumeration type is the block of comment directly following the record type
declaration, or directly preceding it if the option -l was specified.
The following tag is supported when annotating enumeration literals:
@value
document an enumeration literal, with the following syntax:
@value <enumeration_literal> <description>
where:
<enumeration_literal>
7
GNATdoc User Guide, Release 22.0w
is the value of the enumeration literal as it appears in the enumeration type declara-
tion.
<description>
the documentation for the enumeration literal; all following text is considered for
inclusion, until a blank comment line or another tag is encountered.
For example:
Enumeration literals can also be documented in line, with the documentation for each literal directly following its
declaration (or directly preceding the component declaration, if the option -l was specified). In this case, the tag
@value is not required:
As shown above, a combined approach of documentation is also supported (see that the general description of the
enumeration type Colors is located before its declaration and the documentation of its literals is located after their
declaration).
The documentation attached to each record type is the block of comment directly following the record type declaration,
or directly preceding it if the option -l was specified.
The following tags are supported when annotating subprograms:
@field
document a record component, with the following syntax:
@field <component_name> <description>
where:
<component_name>
is the name of the component as it appears in the subprogram.
<description>
the documentation for the component; all following text is considered for inclusion,
until a blank comment line or another tag is encountered.
For example:
Record components can also be documented in line, with the documentation for each component directly following
its declaration (or directly preceding the component declaration, if the option -l was specified). In this case, the tag
@field is not required:
As shown above, a combined approach of documentation is also supported (see that the general description of the
record type Point is located before its declaration and the documentation of its components X and Y is located after
their declaration).
The documentation attached to each subprogram is the block of comment directly following the subprogram declara-
tion, or directly preceding it if the option -l was specified.
The following tags are supported when annotating subprograms:
@param
document a subprogram parameter, with the following syntax:
@param <param_name> <description>
where:
<param_name>
is the name of the parameter as it appears in the subprogram.
<description>
the documentation for the parameter; all following text is considered for inclusion,
until a blank comment line or another tag is encountered.
@return
document the return type of a function, with the following syntax:
@return <description>
where:
<description>
is the documentation for the return value; all following text is considered for inclu-
sion, until a blank comment line or another tag is encountered.
@exception
document an exception, with the following syntax:
@exception <exception_name> <description>
where:
<exception>
is the name of the exception potentially raised by the subprogram
<description>
is the documentation for this exception; all following text is considered for inclusion,
until a blank comment line or another tag is encountered.
For example:
function Set_Alarm
(Message : String;
Minutes : Natural) return Boolean;
-- Display a message after the given time.
-- @param Message The text to display
-- @param Minutes The number of minutes to wait
-- @exception System.Assertions.Assert_Failure raised
-- if Minutes = 0 or Minutes > 300
-- @return True iff the alarm was successfully registered
The parameters can also be documented in line, with the documentation for each parameter directly following the
parameter type declaration (or directly preceding the parameter declaration, if the option -l was specified). In this
case, the tag @param is not required:
function Set_Alarm
(Message : String;
-- The text to display
Minutes : Natural
-- The number of minutes to wait
) return Boolean;
-- Display a message after the given time.
-- @exception System.Assertions.Assert_Failure raised
-- if Minutes = 0 or Minutes > 300
-- @return True iff the alarm was successfully registered
GNATdoc recognizes several markup constructs inside description text, that can be used to better control the format
of the generated documentation.
All markup constructs are based on paragraphs. A paragraph is one or more consecutive lines of text, separated from
the flow of comments by one blank line. All lines in a paragraph should have the same indentation. Sequential
paragraphs with the same indentation level are processed as a list of paragraphs.
Bulled lists start by a paragraph that begins with the characters ‘-‘ or ‘*’. List items of the same list must have the
‘-‘ or ‘*’ character at same indentation. When the text of a list item occupies more than one line, it should be aligned
with the first character on the first line of the list item. List items can have more than one paragraph, in which case all
paragraphs should use the same indentation as the first paragraph:
-- - This is the first bullet list item. The blank line above the
-- first list item is required; blank lines between list items
-- (such as below this paragraph) are optional.
--
-- - This is the first paragraph in the second item in the list.
--
-- This is the second paragraph in the second item in the list.
-- The blank line above this paragraph is required. The left edge
-- of this paragraph lines up with the paragraph above, both
-- indented relative to the bullet.
--
-- - This is a sublist. The bullet lines up with the left edge of
-- the text blocks above. A sublist is a new list so requires a
-- blank line above and below.
--
-- - This is the third item of the main list.
--
-- This paragraph is not part of the list.
Code blocks can be used to include preformatted text into the documentation. A code block should have an indentation
of three or more spaces. Contrary to other constructs, a code block doesn’t end wth an empty line:
-- with Ada.Text_IO;
--
-- procedure Hello_World is
-- begin
-- Ada.Text_IO.Put_Line ("Hello, world!");
-- emd Hello_World;
The tag @private notifies GNATdoc that no documentation must be generated on a given entity. For example:
The tag @group is used by GNATdoc to generate an index of packages in the project grouped by categories.
THREE
CONFIGURATION
The documentation is generated by default into a directory called gnatdoc, created under the object directory of the
root project. This behavior can be modified by specifying the attribute Documentation_Dir in the package Documen-
tation of your root project:
project Default is
package Documentation is
for Documentation_Dir use "html";
end Documentation;
end P;
By default GNATdoc recursively processes all the projects on which your root project depends. This behavior can be
modified by specifying the attribute Ignored_Subprojects in the package Documentation of your root project:
with "prj_1";
with "prj_2";
with "prj_3";
project Default is
package Documentation is
for Ignored_Subprojects use ("prj_1", "prj_3");
end Documentation;
end Default;
The directory containing images is specified by the string attribute Image_Dir of the Documentation package:
package Documentation is
for Image_Dir use "image_files";
end Documentation;
13
GNATdoc User Guide, Release 22.0w
The regular expression for recognizing doc comments can be specified via the string attribute Doc_Pattern of the
Documentation package:
package Documentation is
for Doc_Pattern use "^<";
-- This considers comments beginning with "--<" to be documentation
end Documentation;
Set of tags processed by GNATdoc can be extended by providing custom tags handlers. String attribute Cus-
tom_Tags_Definition allows to specify Python file that contains implementation of custom tags handlers:
package Documentation is
for Custom_Tags_Definition use "my_tags.py";
-- GNATdoc loads my_tags.py file on startup to process custom tags
end Documentation;
GNATdoc uses a set of static resources and templates files to control the final rendering. Modifying these static re-
sources and templates you can control the rendering of the generated documentation. The files used for generating
the documentation can be found under <install_dir>/share/gnatstudio/gnatdoc/html. If you need a
different layout from the proposed one, you can override those files and provides new files. The directory for user de-
fined static resources and templates can be specified via the string attribute HTTP_Custom_Dir of the Documentation
package in your project file:
package Documentation is
for HTML_Custom_Dir use "docs/gnatdoc_html";
end Documentation;
All files in static subdirectory will be copied to result documentation directory. This can be used to provide
additional files like CSS, images, etc.
Files in templates subdirectory are used as templates when documentation is generated. You can put modified
versions of default files in this directory with same name as original file. Adding new files has no effect on generated
documentation.
14 Chapter 3. Configuration
CHAPTER
FOUR
It is possible to extend the set of supported tags by providing custom tag handlers written in Python. Assuming you
have written these in a file called mytags.py, you should add the switch –custom-tags-definition=mytags.py to the
gnatdoc command line.
In your file, you will need to declare a Python class for each custom tag you wish to define. This class should be
inherited from the GPS.InlineTagHandler class. Its constructor must call the constructor of the inherited class
and pass it the name of the tag you want to handle. Each tag handler class must be registered by calling GPS.
register_tag_handler().
Custom tag handling class must implement the function to_markup(). Inside this function, you should use the
provided writer to generate documentation. Most methods of the class GPS.MarkupGenerator have ‘start’/’end’
pairs. These functions generate elements that can be nested. The class for custom tag handling is responsible for
generating one call to the ‘end’ function for each call ‘start’ function.
Here is an example of a custom tag handler that defines and registers a handler for the ‘hello’ tag, and outputs the text
‘Hello, <parameter>!’ to the generated documentation:
class HelloTagHandler(GPS.InlineTagHandler):
def __init__(self):
super(HelloTagHandler, self).__init__('hello')
def has_parameter(self):
return True
GPS.register_tag_handler(HelloTagHandler())
HTML backend allows to specify CSS class to be applied to generated elements. All functions of GPS.
MarkupGenerator that have ‘attributes’ parameters use value of ‘class’ key to set CSS class name of generated
element. See HTML output customization for more information how to provide your own CSS files and to modify
default templates to link CSS files with generated documentation.
text method of GPS.MarkupGenerator accepts ‘href’ key to generate cross reference to URL specified by its
value.
15
GNATdoc User Guide, Release 22.0w
4.2.1 GPS
GPS.register_tag_handler(handler)
Registers instance of custom tag handler.
4.2.2 GPS.InlineTagHandler
class GPS.InlineTagHandler(name)
This class is intended to be used as base class for custom tag handlers of inline tags.
__init__(name)
Initialize base class
Parameters name (string) – Name of custom tag
has_parameter()
Should returns True when custom tag has parameter. Default implementation returns False.
Returns Should or should not additional parameter be parsed and passes to custom tag handler.
to_markup(writer, parameter)
Do custom tag processing and use writer to generate documentation.
Parameters
• writer (GPS.MarkupGenerator) – Writer to be used to generate documentation.
• parameter (string) – Additional parameter of custom tag provided in source code.
4.2.3 GPS.MarkupGenerator
class GPS.MarkupGenerator
Used by custom tag handler to generate structured output.
start_paragraph(attributes)
Opens paragraph in generated documentation. GPS.MarkupGenerator.end_paragraph() must
be called to close paragraph.
Paragraphs can be nested and can contain lists and text too.
Parameters attributes (dictionary) – Additional attributes to be passed to backend.
end_paragraph()
Closes paragraph in generated documentation.
start_list(attributes)
Opens list in generated documentation. func:GPS.MarkupGenerator.end_list must be called to close list.
Lists can contains list items only.
Parameters attributes (dictionary) – Additional attributes to be passed to backend.
end_list()
Closes list in generated documentation.
start_list_item(attributes)
Opens item of the list in generated documentation. func:GPS.MarkupGenerator.end_list_item must be
called to close list item.
List item can contain paragraph, lists and text.
Parameters attributes (dictionary) – Additional attributes to be passed to backend.
end_list_item()
Closes list item in generated documentation.
text(text, attributes)
Outputs test to generated documentation.
Parameters
• text (string) – Text to be output in generated documentation.
• attributes (dict) – Additional attributes to be passed to backend.
html(html)
Outputs HTML markup to generated documentation. This markup is processed by browser to display its
content.
Note, this function is intended to be used for HTML backend only.
Parameters html (string) – HTML markup to be output in generated documentation.
generate_after_paragraph()
Switch MarkupGenerator to generate output after processing of paragraph where custom tag is used.
generate_inline()
Switch MarkupGenerator to generate output in place where custom tag is used.
FIVE
• search
• genindex
This document may be copied, in whole or in part, in any form or by any means, as is or with alterations, provided that
(1) alterations are clearly marked as alterations and (2) this copyright notice is included unmodified in any copy.
19
INDEX
Symbols
__init__() (GPS.InlineTagHandler method), 16
E
end_list() (GPS.MarkupGenerator method), 16
end_list_item() (GPS.MarkupGenerator method), 17
end_paragraph() (GPS.MarkupGenerator method), 16
G
generate_after_paragraph() (GPS.MarkupGenerator
method), 17
generate_inline() (GPS.MarkupGenerator method), 17
H
has_parameter() (GPS.InlineTagHandler method), 16
html() (GPS.MarkupGenerator method), 17
I
InlineTagHandler (class in GPS), 16
M
MarkupGenerator (class in GPS), 16
R
register_tag_handler() (in module GPS), 16
S
start_list() (GPS.MarkupGenerator method), 16
start_list_item() (GPS.MarkupGenerator method), 16
start_paragraph() (GPS.MarkupGenerator method), 16
T
text() (GPS.MarkupGenerator method), 17
to_markup() (GPS.InlineTagHandler method), 16
20