]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.170 2015/02/03 00:48:47 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2015 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.
20 #include <sys/types.h>
32 #include "libmandoc.h"
34 enum rew
{ /* see rew_dohalt() */
41 static void blk_full(MACRO_PROT_ARGS
);
42 static void blk_exp_close(MACRO_PROT_ARGS
);
43 static void blk_part_exp(MACRO_PROT_ARGS
);
44 static void blk_part_imp(MACRO_PROT_ARGS
);
45 static void ctx_synopsis(MACRO_PROT_ARGS
);
46 static void in_line_eoln(MACRO_PROT_ARGS
);
47 static void in_line_argn(MACRO_PROT_ARGS
);
48 static void in_line(MACRO_PROT_ARGS
);
49 static void phrase_ta(MACRO_PROT_ARGS
);
51 static void dword(struct mdoc
*, int, int, const char *,
53 static void append_delims(struct mdoc
*, int, int *, char *);
54 static enum mdoct
lookup(struct mdoc
*, enum mdoct
,
55 int, int, const char *);
56 static int macro_or_word(MACRO_PROT_ARGS
, int);
57 static void make_pending(struct mdoc
*, struct mdoc_node
*,
58 struct mdoc_node
*, int, int);
59 static int parse_rest(struct mdoc
*, enum mdoct
,
61 static enum mdoct
rew_alt(enum mdoct
);
62 static enum rew
rew_dohalt(enum mdoct
, enum mdoc_type
,
63 const struct mdoc_node
*);
64 static void rew_elem(struct mdoc
*, enum mdoct
);
65 static void rew_last(struct mdoc
*, const struct mdoc_node
*);
66 static void rew_pending(struct mdoc
*, const struct mdoc_node
*);
67 static void rew_sub(enum mdoc_type
, struct mdoc
*,
68 enum mdoct
, int, int);
70 const struct mdoc_macro __mdoc_macros
[MDOC_MAX
] = {
71 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ap */
72 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
73 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
74 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
75 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Sh */
76 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Ss */
77 { in_line_eoln
, 0 }, /* Pp */
78 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* D1 */
79 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* Dl */
80 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
81 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ed */
82 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
83 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* El */
84 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* It */
85 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* An */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Cd */
89 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
90 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
91 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
92 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
93 { in_line_eoln
, 0 }, /* Ex */
94 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
95 { in_line_eoln
, 0 }, /* Fd */
96 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
97 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
98 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
99 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ic */
100 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
101 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Li */
102 { blk_full
, MDOC_JOIN
}, /* Nd */
103 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
104 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
105 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ot */
106 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
107 { in_line_eoln
, 0 }, /* Rv */
108 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
109 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
110 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
111 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
112 { in_line_eoln
, MDOC_JOIN
}, /* %A */
113 { in_line_eoln
, MDOC_JOIN
}, /* %B */
114 { in_line_eoln
, MDOC_JOIN
}, /* %D */
115 { in_line_eoln
, MDOC_JOIN
}, /* %I */
116 { in_line_eoln
, MDOC_JOIN
}, /* %J */
117 { in_line_eoln
, 0 }, /* %N */
118 { in_line_eoln
, MDOC_JOIN
}, /* %O */
119 { in_line_eoln
, 0 }, /* %P */
120 { in_line_eoln
, MDOC_JOIN
}, /* %R */
121 { in_line_eoln
, MDOC_JOIN
}, /* %T */
122 { in_line_eoln
, 0 }, /* %V */
123 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
124 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ac */
125 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
126 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ao */
127 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Aq */
128 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
129 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
130 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bc */
131 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
132 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
133 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bo */
134 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Bq */
135 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
136 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
137 { in_line_eoln
, 0 }, /* Db */
138 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
139 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Dc */
140 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
141 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Do */
142 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Dq */
143 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ec */
144 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ef */
145 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Em */
146 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
147 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
148 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
149 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* No */
150 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
151 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ns */
152 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
153 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
154 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
155 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Pc */
156 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
157 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
158 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Po */
159 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Pq */
160 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
161 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qc */
162 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ql */
163 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
164 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qo */
165 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Qq */
166 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Re */
167 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
168 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
169 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Sc */
170 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
171 MDOC_EXPLICIT
| MDOC_JOIN
}, /* So */
172 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sq */
173 { in_line_argn
, 0 }, /* Sm */
174 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sx */
175 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sy */
176 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
177 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ux */
178 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
179 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
180 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
181 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
182 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Fc */
183 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
184 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oo */
185 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
186 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oc */
187 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
188 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ek */
189 { in_line_eoln
, 0 }, /* Bt */
190 { in_line_eoln
, 0 }, /* Hf */
191 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fr */
192 { in_line_eoln
, 0 }, /* Ud */
193 { in_line
, 0 }, /* Lb */
194 { in_line_eoln
, 0 }, /* Lp */
195 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
196 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
197 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Brq */
198 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
199 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bro */
200 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
201 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Brc */
202 { in_line_eoln
, MDOC_JOIN
}, /* %C */
203 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Es */
204 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* En */
205 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
206 { in_line_eoln
, MDOC_JOIN
}, /* %Q */
207 { in_line_eoln
, 0 }, /* br */
208 { in_line_eoln
, 0 }, /* sp */
209 { in_line_eoln
, 0 }, /* %U */
210 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ta */
211 { in_line_eoln
, MDOC_PROLOGUE
}, /* ll */
214 const struct mdoc_macro
* const mdoc_macros
= __mdoc_macros
;
218 * This is called at the end of parsing. It must traverse up the tree,
219 * closing out open [implicit] scopes. Obviously, open explicit scopes
223 mdoc_macroend(struct mdoc
*mdoc
)
227 /* Scan for open explicit scopes. */
229 n
= mdoc
->last
->flags
& MDOC_VALID
?
230 mdoc
->last
->parent
: mdoc
->last
;
232 for ( ; n
; n
= n
->parent
)
233 if (n
->type
== MDOC_BLOCK
&&
234 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
)
235 mandoc_msg(MANDOCERR_BLK_NOEND
, mdoc
->parse
,
236 n
->line
, n
->pos
, mdoc_macronames
[n
->tok
]);
238 /* Rewind to the first. */
240 rew_last(mdoc
, mdoc
->first
);
244 * Look up the macro at *p called by "from",
245 * or as a line macro if from == MDOC_MAX.
248 lookup(struct mdoc
*mdoc
, enum mdoct from
, int line
, int ppos
, const char *p
)
252 if (from
== MDOC_MAX
|| mdoc_macros
[from
].flags
& MDOC_PARSED
) {
253 res
= mdoc_hash_find(p
);
254 if (res
!= MDOC_MAX
) {
255 if (mdoc_macros
[res
].flags
& MDOC_CALLABLE
)
257 if (res
!= MDOC_br
&& res
!= MDOC_sp
&& res
!= MDOC_ll
)
258 mandoc_msg(MANDOCERR_MACRO_CALL
,
259 mdoc
->parse
, line
, ppos
, p
);
266 * Rewind up to and including a specific node.
269 rew_last(struct mdoc
*mdoc
, const struct mdoc_node
*to
)
271 struct mdoc_node
*n
, *np
;
274 mdoc
->next
= MDOC_NEXT_SIBLING
;
275 while (mdoc
->last
!= to
) {
276 if ( ! (mdoc
->last
->flags
& MDOC_VALID
))
277 mdoc
->last
->lastline
= to
->lastline
-
278 (mdoc
->flags
& MDOC_NEWLINE
? 1 : 0);
280 * Save the parent here, because we may delete the
281 * mdoc->last node in the post-validation phase and reset
282 * it to mdoc->last->parent, causing a step in the closing
285 np
= mdoc
->last
->parent
;
286 mdoc_valid_post(mdoc
);
290 mdoc
->last
->last
= n
;
292 mdoc_valid_post(mdoc
);
296 * Rewind up to a specific block, including all blocks that broke it.
299 rew_pending(struct mdoc
*mdoc
, const struct mdoc_node
*n
)
304 if (n
->type
!= MDOC_BLOCK
)
307 while ((n
= n
->pending
) != NULL
) {
309 if (n
->type
== MDOC_HEAD
)
310 mdoc_body_alloc(mdoc
, n
->line
, n
->pos
, n
->tok
);
315 * For a block closing macro, return the corresponding opening one.
316 * Otherwise, return the macro itself.
319 rew_alt(enum mdoct tok
)
361 * Rewinding to tok, how do we have to handle *p?
362 * REWIND_NONE: *p would delimit tok, but no tok scope is open
363 * inside *p, so there is no need to rewind anything at all.
364 * REWIND_THIS: *p matches tok, so rewind *p and nothing else.
365 * REWIND_MORE: *p is implicit, rewind it and keep searching for tok.
366 * REWIND_FORCE: *p is explicit, but tok is full, force rewinding *p.
369 rew_dohalt(enum mdoct tok
, enum mdoc_type type
,
370 const struct mdoc_node
*p
)
374 * No matching token, no delimiting block, no broken block.
375 * This can happen when full implicit macros are called for
376 * the first time but try to rewind their previous
379 if (MDOC_ROOT
== p
->type
)
383 * When starting to rewind, skip plain text
384 * and nodes that have already been rewound.
386 if (p
->type
== MDOC_TEXT
|| p
->flags
& (MDOC_VALID
| MDOC_BREAK
))
390 * The easiest case: Found a matching token.
391 * This applies to both blocks and elements.
395 return(type
== p
->type
? REWIND_THIS
: REWIND_MORE
);
398 * While elements do require rewinding for themselves,
399 * they never affect rewinding of other nodes.
401 if (MDOC_ELEM
== p
->type
)
405 * Blocks delimited by our target token get REWIND_MORE.
406 * Blocks delimiting our target token get REWIND_NONE.
410 if (MDOC_BODY
== p
->type
&& MDOC_Bl
== p
->tok
)
418 if (MDOC_BODY
== p
->type
&& MDOC_Sh
== p
->tok
)
422 if (MDOC_ROOT
== p
->parent
->type
)
424 if (MDOC_Nd
== p
->tok
|| MDOC_Ss
== p
->tok
||
433 * Default block rewinding rules.
434 * In particular, let all blocks rewind Nm children.
435 * Do not warn again when closing a block,
436 * since closing the body already warned.
438 if (MDOC_Nm
== p
->tok
||
439 MDOC_BLOCK
== type
|| MDOC_BLOCK
== p
->type
)
443 * By default, closing out full blocks
444 * forces closing of broken explicit blocks.
446 return (REWIND_FORCE
);
450 rew_elem(struct mdoc
*mdoc
, enum mdoct tok
)
455 if (MDOC_ELEM
!= n
->type
)
457 assert(MDOC_ELEM
== n
->type
);
458 assert(tok
== n
->tok
);
463 * We are trying to close the block *breaker,
464 * but the child block *broken is still open.
465 * Thus, postpone closing the *breaker
466 * until the rew_pending() call closing *broken.
469 make_pending(struct mdoc
*mdoc
, struct mdoc_node
*breaker
,
470 struct mdoc_node
*broken
, int line
, int ppos
)
474 mandoc_vmsg(MANDOCERR_BLK_NEST
, mdoc
->parse
, line
, ppos
,
475 "%s breaks %s", mdoc_macronames
[breaker
->tok
],
476 mdoc_macronames
[broken
->tok
]);
479 * If the *broken block (Z) is already broken by a block (B)
480 * contained in the breaker (A), make the breaker pending
481 * on that inner breaker (B). Graphically,
483 * breaker=[A! broken=n=[B!->A (old broken=)[Z->B B] A] Z]
485 * In these graphics, "->" indicates the "pending" pointer and
486 * "!" indicates the MDOC_BREAK flag. Each of the cases gets
487 * one additional pointer (B->A) and one additional flag (A!).
490 for (n
= broken
->parent
; ; n
= n
->parent
)
491 if (n
== broken
->pending
)
493 else if (n
== breaker
)
499 * If another, outer breaker (X) is already pending on
500 * the *broken block (B), we must not clobber the link
501 * to the outer breaker, but make it pending on the new,
502 * now inner breaker (A). Graphically,
504 * [X! n=breaker=[A!->X broken=[B(->X)->A X] A] B].
507 if (broken
->pending
!= NULL
) {
511 * If the inner breaker (A) is already broken, too,
512 * it cannot take on the outer breaker (X) but must
513 * hand it on to its own breakers (Y). Graphically,
515 * [X! n=[Y!->X breaker=[A!->Y Y] broken=[B(->X)->A X] A] B]
520 n
->pending
= broken
->pending
;
524 * Now we have reduced the situation to the simplest case:
525 * breaker=[A! broken=[B->A A] B].
528 broken
->pending
= breaker
;
529 breaker
->flags
|= MDOC_BREAK
;
530 if (breaker
->body
!= NULL
)
531 breaker
->body
->flags
|= MDOC_BREAK
;
535 rew_sub(enum mdoc_type t
, struct mdoc
*mdoc
,
536 enum mdoct tok
, int line
, int ppos
)
538 struct mdoc_node
*n
, *to
;
543 switch (rew_dohalt(tok
, t
, n
)) {
551 (mdoc
->flags
& MDOC_NEWLINE
&&
552 ! (mdoc_macros
[tok
].flags
& MDOC_EXPLICIT
));
555 mandoc_vmsg(MANDOCERR_BLK_BROKEN
, mdoc
->parse
,
556 line
, ppos
, "%s breaks %s",
557 mdoc_macronames
[tok
],
558 mdoc_macronames
[n
->tok
]);
562 (mdoc
->flags
& MDOC_NEWLINE
? 1 : 0);
570 rew_pending(mdoc
, n
);
574 * Allocate a word and check whether it's punctuation or not.
575 * Punctuation consists of those tokens found in mdoc_isdelim().
578 dword(struct mdoc
*mdoc
, int line
, int col
, const char *p
,
579 enum mdelim d
, int may_append
)
586 ! (mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_KEEP
| MDOC_SMOFF
)) &&
587 d
== DELIM_NONE
&& mdoc
->last
->type
== MDOC_TEXT
&&
588 mdoc_isdelim(mdoc
->last
->string
) == DELIM_NONE
) {
589 mdoc_word_append(mdoc
, p
);
593 mdoc_word_alloc(mdoc
, line
, col
, p
);
596 * If the word consists of a bare delimiter,
597 * flag the new node accordingly,
598 * unless doing so was vetoed by the invoking macro.
599 * Always clear the veto, it is only valid for one word.
603 mdoc
->last
->flags
|= MDOC_DELIMO
;
604 else if (d
== DELIM_CLOSE
&&
605 ! (mdoc
->flags
& MDOC_NODELIMC
) &&
606 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
607 mdoc
->last
->flags
|= MDOC_DELIMC
;
608 mdoc
->flags
&= ~MDOC_NODELIMC
;
612 append_delims(struct mdoc
*mdoc
, int line
, int *pos
, char *buf
)
617 if (buf
[*pos
] == '\0')
622 if (mdoc_args(mdoc
, line
, pos
, buf
, MDOC_MAX
, &p
) == ARGS_EOLN
)
624 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 1);
627 * If we encounter end-of-sentence symbols, then trigger
630 * XXX: it's easy to allow this to propagate outward to
631 * the last symbol, such that `. )' will cause the
632 * correct double-spacing. However, (1) groff isn't
633 * smart enough to do this and (2) it would require
634 * knowing which symbols break this behaviour, for
635 * example, `. ;' shouldn't propagate the double-space.
638 if (mandoc_eos(p
, strlen(p
)))
639 mdoc
->last
->flags
|= MDOC_EOS
;
645 * If it is a macro, call it and return 1.
646 * Otherwise, allocate it and return 0.
649 macro_or_word(MACRO_PROT_ARGS
, int parsed
)
658 else if (parsed
&& ! (mdoc
->flags
& MDOC_PHRASELIT
))
659 ntok
= lookup(mdoc
, tok
, line
, ppos
, p
);
661 if (ntok
== MDOC_MAX
) {
662 dword(mdoc
, line
, ppos
, p
, DELIM_MAX
, tok
== MDOC_MAX
||
663 mdoc_macros
[tok
].flags
& MDOC_JOIN
);
666 if (mdoc_macros
[tok
].fp
== in_line_eoln
)
668 mdoc_macro(mdoc
, ntok
, line
, ppos
, pos
, buf
);
670 append_delims(mdoc
, line
, pos
, buf
);
676 * Close out block partial/full explicit.
679 blk_exp_close(MACRO_PROT_ARGS
)
681 struct mdoc_node
*body
; /* Our own body. */
682 struct mdoc_node
*endbody
; /* Our own end marker. */
683 struct mdoc_node
*later
; /* A sub-block starting later. */
684 struct mdoc_node
*n
; /* Search back to our block. */
686 int have_it
, j
, lastarg
, maxargs
, nl
;
688 enum mdoct atok
, ntok
;
691 nl
= MDOC_NEWLINE
& mdoc
->flags
;
698 mdoc
->flags
&= ~MDOC_KEEP
;
706 * Search backwards for beginnings of blocks,
707 * both of our own and of pending sub-blocks.
712 body
= endbody
= later
= NULL
;
713 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
714 if (n
->flags
& (MDOC_VALID
| MDOC_BREAK
))
717 /* Remember the start of our own body. */
719 if (n
->type
== MDOC_BODY
&& atok
== n
->tok
) {
720 if (n
->end
== ENDBODY_NOT
) {
727 if (n
->type
!= MDOC_BLOCK
|| n
->tok
== MDOC_Nm
)
730 if (n
->tok
== MDOC_It
) {
735 if (atok
== n
->tok
) {
740 * Found the start of our own block.
741 * When there is no pending sub block,
742 * just proceed to closing out.
746 (tok
== MDOC_El
&& !have_it
))
750 * When there is a pending sub block, postpone
751 * closing out the current block until the
752 * rew_pending() closing out the sub-block.
755 make_pending(mdoc
, n
, later
, line
, ppos
);
758 * Mark the place where the formatting - but not
759 * the scope - of the current block ends.
762 endbody
= mdoc_endbody_alloc(mdoc
, line
, ppos
,
763 atok
, body
, ENDBODY_SPACE
);
766 * If a block closing macro taking arguments
767 * breaks another block, put the arguments
768 * into the end marker.
772 mdoc
->next
= MDOC_NEXT_CHILD
;
777 * When finding an open sub block, remember the last
778 * open explicit block, or, in case there are only
779 * implicit ones, the first open implicit block.
783 ! (mdoc_macros
[later
->tok
].flags
& MDOC_EXPLICIT
))
788 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, mdoc
->parse
,
789 line
, ppos
, mdoc_macronames
[tok
]);
790 if (maxargs
&& endbody
== NULL
) {
792 * Stray .Ec without previous .Eo:
793 * Break the output line, keep the arguments.
795 mdoc_elem_alloc(mdoc
, line
, ppos
, MDOC_br
, NULL
);
796 rew_elem(mdoc
, MDOC_br
);
798 } else if (endbody
== NULL
) {
799 rew_last(mdoc
, body
);
801 mdoc_tail_alloc(mdoc
, line
, ppos
, atok
);
804 if ( ! (mdoc_macros
[tok
].flags
& MDOC_PARSED
)) {
805 if (buf
[*pos
] != '\0')
806 mandoc_vmsg(MANDOCERR_ARG_SKIP
,
807 mdoc
->parse
, line
, ppos
,
808 "%s %s", mdoc_macronames
[tok
],
811 rew_pending(mdoc
, n
);
820 if (j
== maxargs
&& n
!= NULL
) {
821 rew_pending(mdoc
, n
);
825 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
826 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
829 ntok
= ac
== ARGS_QWORD
? MDOC_MAX
:
830 lookup(mdoc
, tok
, line
, lastarg
, p
);
832 if (ntok
== MDOC_MAX
) {
833 dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
,
834 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
839 rew_pending(mdoc
, n
);
842 mdoc
->flags
&= ~MDOC_NEWLINE
;
843 mdoc_macro(mdoc
, ntok
, line
, lastarg
, pos
, buf
);
848 rew_pending(mdoc
, n
);
850 append_delims(mdoc
, line
, pos
, buf
);
854 in_line(MACRO_PROT_ARGS
)
856 int la
, scope
, cnt
, firstarg
, mayopen
, nc
, nl
;
860 struct mdoc_arg
*arg
;
863 nl
= MDOC_NEWLINE
& mdoc
->flags
;
866 * Whether we allow ignored elements (those without content,
867 * usually because of reserved words) to squeak by.
889 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
894 for (cnt
= scope
= 0;; ) {
896 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
899 * At the end of a macro line,
900 * opening delimiters do not suppress spacing.
903 if (ac
== ARGS_EOLN
) {
905 mdoc
->last
->flags
&= ~MDOC_DELIMO
;
910 * The rest of the macro line is only punctuation,
911 * to be handled by append_delims().
912 * If there were no other arguments,
913 * do not allow the first one to suppress spacing,
914 * even if it turns out to be a closing one.
917 if (ac
== ARGS_PUNCT
) {
918 if (cnt
== 0 && nc
== 0)
919 mdoc
->flags
|= MDOC_NODELIMC
;
923 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Fn
&& !cnt
)) ?
924 MDOC_MAX
: lookup(mdoc
, tok
, line
, la
, p
);
927 * In this case, we've located a submacro and must
928 * execute it. Close out scope, if open. If no
929 * elements have been generated, either create one (nc)
930 * or raise a warning.
933 if (ntok
!= MDOC_MAX
) {
937 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
938 rew_last(mdoc
, mdoc
->last
);
939 } else if ( ! nc
&& ! cnt
) {
941 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
942 mdoc
->parse
, line
, ppos
,
943 mdoc_macronames
[tok
]);
945 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
947 append_delims(mdoc
, line
, pos
, buf
);
952 * Non-quote-enclosed punctuation. Set up our scope, if
953 * a word; rewind the scope, if a delimiter; then append
957 d
= ac
== ARGS_QWORD
? DELIM_NONE
: mdoc_isdelim(p
);
959 if (DELIM_NONE
!= d
) {
961 * If we encounter closing punctuation, no word
962 * has been emitted, no scope is open, and we're
963 * allowed to have an empty element, then start
966 if ((d
== DELIM_CLOSE
||
967 (d
== DELIM_MIDDLE
&& tok
== MDOC_Fl
)) &&
968 !cnt
&& !scope
&& nc
&& mayopen
) {
969 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
976 * Close out our scope, if one is open, before
984 } else if (mayopen
&& !scope
) {
985 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
990 dword(mdoc
, line
, la
, p
, d
,
991 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
994 * If the first argument is a closing delimiter,
995 * do not suppress spacing before it.
998 if (firstarg
&& d
== DELIM_CLOSE
&& !nc
)
999 mdoc
->last
->flags
&= ~MDOC_DELIMC
;
1003 * `Fl' macros have their scope re-opened with each new
1004 * word so that the `-' can be added to each one without
1005 * having to parse out spaces.
1007 if (scope
&& tok
== MDOC_Fl
) {
1008 rew_elem(mdoc
, tok
);
1014 rew_elem(mdoc
, tok
);
1017 * If no elements have been collected and we're allowed to have
1018 * empties (nc), open a scope and close it out. Otherwise,
1024 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1025 rew_last(mdoc
, mdoc
->last
);
1027 mdoc_argv_free(arg
);
1028 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
1029 line
, ppos
, mdoc_macronames
[tok
]);
1033 append_delims(mdoc
, line
, pos
, buf
);
1037 blk_full(MACRO_PROT_ARGS
)
1040 struct mdoc_arg
*arg
;
1041 struct mdoc_node
*blk
; /* Our own block. */
1042 struct mdoc_node
*head
; /* Our own head. */
1043 struct mdoc_node
*body
; /* Our own body. */
1044 struct mdoc_node
*n
;
1045 enum margserr ac
, lac
;
1048 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1050 /* Skip items outside lists. */
1052 if (tok
== MDOC_It
) {
1053 for (n
= mdoc
->last
; n
; n
= n
->parent
)
1054 if (n
->tok
== MDOC_Bl
&& n
->type
== MDOC_BLOCK
&&
1055 ! (n
->flags
& (MDOC_VALID
| MDOC_BREAK
)))
1058 mandoc_vmsg(MANDOCERR_IT_STRAY
, mdoc
->parse
,
1059 line
, ppos
, "It %s", buf
+ *pos
);
1060 mdoc_elem_alloc(mdoc
, line
, ppos
, MDOC_br
, NULL
);
1061 rew_elem(mdoc
, MDOC_br
);
1066 /* Close out prior implicit scope. */
1068 if ( ! (mdoc_macros
[tok
].flags
& MDOC_EXPLICIT
)) {
1069 rew_sub(MDOC_BODY
, mdoc
, tok
, line
, ppos
);
1070 rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
);
1074 * This routine accommodates implicitly- and explicitly-scoped
1075 * macro openings. Implicit ones first close out prior scope
1076 * (seen above). Delay opening the head until necessary to
1077 * allow leading punctuation to print. Special consideration
1078 * for `It -column', which has phrase-part syntax instead of
1079 * regular child nodes.
1082 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1083 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
);
1087 * Exception: Heads of `It' macros in `-diag' lists are not
1088 * parsed, even though `It' macros in general are parsed.
1091 parsed
= tok
!= MDOC_It
||
1092 mdoc
->last
->parent
->tok
!= MDOC_Bl
||
1093 mdoc
->last
->parent
->norm
->Bl
.type
!= LIST_diag
;
1096 * The `Nd' macro has all arguments in its body: it's a hybrid
1097 * of block partial-explicit and full-implicit. Stupid.
1100 if (tok
== MDOC_Nd
) {
1101 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1102 rew_last(mdoc
, head
);
1103 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1107 mdoc
->flags
|= MDOC_KEEP
;
1113 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1114 if (ac
== ARGS_PUNCT
)
1116 if (ac
== ARGS_EOLN
) {
1117 if (lac
!= ARGS_PPHRASE
&& lac
!= ARGS_PHRASE
)
1120 * This is necessary: if the last token on a
1121 * line is a `Ta' or tab, then we'll get
1122 * ARGS_EOLN, so we must be smart enough to
1123 * reopen our scope if the last parse was a
1124 * phrase or partial phrase.
1127 rew_last(mdoc
, body
);
1128 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1133 * Emit leading punctuation (i.e., punctuation before
1134 * the MDOC_HEAD) for non-phrase types.
1139 ac
!= ARGS_PHRASE
&&
1140 ac
!= ARGS_PPHRASE
&&
1142 mdoc_isdelim(p
) == DELIM_OPEN
) {
1143 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1147 /* Open a head if one hasn't been opened. */
1150 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1152 if (ac
== ARGS_PHRASE
||
1154 ac
== ARGS_PPHRASE
) {
1157 * If we haven't opened a body yet, rewind the
1158 * head; if we have, rewind that instead.
1161 rew_last(mdoc
, body
== NULL
? head
: body
);
1162 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1165 * Process phrases: set whether we're in a
1166 * partial-phrase (this effects line handling)
1167 * then call down into the phrase parser.
1170 if (ac
== ARGS_PPHRASE
)
1171 mdoc
->flags
|= MDOC_PPHRASE
;
1172 if (ac
== ARGS_PEND
&& lac
== ARGS_PPHRASE
)
1173 mdoc
->flags
|= MDOC_PPHRASE
;
1174 parse_rest(mdoc
, MDOC_MAX
, line
, &la
, buf
);
1175 mdoc
->flags
&= ~MDOC_PPHRASE
;
1179 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, parsed
))
1183 if (blk
->flags
& MDOC_VALID
)
1186 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1188 append_delims(mdoc
, line
, pos
, buf
);
1193 * If there is an open (i.e., unvalidated) sub-block requiring
1194 * explicit close-out, postpone switching the current block from
1195 * head to body until the rew_pending() call closing out that
1198 for (n
= mdoc
->last
; n
&& n
!= head
; n
= n
->parent
) {
1199 if (n
->type
== MDOC_BLOCK
&&
1200 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
&&
1201 ! (n
->flags
& MDOC_VALID
)) {
1207 /* Close out scopes to remain in a consistent state. */
1209 rew_last(mdoc
, head
);
1210 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1212 if (mdoc
->flags
& MDOC_FREECOL
) {
1213 rew_last(mdoc
, body
);
1214 rew_last(mdoc
, blk
);
1215 mdoc
->flags
&= ~MDOC_FREECOL
;
1220 blk_part_imp(MACRO_PROT_ARGS
)
1225 struct mdoc_node
*blk
; /* saved block context */
1226 struct mdoc_node
*body
; /* saved body context */
1227 struct mdoc_node
*n
;
1229 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1232 * A macro that spans to the end of the line. This is generally
1233 * (but not necessarily) called as the first macro. The block
1234 * has a head as the immediate child, which is always empty,
1235 * followed by zero or more opening punctuation nodes, then the
1236 * body (which may be empty, depending on the macro), then zero
1237 * or more closing punctuation nodes.
1240 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1241 rew_last(mdoc
, mdoc_head_alloc(mdoc
, line
, ppos
, tok
));
1244 * Open the body scope "on-demand", that is, after we've
1245 * processed all our the leading delimiters (open parenthesis,
1249 for (body
= NULL
; ; ) {
1251 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1252 if (ac
== ARGS_EOLN
|| ac
== ARGS_PUNCT
)
1255 if (body
== NULL
&& ac
!= ARGS_QWORD
&&
1256 mdoc_isdelim(p
) == DELIM_OPEN
) {
1257 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1262 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1264 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1268 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1271 * If there is an open sub-block requiring explicit close-out,
1272 * postpone closing out the current block until the
1273 * rew_pending() call closing out the sub-block.
1276 for (n
= mdoc
->last
; n
&& n
!= body
&& n
!= blk
->parent
;
1278 if (n
->type
== MDOC_BLOCK
&&
1279 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
&&
1280 ! (n
->flags
& MDOC_VALID
)) {
1281 make_pending(mdoc
, blk
, n
, line
, ppos
);
1282 mdoc_endbody_alloc(mdoc
, line
, ppos
,
1283 tok
, body
, ENDBODY_NOSPACE
);
1288 rew_last(mdoc
, body
);
1290 append_delims(mdoc
, line
, pos
, buf
);
1291 rew_pending(mdoc
, blk
);
1293 /* Move trailing .Ns out of scope. */
1295 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1297 if (n
&& n
->tok
== MDOC_Ns
)
1298 mdoc_node_relink(mdoc
, n
);
1302 blk_part_exp(MACRO_PROT_ARGS
)
1306 struct mdoc_node
*head
; /* keep track of head */
1309 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1312 * The opening of an explicit macro having zero or more leading
1313 * punctuation nodes; a head with optional single element (the
1314 * case of `Eo'); and a body that may be empty.
1317 mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1321 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1322 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
1325 /* Flush out leading punctuation. */
1327 if (head
== NULL
&& ac
!= ARGS_QWORD
&&
1328 mdoc_isdelim(p
) == DELIM_OPEN
) {
1329 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1334 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1335 if (tok
== MDOC_Eo
) /* Not parsed. */
1336 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 0);
1337 rew_last(mdoc
, head
);
1338 mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1343 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1347 /* Clean-up to leave in a consistent state. */
1350 rew_last(mdoc
, mdoc_head_alloc(mdoc
, line
, ppos
, tok
));
1351 mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1354 append_delims(mdoc
, line
, pos
, buf
);
1358 in_line_argn(MACRO_PROT_ARGS
)
1360 int la
, flushed
, j
, maxargs
, nl
;
1362 struct mdoc_arg
*arg
;
1366 nl
= mdoc
->flags
& MDOC_NEWLINE
;
1369 * A line macro that has a fixed number of arguments (maxargs).
1370 * Only open the scope once the first non-leading-punctuation is
1371 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1372 * keep it open until the maximum number of arguments are
1396 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1402 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1403 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
) {
1404 if (j
< 2 && tok
== MDOC_Pf
)
1405 mandoc_vmsg(MANDOCERR_PF_SKIP
,
1406 mdoc
->parse
, line
, ppos
, "Pf %s",
1407 p
== NULL
? "at eol" : p
);
1411 if ( ! (mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
) &&
1412 ac
!= ARGS_QWORD
&& j
== 0 &&
1413 mdoc_isdelim(p
) == DELIM_OPEN
) {
1414 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1417 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1419 if (j
== maxargs
&& ! flushed
) {
1420 rew_elem(mdoc
, tok
);
1424 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Pf
&& j
== 0)) ?
1425 MDOC_MAX
: lookup(mdoc
, tok
, line
, la
, p
);
1427 if (ntok
!= MDOC_MAX
) {
1429 rew_elem(mdoc
, tok
);
1431 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
1436 if ( ! (mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
) &&
1437 ac
!= ARGS_QWORD
&& ! flushed
&&
1438 mdoc_isdelim(p
) != DELIM_NONE
) {
1439 rew_elem(mdoc
, tok
);
1443 dword(mdoc
, line
, la
, p
, DELIM_MAX
,
1444 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
1449 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1450 if (ac
== ARGS_PUNCT
&& tok
== MDOC_Pf
)
1451 append_delims(mdoc
, line
, pos
, buf
);
1454 rew_elem(mdoc
, tok
);
1456 append_delims(mdoc
, line
, pos
, buf
);
1460 in_line_eoln(MACRO_PROT_ARGS
)
1462 struct mdoc_node
*n
;
1463 struct mdoc_arg
*arg
;
1465 if ((tok
== MDOC_Pp
|| tok
== MDOC_Lp
) &&
1466 ! (mdoc
->flags
& MDOC_SYNOPSIS
)) {
1468 if (mdoc
->next
== MDOC_NEXT_SIBLING
)
1470 if (n
->tok
== MDOC_Nm
)
1471 rew_last(mdoc
, mdoc
->last
->parent
);
1474 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1475 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1476 if (parse_rest(mdoc
, tok
, line
, pos
, buf
))
1478 rew_elem(mdoc
, tok
);
1482 * The simplest argument parser available: Parse the remaining
1483 * words until the end of the phrase or line and return 0
1484 * or until the next macro, call that macro, and return 1.
1487 parse_rest(struct mdoc
*mdoc
, enum mdoct tok
, int line
, int *pos
, char *buf
)
1493 if (mdoc_args(mdoc
, line
, pos
, buf
, tok
, NULL
) == ARGS_EOLN
)
1495 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1501 ctx_synopsis(MACRO_PROT_ARGS
)
1504 if (~mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_NEWLINE
))
1505 in_line(mdoc
, tok
, line
, ppos
, pos
, buf
);
1506 else if (tok
== MDOC_Nm
)
1507 blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
);
1509 assert(tok
== MDOC_Vt
);
1510 blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
);
1515 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1516 * They're unusual because they're basically free-form text until a
1517 * macro is encountered.
1520 phrase_ta(MACRO_PROT_ARGS
)
1522 struct mdoc_node
*body
, *n
;
1524 /* Make sure we are in a column list or ignore this macro. */
1527 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
1528 if (n
->flags
& (MDOC_VALID
| MDOC_BREAK
))
1530 if (n
->tok
== MDOC_It
&& n
->type
== MDOC_BODY
)
1532 if (n
->tok
== MDOC_Bl
)
1536 if (n
== NULL
|| n
->norm
->Bl
.type
!= LIST_column
) {
1537 mandoc_msg(MANDOCERR_TA_STRAY
, mdoc
->parse
,
1542 /* Advance to the next column. */
1544 rew_last(mdoc
, body
);
1545 mdoc_body_alloc(mdoc
, line
, ppos
, MDOC_It
);
1546 parse_rest(mdoc
, MDOC_MAX
, line
, pos
, buf
);