2 .Dd $Mdocdate: January 20 2009 $
13 .Nd mdoc macro compiler library
17 .Vt extern const char * const * mdoc_macronames;
18 .Vt extern const char * const * mdoc_argnames;
20 .Fn mdoc_alloc "void *data" "const struct mdoc_cb *cb"
22 .Fn mdoc_free "struct mdoc *mdoc"
24 .Fn mdoc_parseln "struct mdoc *mdoc" "int line" "char *buf"
25 .Ft "const struct mdoc_node *"
26 .Fn mdoc_node "struct mdoc *mdoc"
27 .Ft "const struct mdoc_meta *"
28 .Fn mdoc_meta "struct mdoc *mdoc"
30 .Fn mdoc_endparse "struct mdoc *mdoc"
35 library parses lines of mdoc-macro text into an abstract syntax tree.
36 In general, applications initiate a parsing sequence with
38 parse each line in a document with
40 close the parsing session with
42 operate over the syntax tree returned by
46 then free all allocated memory with
50 section for a full example.
52 .\" Function descriptions.
53 Function descriptions follow:
54 .Bl -ohang -offset indent
56 Allocates a parsing structure. The
58 pointer is passed to callbacks in
60 which are documented further in the header file. Returns NULL on
61 failure. If non-NULL, the pointer must be freed with
64 Free all resources of a parser. The pointer is no longer valid after
67 Parse a nil-terminated line of input. This line should not contain the
68 trailing newline. Returns 0 on failure, 1 on success. The input buffer
70 is modified by this function.
72 Signals that the parse is complete. Note that if
74 is called subsequent to
76 the resulting tree is incomplete. Returns 0 on failure, 1 on success.
78 Returns the first node of the parse. Note that if
82 return 0, the tree will be incomplete.
84 Returns the document's parsed meta-data. If this information has not
89 return 0, the data will be incomplete.
92 .\" Variable descriptions.
93 The following variables are also defined:
94 .Bl -ohang -offset indent
95 .It Va mdoc_macronames
96 An array of string-ified token names.
98 An array of string-ified token argument names.
106 The following example reads lines from stdin and parses them, operating
107 on the finished parse tree with
109 Note that, if the last line of the file isn't newline-terminated, this
110 will truncate the file's last character (see
112 Further, this example does not error-check nor free memory upon failure.
115 struct mdoc_node *node;
121 mdoc = mdoc_alloc(NULL, NULL);
123 while ((buf = fgetln(fp, &len))) {
124 buf[len - 1] = '\\0';
125 if ( ! mdoc_parseln(mdoc, line, buf))
126 errx(1, "mdoc_parseln");
130 if ( ! mdoc_endparse(mdoc))
131 errx(1, "mdoc_endparse");
132 if (NULL == (node = mdoc_node(mdoc)))
133 errx(1, "mdoc_node");
149 utility was written by
150 .An Kristaps Dzonsons Aq kristaps@kth.se .
154 Bugs, un-implemented macros and incompabilities are documented in this
155 section. The baseline for determining whether macro parsing is
166 macros aren't handled when used to span lines for the
168 macro. Such usage is specifically discouraged in
173 is invoked, whitespace is not stripped around
175 or tab-character separators.
179 macro only accepts a single parameter. Furthermore, several macros
182 and possibly others) accept multiple arguments with a warning.
184 Incompatible: only those macros specified by
190 are supported; support for
192 and other BSD systems is in progress.