1 .\" $Id: man.3,v 1.23 2010/08/16 09:51:17 kristaps Exp $
3 .\" Copyright (c) 2009-2010 Kristaps Dzonsons <kristaps@bsd.lv>
5 .\" Permission to use, copy, modify, and distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 .Dd $Mdocdate: August 16 2010 $
29 .Nd man macro compiler library
33 .Vt extern const char * const * man_macronames;
36 .Fa "struct regset *regs"
42 .Fn man_endparse "struct man *man"
44 .Fn man_free "struct man *man"
45 .Ft "const struct man_meta *"
46 .Fn man_meta "const struct man *man"
47 .Ft "const struct man_node *"
48 .Fn man_node "const struct man *man"
56 .Fn man_reset "struct man *man"
60 library parses lines of
62 input into an abstract syntax tree (AST).
64 In general, applications initiate a parsing sequence with
66 parse each line in a document with
68 close the parsing session with
70 operate over the syntax tree returned by
74 then free all allocated memory with
78 function may be used in order to reset the parser for another input
82 section for a full example.
84 Beyond the full set of macros defined in
88 library also accepts the following macros:
90 .Bl -tag -width Ds -compact
92 Has no effect. Handled as a current-scope line macro.
96 .Pq part of the standard preamble for Perl documentation .
97 Handled as a line macro.
101 .Pq part of the standard preamble for Perl documentation .
102 Handled as a current-scope line macro.
108 .Pq part of the standard preamble for Perl documentation .
109 Handled as a current-scope line macro.
112 Furthermore, the following escapes are accepted to allow
114 documents to be correctly formatted:
117 \e*(L" (left double-quote),
118 \e*(R" (right double-quote),
119 \e*(C` (left single-quote),
120 \e*(C' (right single-quote),
125 \e*/ (forward slash),
135 This section further defines the
140 available to programmers.
142 .Sx Abstract Syntax Tree
143 section documents the output tree.
149 may use the following types:
152 An opaque type defined in
154 Its values are only used privately within the library.
156 A function callback type defined in
158 .It Vt struct man_node
163 .Sx Abstract Syntax Tree
167 Function descriptions follow:
170 Allocates a parsing structure.
177 arguments are defined in
179 Returns NULL on failure.
180 If non-NULL, the pointer must be freed with
183 Reset the parser for another parse routine.
186 behaves as if invoked for the first time.
188 Free all resources of a parser.
189 The pointer is no longer valid after invocation.
191 Parse a nil-terminated line of input.
192 This line should not contain the trailing newline.
193 Returns 0 on failure, 1 on success.
196 is modified by this function.
198 Signals that the parse is complete.
201 is called subsequent to
203 the resulting tree is incomplete.
204 Returns 0 on failure, 1 on success.
206 Returns the first node of the parse.
211 return 0, the tree will be incomplete.
213 Returns the document's parsed meta-data.
214 If this information has not yet been supplied or
218 return 0, the data will be incomplete.
221 The following variables are also defined:
223 .It Va man_macronames
224 An array of string-ified token names.
226 .Ss Abstract Syntax Tree
229 functions produce an abstract syntax tree (AST) describing input in a
231 It may be reviewed at any time with
233 however, if called before
239 fail, it may be incomplete.
241 This AST is governed by the ontological rules dictated in
243 and derives its terminology accordingly.
245 The AST is composed of
247 nodes with element, root and text types as declared by the
250 Each node also provides its parse point (the
255 fields), its position in the tree (the
261 fields) and some type-specific data.
263 The tree itself is arranged according to the following normal form,
264 where capitalised non-terminals represent nodes.
266 .Bl -tag -width "ELEMENTXX" -compact
270 \(<- ELEMENT | TEXT | BLOCK
283 The only elements capable of nesting other elements are those with
284 next-lint scope as documented in
287 The following example reads lines from stdin and parses them, operating
288 on the finished parse tree with
290 This example does not error-check nor free memory upon failure.
291 .Bd -literal -offset indent
294 struct man_node *node;
299 bzero(®s, sizeof(struct regset));
301 man = man_alloc(®s, NULL, 0, NULL);
305 while ((len = getline(&buf, &alloc_len, stdin)) >= 0) {
306 if (len && buflen[len - 1] = '\en')
307 buf[len - 1] = '\e0';
308 if ( ! man_parseln(man, line, buf))
309 errx(1, "man_parseln");
315 if ( ! man_endparse(man))
316 errx(1, "man_endparse");
317 if (NULL == (node = man_node(man)))
326 in the source archive for a rigorous reference.
333 library was written by
334 .An Kristaps Dzonsons Aq kristaps@bsd.lv .