(!*******************************************************
* Mosel Example Programs
* ======================
*
* file mddoc.mos
* ``````````````
* Example for the use of the Mosel language
* (Use of annotations for documentation)
*
* (c) 2015 Fair Isaac Corporation
* author: Y. Colombani, rev. Jan. 2024
*******************************************************!)
package mddoc
version 0.0.8
namespace myns
!The following optional header is required only when building the PDF
(!@doc.
@xmlheader
@xmlroot manual
!)
(!@doc.
@title An example of model documentation
@date January 2024
@chapter Annotations for documentation
@section Running moseldoc
@p [XML]
The moseldoc program takes as input a bim file produced from
a Mosel model compiled with the -D compiler option.
Generation of the documentation for this model is therefore obtained by
executing the following commands:
@p [SRC]
>mosel comp -D mddoc
>moseldoc mddoc
@p
The result of this process is an XML file ("mddoc_doc.xml")
and a directory containing an HTML version of the documentation
("mddoc_html"). The program will produce only the XML file
(from a bim file) if option -xml is used and only the HTML data
(from an XML file) if -html
is selected. The option -f will be required to force the
replacement of existing files.
@p
As a Mosel program available in source form, moseldoc
can be adapted to fit specific user requirements. To re-generate the
moseldoc executable use this compilation command (requires a C compiler):
@p [SRC]
>mosel comp moseldoc.mos -o deploy.exe:moseldoc
@p
Note for Xpress Workbench users:
To enable the -D compiler option in Workbench open the Run
menu and select the entry Compiler Options, enable the
Generate Doc Annotations option, then confirm with Save.
Click on the Compile button in the Workbench toolbar to generate
a BIM file that contains the documentation annotations.
@section Automatic addition of annotations
@p
The documentation generation relies on annotations that are recorded
into the bim
file. Some of these annotations are automatically produced by the Mosel
compiler when it is run with the option -D (it is also possible
to overwrite annotations set by the compiler).
These are the automatically generated annotations:
- @doc.name
- model/package name
- @doc.version
- model/package version
- @doc.date
- generation date
- @doc.syntax
- subroutine prototype
- @doc.type
- entity type
- @doc.recfldtype
- record field type
- @doc.default
- parameter default value
- @doc.const
- constant value
@p
The special annotation @doc.autogen can be used to disable
locally this automatic generation procedure (when it is set to 'false', the
generation is disabled).
@p
Thanks to the automatic generation feature it is possible to produce a documentation for model source files that do not contain any annotations.
@section Document structure
@p
The document is organised in chapters (@doc.chapter title),
sections (@doc.section title) and subsections (@doc.subsection title).
In each of these components, paragraphs are added using the marker @doc.p.
By default, the paragraph content is expected to be valid XML but plain
text can also be used by starting the paragraph with the [TXT] marker
(in this case special characters like '<' are not interpreted) and to insert
code examples you need to start with the marker [SRC] (special
characters are not interpreted and spacing is preserved).
@p
Simple text formatting is available via the XML tags i (italics), b (bold), em (emphasized), and tt (typewriter).
@p
Math formulae can be typeset using Latex syntax, either inline: \sum _{i=1}^{N} C_{i} \cdot x_{i} \leq 10 or in display mode (it is possible to link to an equation on the same page): \prod _{i=1}^{N} C_{i} \cdot x_{i} \lt 10
or also:
\begin{eqnarray*} x + y + z \tamp = \tamp 3 \\
x \tamp \leq \tamp 2 \cdot y \end{eqnarray*}
@subsection Relocating documentation contents
@p
Documentation contents (entities, function definitions and paragraphs) are
automatically associated with the current subsection, section or chapter
(depending on the last definition). It is also possible to specify
a different location using the @doc.relocate annotation that
must designate a target location in the document that has been defined
with @doc.location.
@subsection References
@p
Entities and subroutine definitions within the same document can be referenced respectively via entRef and fctRef XML tags that can be employed within annotations @doc.p, @doc.[cparam.]info, and @doc.related. It is also possible to generate lists of entities or subroutines within annotations @doc.p:
@p
@p
!)
(!@doc.
@chapter The example
@p
This entire document is generated from the source file
mddoc.mos. Please look at the model source to see which annotations
were defined to produce the output under this chapter.
!)
!@doc.section Runtime parameters
parameters
!@doc.descr short parameter description
!@doc.value v1 possible value
!@doc.value v2 another possible value
!@doc.info some more explanation (longer text)
P1="some text"
! Define the insertion point for the documentation of control parameters
!@doc.cparamloc sec_cparam
(!@doc.cparam.
@descr p2 short parameter description
@value p2 v1 possible value
@value p2 v2 another possible value
@default p2 0
@info p2 some more explanation (longer text)
@info p2 Can reference other control parameters p3
!)
"p2":integer
!@doc.cparam.descr p3 short parameter description
!@doc.cparam.default p3 true
"p3":boolean
end-parameters
!@doc.section Requirements
!@doc.location reqdefs
requirements
!@doc.descr this set must be defined by some other package/model
!@doc.info some more detailed information
!@doc.related S
R: range
!@doc.ignore
!@doc.descr another set for testing requirements
S2: range
!@doc.descr procedure defined by some other package/model
!@doc.info some additional information
!@doc.related aproc procedure myextproc procedure myextproc(val:integer) end-requirements !@doc.section Constants, variables, and type definitions !@doc.location vardefs public declarations (!@doc. @descr short description of the constant set @info additional information !) S=1..10 !@doc.descr an error code constant MYERR=11 !@doc.descr namespaced entity myns~val: integer !@doc.descr an array !@doc.deprecated This array should no longer be used. A: array(S) of real !@doc.descr definition of a union type for Mosel's basic types basictype = string or integer or real or boolean !@doc.descr a list of basic types !@doc.info see also the definition of the type basictype
LB: list of basictype
!@doc.descr a union of scalar numerical type
nu: real or integer
!@doc.descr a subroutine reference
myfct: function(r:real): real
(!@doc.
@descr a record type
@recflddescr fld1 field description
@recflddescr fld2 another field description
@recfldval fld2 val1 meaning of a specific value
@recfldval fld2 v2 another value for this field with a subroutine reference aproc
@info further information
!)
rectype=public record
fld1:integer
fld2:string
end-record
(!@doc.
@descr a record variable
@recflddescr fldA field description
@recflddescr fldB another field description
@setby aproc
@info @doc.value may also be used with a variable
@info several @doc.info tags can be used for a given entity
@info entities can be referenced: rectype and myns~val !) recvar:public record fldA:integer fldB:string end-record end-declarations ! **** Documenting annotations **** ! Select annotation categories to be included in documentation !@doc.annotcat my ! Relocate insertion point for annotations documentation to a location ! defined via '@doc.location' !@doc.annotloc sec_ann !@mc.def my.annotname multi,global,values=avalue value2 value3 !@mc.def my.anotherannotname integer,specific,range=1 10 (!@doc.annot. @descr my.annotname Short description of the annotation. @default my.annotname avalue @type my.annotname text @value my.annotname avalue Explanation of this value @value my.annotname value2 Another possible value @value my.annotname value3 Yet another possible value @info my.annotname Some more detailed explanations. @info my.annotname my.anotherannotname !) !@doc.annot.descr my.anotherannotname Short description of the annotation. ! **** Documenting subroutines **** (!@doc. @section Subroutines @p [TXT] The list of subroutines below is automatically generated from the declarations appearing within the scope of this section !) (!@doc. @descr some short description @param i first parameter @param r second parameter @param flags some flags. Possible values: @paramval flags 1 first option @paramval flags 2 second option @err 33 error condition that can be set @err MYERR reference to an error code constant @return the truth @example Some descriptive text for the example @example [SRC] the example code is here @info useful information for myfunct
!)
public function myfunct(i:integer,r:real,flags:integer):boolean
returned:=i>r
end-function
!@doc.group myfunct
!@doc.info myotherfunc is an alternative to myfunct
!@doc.info Up to 3 different subroutine names can be grouped
public function myotherfunc(i:integer):boolean
returned:=true
end-function
(!@doc.
@descr Yet another routine
@deprecated Use myotherfunc in place of this routine.
@param s the only parameter
@info should modify recvar
@related recvar, myns~aproc
!)
public procedure aproc(s:string)
writeln(s)
end-procedure
(!@doc.
@descr Namespaced subroutine
@param s the only parameter
@related aproc !) public procedure myns~aproc(s:string) writeln(s) end-procedure ! **** Deactivating temporarily the generation of documentation **** ! The following procedure will not be included into the doc (!@doc. @descr Ignored by the documentation @ignore !) public procedure hiddenproc a:=1 end-procedure ! Don't document these generic routines for handling package control parameters !@doc.autogen=false public function mddoc~getbparam(name:string):boolean returned:=true end-function public function mddoc~getiparam(name:string):integer returned:=0 end-function public procedure mddoc~setparam(name:string, val:boolean) writeln("setparam") end-procedure public procedure mddoc~setparam(name:string, val:integer) writeln("setparam") end-procedure !@doc.autogen ! Re-enable generation of documentation annotations ! **** Relocating portions of the documentation **** ! The documentation of this scalar will be relocated to the section 'Constants and variables' !@doc.relocate vardefs public declarations advar:string !@doc.descr an additional variable end-declarations ! The documentation of this subroutine will be relocated to the section 'Requirements' !@doc.relocate reqdefs requirements !@doc.descr function defined by some other package/model function myextfunc:real end-requirements ! The documentation of the control parameters will be inserted here !@doc.section Control parameters !@doc.location sec_cparam ! The documentation of the annotations will be inserted here !@doc.section Annotations !@doc.location sec_ann end-package