\documentclass[11pt]{article} \usepackage{times} \usepackage{pl} \usepackage{html} \usepackage{plpage} \sloppy \makeindex \onefile \htmloutput{.} % Output directory \htmlmainfile{pldoc} % Main document file \bodycolor{white} % Page colour \renewcommand{\runningtitle}{SWI-Prolog documentation package} \begin{document} \title{SWI-Prolog Source Documentation \\ Version 2} \author{Jan Wielemaker \\ VU University, Amsterdam \\ The Netherlands \\ E-mail: \email{J.Wielemaker@vu.nl}} \maketitle \begin{abstract} This document presents PlDoc, the SWI-Prolog source-code documentation infrastructure. PlDoc is loosely based on JavaDoc, using structured comments to mix documentation with source-code. SWI-Prolog's PlDoc is entirely written in Prolog and well integrated into the environment. It can create HTML+CSS and \LaTeX{} documentation files as well as act as a web-server for the loaded project during program development. The SWI-Prolog website (\url{http:www.swi-prolog.org}) is written in Prolog and integrates PlDoc to provide a comprehensive searchable \href{http://www.swi-prolog.org/pldoc/index.html}{online manual}. Version~2 of PlDoc extends the syntax with \href{http://en.wikipedia.org/wiki/Markdown}{Markdown} markup as specified by \href{http://www.stack.nl/~dimitri/doxygen/}{Doxygen}. Based on experience with version~1, PlDoc~2 both tightens some rules to avoid misinterpretations and relaxes others that were considered too conservative. \end{abstract} \pagebreak \tableofcontents \vfill \vfill \newpage \section{Introduction} \label{sec:pldoc-intro} When developing Prolog source that has to be maintained for a longer period or is developed by a ---possibly distributed--- team some basic quality mechanisms need to be adopted. A shared and well designed codingstyle \cite{DBLP:dblpjournals/tplp/CovingtonBOWP12} is one of them. In addition, documentation of source-files and their primary interfaces as well as a testing framework must be established. In our view, hitherto existing documentation and testing frameworks fell short realising the basic needs in a lightweight and easy to adopt system. To encourage consistent style, well commented code and test-assisted development, we make sure that \begin{shortlist} \item The documentation and testing framework requires a minimum of work and learning. \item The framework is immediately rewarding to the individual programmer as well as the team, \end{shortlist} First, we describe the documentation system we developed for SWI-Prolog. In \secref{motivation} we motivate our main choices. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Overview} \label{sec:pldoc-overview} Like JavaDoc, the PlDoc infrastructure is based on \emph{structured comments}. Using comments, no changes have to be made to Prolog to load the documented source. If the \pllib{pldoc} library is loaded, Prolog will not only load the source, but also parse all structured comments. It processes the mode-declarations inside the comments and stores these as annotations in the Prolog database to support the test framework and other runtime and compiletime analysis tools that may be developed in the future. Documentation for all or some of the loaded files can be written to file in either HTML+CSS or \LaTeX{} (see \secref{doclatex}) format. Each source file is documented in a single file. In addition, the documentation generator will generate an index file that can be used as an index for a browser or input file for \LaTeX{} for producing nicely typeset document. To support the developer, the documentation system can be asked to start a web-server that can be used to browse the documentation. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Structured comments} \label{sec:pldoc-comments} Structured comments come in two flavours, the line-comment (\%) based one, seen mostly in the Prolog community and the block-comment (\verb$/*$\ldots\verb$*/$) based one, commonly seen in the Java and C domains. As we cannot determine the argument names, type and modes from following (predicate) source itself, we must supply this in the comment.\footnote{See \secref{motivation:modes}.} The overall structure of the comment therefore is: \begin{shortlist} \item Semi-formal type- and mode-description, see \secref{modes} \item Wiki-style documentation body, see \secref{wiki} \item JavaDoc style tags (\chr{@}keyword value, see \secref{tags}) \end{shortlist} The \verb$/*$\ldots\verb$*/$ style comment starts with \verb$/**$. The type and mode declarations start at the first non-blank line and are ended by a blank line. The \chr{\%}-style line comments start with \verb$%!$ or, for compatibility reasons, with \verb$%%$.\footnote{The \texttt{\%\%} leader was considered to give too many false positives on arbitrary source code. It is still accepted, but invalid comments are silently ignored, while invalid comments that start with \texttt{\%!} result in a warning.} The type and mode declaration is ended by the first line that starts with a single \%. E.g., the following two fragments are identical wrt. PlDoc. Skipping blank-lines in \verb$/**$ comments allows to start the comment on the second line. \begin{code} %! predicate(-Arg:type) is nondet % Predicate ... \end{code} \begin{code} /** * predicate(-Arg:type) is nondet * * Predicate ... */ \end{code} The JavaDoc style keyword list starts at the first line starting with @. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{File (module) comments} \label{sec:sectioncomments} An important aspect is documentation of the file or module as a whole, explaining its design, purpose and relation to other modules. In JavaDoc this is the comment that preceeds the class definition. The Prolog equivalent would be to put the module comment in front of the module declaration. The module declaration itself however is an important index to the content of the file and is therefore best kept first. The general comment-structure for module comments is to use a type identifier between angled brackets, followed by the title of the section. Currently the only type provided is \const{module}. Other types may be added later. \subsection*{Example} \begin{code} /** Prolog documentation processor This module processes structured comments and generates both formal mode declarations from them as well as documentation in the form of HTML or LaTeX. @author Jan Wielemaker @license GPL */ \end{code} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Type, mode and determinism declaration headers} \label{sec:modes} Many predicates can sensibly be called in different ways, e.g. with a specific argument as input or as output. The header of the documentation of a predicate consists of one or more \jargon{templates}, each representing a specific way of calling the predicate. A template can contain information about types, argument instantiation patterns, determinism and more. The syntax is informally described below: \begin{center} \begin{tabular}{lrl} \hline