1 .\" $Id: mandoc.3,v 1.1 2011/03/22 10:02:50 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: March 22 2011 $
32 .Nd mandoc macro compiler library
37 .Ft "const struct man_meta *"
39 .Fa "const struct man *man"
41 .Ft "const struct man_node *"
43 .Fa "const struct man *man"
45 .Ft "const struct mdoc_meta *"
47 .Fa "const struct mdoc *mdoc"
49 .Ft "const struct mdoc_node *"
51 .Fa "const struct mdoc *mdoc"
55 .Fa "enum mparset type"
56 .Fa "enum mandoclevel wlevel"
62 .Fa "struct mparse *parse"
64 .Ft "enum mandoclevel"
66 .Fa "struct mparse *parse"
68 .Fa "const char *fname"
72 .Fa "struct mparse *parse"
76 .Fa "struct mparse *parse"
77 .Fa "struct mdoc **mdoc"
78 .Fa "struct man **man"
80 .Vt extern const char * const * man_macronames;
81 .Vt extern const char * const * mdoc_argnames;
82 .Vt extern const char * const * mdoc_macronames;
88 manual into an abstract syntax tree (AST).
90 manuals are composed of
101 The following describes a general parse sequence:
104 initiate a parsing sequence with
107 parse files or file descriptors with
110 retrieve a parsed syntax tree, if the parse was successful, with
113 iterate over parse nodes with
118 free all allocated memory with
124 .Sh IMPLEMENTATION NOTES
125 This section consists of structural documentation for
130 .Ss Man Abstract Syntax Tree
131 This AST is governed by the ontological rules dictated in
133 and derives its terminology accordingly.
135 The AST is composed of
137 nodes with element, root and text types as declared by the
140 Each node also provides its parse point (the
145 fields), its position in the tree (the
151 fields) and some type-specific data.
153 The tree itself is arranged according to the following normal form,
154 where capitalised non-terminals represent nodes.
156 .Bl -tag -width "ELEMENTXX" -compact
160 \(<- ELEMENT | TEXT | BLOCK
173 The only elements capable of nesting other elements are those with
174 next-lint scope as documented in
176 .Ss Mdoc Abstract Syntax Tree
177 This AST is governed by the ontological
180 and derives its terminology accordingly.
182 elements described in
184 are described simply as
187 The AST is composed of
189 nodes with block, head, body, element, root and text types as declared
193 Each node also provides its parse point (the
198 fields), its position in the tree (the
205 fields) and some type-specific data, in particular, for nodes generated
206 from macros, the generating macro in the
210 The tree itself is arranged according to the following normal form,
211 where capitalised non-terminals represent nodes.
213 .Bl -tag -width "ELEMENTXX" -compact
217 \(<- BLOCK | ELEMENT | TEXT
219 \(<- HEAD [TEXT] (BODY [TEXT])+ [TAIL [TEXT]]
225 \(<- mnode* [ENDBODY mnode*]
229 \(<- [[:printable:],0x1e]*
232 Of note are the TEXT nodes following the HEAD, BODY and TAIL nodes of
233 the BLOCK production: these refer to punctuation marks.
234 Furthermore, although a TEXT node will generally have a non-zero-length
235 string, in the specific case of
236 .Sq \&.Bd \-literal ,
237 an empty line will produce a zero-length string.
238 Multiple body parts are only found in invocations of
240 where a new body introduces a new phrase.
244 syntax tree accomodates for broken block structures as well.
245 The ENDBODY node is available to end the formatting associated
246 with a given block before the physical end of that block.
249 field, is of the BODY
253 as the BLOCK it is ending, and has a
255 field pointing to that BLOCK's BODY node.
256 It is an indirect child of that BODY node
257 and has no children of its own.
259 An ENDBODY node is generated when a block ends while one of its child
260 blocks is still open, like in the following example:
261 .Bd -literal -offset indent
268 This example results in the following block structure:
269 .Bd -literal -offset indent
274 BLOCK Bo, pending -> Ao
279 ENDBODY Ao, pending -> Ao
284 Here, the formatting of the
286 block extends from TEXT ao to TEXT ac,
287 while the formatting of the
289 block extends from TEXT bo to TEXT bc.
290 It renders as follows in
294 .Dl <ao [bo ac> bc] end
296 Support for badly-nested blocks is only provided for backward
297 compatibility with some older
300 Using badly-nested blocks is
301 .Em strongly discouraged ;
308 are unable to render them in any meaningful way.
309 Furthermore, behaviour when encountering badly-nested blocks is not
310 consistent across troff implementations, especially when using multiple
311 levels of badly-nested blocks.
322 library was written by
323 .An Kristaps Dzonsons Aq kristaps@bsd.lv .