1 .\" $Id: mandoc.3,v 1.3 2011/04/09 15:53:48 kristaps Exp $
3 .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 .\" Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
6 .\" Permission to use, copy, modify, and distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 .Dd $Mdocdate: April 9 2011 $
35 .Nd mandoc macro compiler library
43 .Fa "const char **seq"
46 .Ft "const struct man_meta *"
48 .Fa "const struct man *man"
50 .Ft "const struct man_node *"
52 .Fa "const struct man *man"
54 .Ft "const struct mdoc_meta *"
56 .Fa "const struct mdoc *mdoc"
58 .Ft "const struct mdoc_node *"
60 .Fa "const struct mdoc *mdoc"
64 .Fa "enum mparset type"
65 .Fa "enum mandoclevel wlevel"
71 .Fa "struct mparse *parse"
73 .Ft "enum mandoclevel"
75 .Fa "struct mparse *parse"
77 .Fa "const char *fname"
81 .Fa "struct mparse *parse"
85 .Fa "struct mparse *parse"
86 .Fa "struct mdoc **mdoc"
87 .Fa "struct man **man"
95 .Fa "enum mandoclevel"
97 .Vt extern const char * const * man_macronames;
98 .Vt extern const char * const * mdoc_argnames;
99 .Vt extern const char * const * mdoc_macronames;
105 manual into an abstract syntax tree (AST).
107 manuals are composed of
111 and may be mixed with
118 The following describes a general parse sequence:
121 initiate a parsing sequence with
124 parse files or file descriptors with
127 retrieve a parsed syntax tree, if the parse was successful, with
130 iterate over parse nodes with
135 free all allocated memory with
142 This section documents the functions, types, and variables available
147 .It Vt "enum mandoc_esc"
148 .It Vt "enum mandocerr"
149 .It Vt "enum mandoclevel"
150 .It Vt "enum mparset"
151 .It Vt "struct mparse"
166 .It Fn mparse_strerror
167 .It Fn mparse_strlevel
171 .It Va man_macronames
173 .It Va mdoc_macronames
175 .Sh IMPLEMENTATION NOTES
176 This section consists of structural documentation for
181 .Ss Man Abstract Syntax Tree
182 This AST is governed by the ontological rules dictated in
184 and derives its terminology accordingly.
186 The AST is composed of
188 nodes with element, root and text types as declared by the
191 Each node also provides its parse point (the
196 fields), its position in the tree (the
202 fields) and some type-specific data.
204 The tree itself is arranged according to the following normal form,
205 where capitalised non-terminals represent nodes.
207 .Bl -tag -width "ELEMENTXX" -compact
211 \(<- ELEMENT | TEXT | BLOCK
224 The only elements capable of nesting other elements are those with
225 next-lint scope as documented in
227 .Ss Mdoc Abstract Syntax Tree
228 This AST is governed by the ontological
231 and derives its terminology accordingly.
233 elements described in
235 are described simply as
238 The AST is composed of
240 nodes with block, head, body, element, root and text types as declared
244 Each node also provides its parse point (the
249 fields), its position in the tree (the
256 fields) and some type-specific data, in particular, for nodes generated
257 from macros, the generating macro in the
261 The tree itself is arranged according to the following normal form,
262 where capitalised non-terminals represent nodes.
264 .Bl -tag -width "ELEMENTXX" -compact
268 \(<- BLOCK | ELEMENT | TEXT
270 \(<- HEAD [TEXT] (BODY [TEXT])+ [TAIL [TEXT]]
276 \(<- mnode* [ENDBODY mnode*]
280 \(<- [[:printable:],0x1e]*
283 Of note are the TEXT nodes following the HEAD, BODY and TAIL nodes of
284 the BLOCK production: these refer to punctuation marks.
285 Furthermore, although a TEXT node will generally have a non-zero-length
286 string, in the specific case of
287 .Sq \&.Bd \-literal ,
288 an empty line will produce a zero-length string.
289 Multiple body parts are only found in invocations of
291 where a new body introduces a new phrase.
295 syntax tree accomodates for broken block structures as well.
296 The ENDBODY node is available to end the formatting associated
297 with a given block before the physical end of that block.
300 field, is of the BODY
304 as the BLOCK it is ending, and has a
306 field pointing to that BLOCK's BODY node.
307 It is an indirect child of that BODY node
308 and has no children of its own.
310 An ENDBODY node is generated when a block ends while one of its child
311 blocks is still open, like in the following example:
312 .Bd -literal -offset indent
319 This example results in the following block structure:
320 .Bd -literal -offset indent
325 BLOCK Bo, pending -> Ao
330 ENDBODY Ao, pending -> Ao
335 Here, the formatting of the
337 block extends from TEXT ao to TEXT ac,
338 while the formatting of the
340 block extends from TEXT bo to TEXT bc.
341 It renders as follows in
345 .Dl <ao [bo ac> bc] end
347 Support for badly-nested blocks is only provided for backward
348 compatibility with some older
351 Using badly-nested blocks is
352 .Em strongly discouraged ;
359 are unable to render them in any meaningful way.
360 Furthermore, behaviour when encountering badly-nested blocks is not
361 consistent across troff implementations, especially when using multiple
362 levels of badly-nested blocks.
373 library was written by
374 .An Kristaps Dzonsons Aq kristaps@bsd.lv .