]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.173 2015/02/04 18:03: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 static void blk_full(MACRO_PROT_ARGS
);
35 static void blk_exp_close(MACRO_PROT_ARGS
);
36 static void blk_part_exp(MACRO_PROT_ARGS
);
37 static void blk_part_imp(MACRO_PROT_ARGS
);
38 static void ctx_synopsis(MACRO_PROT_ARGS
);
39 static void in_line_eoln(MACRO_PROT_ARGS
);
40 static void in_line_argn(MACRO_PROT_ARGS
);
41 static void in_line(MACRO_PROT_ARGS
);
42 static void phrase_ta(MACRO_PROT_ARGS
);
44 static void dword(struct mdoc
*, int, int, const char *,
46 static void append_delims(struct mdoc
*, int, int *, char *);
47 static enum mdoct
lookup(struct mdoc
*, enum mdoct
,
48 int, int, const char *);
49 static int macro_or_word(MACRO_PROT_ARGS
, int);
50 static void make_pending(struct mdoc
*, struct mdoc_node
*,
51 struct mdoc_node
*, int, int);
52 static int parse_rest(struct mdoc
*, enum mdoct
,
54 static enum mdoct
rew_alt(enum mdoct
);
55 static void rew_elem(struct mdoc
*, enum mdoct
);
56 static void rew_last(struct mdoc
*, const struct mdoc_node
*);
57 static void rew_pending(struct mdoc
*, const struct mdoc_node
*);
59 const struct mdoc_macro __mdoc_macros
[MDOC_MAX
] = {
60 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ap */
61 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
62 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
63 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
64 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Sh */
65 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Ss */
66 { in_line_eoln
, 0 }, /* Pp */
67 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* D1 */
68 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* Dl */
69 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
70 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ed */
71 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
72 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* El */
73 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* It */
74 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
75 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* An */
76 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
77 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Cd */
78 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
79 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
80 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
81 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
82 { in_line_eoln
, 0 }, /* Ex */
83 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
84 { in_line_eoln
, 0 }, /* Fd */
85 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ic */
89 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
90 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Li */
91 { blk_full
, MDOC_JOIN
}, /* Nd */
92 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
93 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
94 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ot */
95 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
96 { in_line_eoln
, 0 }, /* Rv */
97 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
98 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
99 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
100 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
101 { in_line_eoln
, MDOC_JOIN
}, /* %A */
102 { in_line_eoln
, MDOC_JOIN
}, /* %B */
103 { in_line_eoln
, MDOC_JOIN
}, /* %D */
104 { in_line_eoln
, MDOC_JOIN
}, /* %I */
105 { in_line_eoln
, MDOC_JOIN
}, /* %J */
106 { in_line_eoln
, 0 }, /* %N */
107 { in_line_eoln
, MDOC_JOIN
}, /* %O */
108 { in_line_eoln
, 0 }, /* %P */
109 { in_line_eoln
, MDOC_JOIN
}, /* %R */
110 { in_line_eoln
, MDOC_JOIN
}, /* %T */
111 { in_line_eoln
, 0 }, /* %V */
112 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
113 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ac */
114 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
115 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ao */
116 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Aq */
117 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
118 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
119 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bc */
120 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
121 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
122 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bo */
123 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Bq */
124 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
125 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
126 { in_line_eoln
, 0 }, /* Db */
127 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
128 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Dc */
129 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
130 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Do */
131 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Dq */
132 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ec */
133 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ef */
134 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Em */
135 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
136 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
137 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
138 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* No */
139 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
140 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ns */
141 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
142 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
143 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
144 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Pc */
145 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
146 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
147 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Po */
148 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Pq */
149 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
150 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qc */
151 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ql */
152 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
153 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qo */
154 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Qq */
155 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Re */
156 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
157 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
158 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Sc */
159 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
160 MDOC_EXPLICIT
| MDOC_JOIN
}, /* So */
161 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sq */
162 { in_line_argn
, 0 }, /* Sm */
163 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sx */
164 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sy */
165 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
166 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ux */
167 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
168 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
169 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
170 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
171 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Fc */
172 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
173 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oo */
174 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
175 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oc */
176 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
177 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ek */
178 { in_line_eoln
, 0 }, /* Bt */
179 { in_line_eoln
, 0 }, /* Hf */
180 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fr */
181 { in_line_eoln
, 0 }, /* Ud */
182 { in_line
, 0 }, /* Lb */
183 { in_line_eoln
, 0 }, /* Lp */
184 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
185 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
186 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Brq */
187 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
188 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bro */
189 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
190 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Brc */
191 { in_line_eoln
, MDOC_JOIN
}, /* %C */
192 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Es */
193 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* En */
194 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
195 { in_line_eoln
, MDOC_JOIN
}, /* %Q */
196 { in_line_eoln
, 0 }, /* br */
197 { in_line_eoln
, 0 }, /* sp */
198 { in_line_eoln
, 0 }, /* %U */
199 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ta */
200 { in_line_eoln
, MDOC_PROLOGUE
}, /* ll */
203 const struct mdoc_macro
* const mdoc_macros
= __mdoc_macros
;
207 * This is called at the end of parsing. It must traverse up the tree,
208 * closing out open [implicit] scopes. Obviously, open explicit scopes
212 mdoc_macroend(struct mdoc
*mdoc
)
216 /* Scan for open explicit scopes. */
218 n
= mdoc
->last
->flags
& MDOC_VALID
?
219 mdoc
->last
->parent
: mdoc
->last
;
221 for ( ; n
; n
= n
->parent
)
222 if (n
->type
== MDOC_BLOCK
&&
223 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
)
224 mandoc_msg(MANDOCERR_BLK_NOEND
, mdoc
->parse
,
225 n
->line
, n
->pos
, mdoc_macronames
[n
->tok
]);
227 /* Rewind to the first. */
229 rew_last(mdoc
, mdoc
->first
);
233 * Look up the macro at *p called by "from",
234 * or as a line macro if from == MDOC_MAX.
237 lookup(struct mdoc
*mdoc
, enum mdoct from
, int line
, int ppos
, const char *p
)
241 if (from
== MDOC_MAX
|| mdoc_macros
[from
].flags
& MDOC_PARSED
) {
242 res
= mdoc_hash_find(p
);
243 if (res
!= MDOC_MAX
) {
244 if (mdoc_macros
[res
].flags
& MDOC_CALLABLE
)
246 if (res
!= MDOC_br
&& res
!= MDOC_sp
&& res
!= MDOC_ll
)
247 mandoc_msg(MANDOCERR_MACRO_CALL
,
248 mdoc
->parse
, line
, ppos
, p
);
255 * Rewind up to and including a specific node.
258 rew_last(struct mdoc
*mdoc
, const struct mdoc_node
*to
)
260 struct mdoc_node
*n
, *np
;
263 mdoc
->next
= MDOC_NEXT_SIBLING
;
264 while (mdoc
->last
!= to
) {
265 if ( ! (mdoc
->last
->flags
& MDOC_VALID
))
266 mdoc
->last
->lastline
= to
->lastline
-
267 (mdoc
->flags
& MDOC_NEWLINE
? 1 : 0);
269 * Save the parent here, because we may delete the
270 * mdoc->last node in the post-validation phase and reset
271 * it to mdoc->last->parent, causing a step in the closing
274 np
= mdoc
->last
->parent
;
275 mdoc_valid_post(mdoc
);
279 mdoc
->last
->last
= n
;
281 mdoc_valid_post(mdoc
);
285 * Rewind up to a specific block, including all blocks that broke it.
288 rew_pending(struct mdoc
*mdoc
, const struct mdoc_node
*n
)
293 if (n
->type
!= MDOC_BLOCK
)
296 while ((n
= n
->pending
) != NULL
) {
298 if (n
->type
== MDOC_HEAD
)
299 mdoc_body_alloc(mdoc
, n
->line
, n
->pos
, n
->tok
);
304 * For a block closing macro, return the corresponding opening one.
305 * Otherwise, return the macro itself.
308 rew_alt(enum mdoct tok
)
350 rew_elem(struct mdoc
*mdoc
, enum mdoct tok
)
355 if (MDOC_ELEM
!= n
->type
)
357 assert(MDOC_ELEM
== n
->type
);
358 assert(tok
== n
->tok
);
363 * We are trying to close the block *breaker,
364 * but the child block *broken is still open.
365 * Thus, postpone closing the *breaker
366 * until the rew_pending() call closing *broken.
369 make_pending(struct mdoc
*mdoc
, struct mdoc_node
*breaker
,
370 struct mdoc_node
*broken
, int line
, int ppos
)
374 mandoc_vmsg(MANDOCERR_BLK_NEST
, mdoc
->parse
, line
, ppos
,
375 "%s breaks %s", mdoc_macronames
[breaker
->tok
],
376 mdoc_macronames
[broken
->tok
]);
379 * If the *broken block (Z) is already broken by a block (B)
380 * contained in the breaker (A), make the breaker pending
381 * on that inner breaker (B). Graphically,
383 * breaker=[A! broken=n=[B!->A (old broken=)[Z->B B] A] Z]
385 * In these graphics, "->" indicates the "pending" pointer and
386 * "!" indicates the MDOC_BREAK flag. Each of the cases gets
387 * one additional pointer (B->A) and one additional flag (A!).
390 for (n
= broken
->parent
; ; n
= n
->parent
)
391 if (n
== broken
->pending
)
393 else if (n
== breaker
)
399 * If another, outer breaker (X) is already pending on
400 * the *broken block (B), we must not clobber the link
401 * to the outer breaker, but make it pending on the new,
402 * now inner breaker (A). Graphically,
404 * [X! n=breaker=[A!->X broken=[B(->X)->A X] A] B].
407 if (broken
->pending
!= NULL
) {
411 * If the inner breaker (A) is already broken, too,
412 * it cannot take on the outer breaker (X) but must
413 * hand it on to its own breakers (Y). Graphically,
415 * [X! n=[Y!->X breaker=[A!->Y Y] broken=[B(->X)->A X] A] B]
420 n
->pending
= broken
->pending
;
424 * Now we have reduced the situation to the simplest case:
425 * breaker=[A! broken=[B->A A] B].
428 broken
->pending
= breaker
;
429 breaker
->flags
|= MDOC_BREAK
;
430 if (breaker
->body
!= NULL
)
431 breaker
->body
->flags
|= MDOC_BREAK
;
435 * Allocate a word and check whether it's punctuation or not.
436 * Punctuation consists of those tokens found in mdoc_isdelim().
439 dword(struct mdoc
*mdoc
, int line
, int col
, const char *p
,
440 enum mdelim d
, int may_append
)
447 ! (mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_KEEP
| MDOC_SMOFF
)) &&
448 d
== DELIM_NONE
&& mdoc
->last
->type
== MDOC_TEXT
&&
449 mdoc_isdelim(mdoc
->last
->string
) == DELIM_NONE
) {
450 mdoc_word_append(mdoc
, p
);
454 mdoc_word_alloc(mdoc
, line
, col
, p
);
457 * If the word consists of a bare delimiter,
458 * flag the new node accordingly,
459 * unless doing so was vetoed by the invoking macro.
460 * Always clear the veto, it is only valid for one word.
464 mdoc
->last
->flags
|= MDOC_DELIMO
;
465 else if (d
== DELIM_CLOSE
&&
466 ! (mdoc
->flags
& MDOC_NODELIMC
) &&
467 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
468 mdoc
->last
->flags
|= MDOC_DELIMC
;
469 mdoc
->flags
&= ~MDOC_NODELIMC
;
473 append_delims(struct mdoc
*mdoc
, int line
, int *pos
, char *buf
)
478 if (buf
[*pos
] == '\0')
483 if (mdoc_args(mdoc
, line
, pos
, buf
, MDOC_MAX
, &p
) == ARGS_EOLN
)
485 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 1);
488 * If we encounter end-of-sentence symbols, then trigger
491 * XXX: it's easy to allow this to propagate outward to
492 * the last symbol, such that `. )' will cause the
493 * correct double-spacing. However, (1) groff isn't
494 * smart enough to do this and (2) it would require
495 * knowing which symbols break this behaviour, for
496 * example, `. ;' shouldn't propagate the double-space.
499 if (mandoc_eos(p
, strlen(p
)))
500 mdoc
->last
->flags
|= MDOC_EOS
;
506 * If it is a macro, call it and return 1.
507 * Otherwise, allocate it and return 0.
510 macro_or_word(MACRO_PROT_ARGS
, int parsed
)
519 else if (parsed
&& ! (mdoc
->flags
& MDOC_PHRASELIT
))
520 ntok
= lookup(mdoc
, tok
, line
, ppos
, p
);
522 if (ntok
== MDOC_MAX
) {
523 dword(mdoc
, line
, ppos
, p
, DELIM_MAX
, tok
== MDOC_MAX
||
524 mdoc_macros
[tok
].flags
& MDOC_JOIN
);
527 if (mdoc_macros
[tok
].fp
== in_line_eoln
)
529 mdoc_macro(mdoc
, ntok
, line
, ppos
, pos
, buf
);
531 append_delims(mdoc
, line
, pos
, buf
);
537 * Close out block partial/full explicit.
540 blk_exp_close(MACRO_PROT_ARGS
)
542 struct mdoc_node
*body
; /* Our own body. */
543 struct mdoc_node
*endbody
; /* Our own end marker. */
544 struct mdoc_node
*itblk
; /* An It block starting later. */
545 struct mdoc_node
*later
; /* A sub-block starting later. */
546 struct mdoc_node
*n
; /* Search back to our block. */
548 int j
, lastarg
, maxargs
, nl
;
550 enum mdoct atok
, ntok
;
553 nl
= MDOC_NEWLINE
& mdoc
->flags
;
560 mdoc
->flags
&= ~MDOC_KEEP
;
568 * Search backwards for beginnings of blocks,
569 * both of our own and of pending sub-blocks.
573 body
= endbody
= itblk
= later
= NULL
;
574 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
575 if (n
->flags
& (MDOC_VALID
| MDOC_BREAK
))
578 /* Remember the start of our own body. */
580 if (n
->type
== MDOC_BODY
&& atok
== n
->tok
) {
581 if (n
->end
== ENDBODY_NOT
) {
588 if (n
->type
!= MDOC_BLOCK
|| n
->tok
== MDOC_Nm
)
591 if (n
->tok
== MDOC_It
) {
596 if (atok
== n
->tok
) {
601 * Found the start of our own block.
602 * When there is no pending sub block,
603 * just proceed to closing out.
607 (tok
== MDOC_El
&& itblk
== NULL
))
611 * When there is a pending sub block, postpone
612 * closing out the current block until the
613 * rew_pending() closing out the sub-block.
616 make_pending(mdoc
, n
, later
, line
, ppos
);
618 itblk
->flags
|= MDOC_BREAK
;
621 * Mark the place where the formatting - but not
622 * the scope - of the current block ends.
625 endbody
= mdoc_endbody_alloc(mdoc
, line
, ppos
,
626 atok
, body
, ENDBODY_SPACE
);
629 * If a block closing macro taking arguments
630 * breaks another block, put the arguments
631 * into the end marker.
635 mdoc
->next
= MDOC_NEXT_CHILD
;
640 * When finding an open sub block, remember the last
641 * open explicit block, or, in case there are only
642 * implicit ones, the first open implicit block.
646 ! (mdoc_macros
[later
->tok
].flags
& MDOC_EXPLICIT
))
651 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, mdoc
->parse
,
652 line
, ppos
, mdoc_macronames
[tok
]);
653 if (maxargs
&& endbody
== NULL
) {
655 * Stray .Ec without previous .Eo:
656 * Break the output line, keep the arguments.
658 mdoc_elem_alloc(mdoc
, line
, ppos
, MDOC_br
, NULL
);
659 rew_elem(mdoc
, MDOC_br
);
661 } else if (endbody
== NULL
) {
662 rew_last(mdoc
, body
);
664 mdoc_tail_alloc(mdoc
, line
, ppos
, atok
);
667 if ( ! (mdoc_macros
[tok
].flags
& MDOC_PARSED
)) {
668 if (buf
[*pos
] != '\0')
669 mandoc_vmsg(MANDOCERR_ARG_SKIP
,
670 mdoc
->parse
, line
, ppos
,
671 "%s %s", mdoc_macronames
[tok
],
673 if (endbody
== NULL
&& n
!= NULL
)
674 rew_pending(mdoc
, n
);
683 if (j
== maxargs
&& n
!= NULL
) {
684 rew_pending(mdoc
, n
);
688 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
689 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
692 ntok
= ac
== ARGS_QWORD
? MDOC_MAX
:
693 lookup(mdoc
, tok
, line
, lastarg
, p
);
695 if (ntok
== MDOC_MAX
) {
696 dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
,
697 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
702 rew_pending(mdoc
, n
);
705 mdoc
->flags
&= ~MDOC_NEWLINE
;
706 mdoc_macro(mdoc
, ntok
, line
, lastarg
, pos
, buf
);
711 rew_pending(mdoc
, n
);
713 append_delims(mdoc
, line
, pos
, buf
);
717 in_line(MACRO_PROT_ARGS
)
719 int la
, scope
, cnt
, firstarg
, mayopen
, nc
, nl
;
723 struct mdoc_arg
*arg
;
726 nl
= MDOC_NEWLINE
& mdoc
->flags
;
729 * Whether we allow ignored elements (those without content,
730 * usually because of reserved words) to squeak by.
752 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
757 for (cnt
= scope
= 0;; ) {
759 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
762 * At the end of a macro line,
763 * opening delimiters do not suppress spacing.
766 if (ac
== ARGS_EOLN
) {
768 mdoc
->last
->flags
&= ~MDOC_DELIMO
;
773 * The rest of the macro line is only punctuation,
774 * to be handled by append_delims().
775 * If there were no other arguments,
776 * do not allow the first one to suppress spacing,
777 * even if it turns out to be a closing one.
780 if (ac
== ARGS_PUNCT
) {
781 if (cnt
== 0 && nc
== 0)
782 mdoc
->flags
|= MDOC_NODELIMC
;
786 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Fn
&& !cnt
)) ?
787 MDOC_MAX
: lookup(mdoc
, tok
, line
, la
, p
);
790 * In this case, we've located a submacro and must
791 * execute it. Close out scope, if open. If no
792 * elements have been generated, either create one (nc)
793 * or raise a warning.
796 if (ntok
!= MDOC_MAX
) {
800 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
801 rew_last(mdoc
, mdoc
->last
);
802 } else if ( ! nc
&& ! cnt
) {
804 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
805 mdoc
->parse
, line
, ppos
,
806 mdoc_macronames
[tok
]);
808 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
810 append_delims(mdoc
, line
, pos
, buf
);
815 * Non-quote-enclosed punctuation. Set up our scope, if
816 * a word; rewind the scope, if a delimiter; then append
820 d
= ac
== ARGS_QWORD
? DELIM_NONE
: mdoc_isdelim(p
);
822 if (DELIM_NONE
!= d
) {
824 * If we encounter closing punctuation, no word
825 * has been emitted, no scope is open, and we're
826 * allowed to have an empty element, then start
829 if ((d
== DELIM_CLOSE
||
830 (d
== DELIM_MIDDLE
&& tok
== MDOC_Fl
)) &&
831 !cnt
&& !scope
&& nc
&& mayopen
) {
832 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
839 * Close out our scope, if one is open, before
847 } else if (mayopen
&& !scope
) {
848 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
853 dword(mdoc
, line
, la
, p
, d
,
854 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
857 * If the first argument is a closing delimiter,
858 * do not suppress spacing before it.
861 if (firstarg
&& d
== DELIM_CLOSE
&& !nc
)
862 mdoc
->last
->flags
&= ~MDOC_DELIMC
;
866 * `Fl' macros have their scope re-opened with each new
867 * word so that the `-' can be added to each one without
868 * having to parse out spaces.
870 if (scope
&& tok
== MDOC_Fl
) {
880 * If no elements have been collected and we're allowed to have
881 * empties (nc), open a scope and close it out. Otherwise,
887 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
888 rew_last(mdoc
, mdoc
->last
);
891 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
892 line
, ppos
, mdoc_macronames
[tok
]);
896 append_delims(mdoc
, line
, pos
, buf
);
900 blk_full(MACRO_PROT_ARGS
)
903 struct mdoc_arg
*arg
;
904 struct mdoc_node
*blk
; /* Our own or a broken block. */
905 struct mdoc_node
*head
; /* Our own head. */
906 struct mdoc_node
*body
; /* Our own body. */
908 enum margserr ac
, lac
;
911 nl
= MDOC_NEWLINE
& mdoc
->flags
;
913 if ( ! (mdoc_macros
[tok
].flags
& MDOC_EXPLICIT
)) {
915 /* Here, tok is one of Sh Ss Nm Nd It. */
918 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
919 if (n
->flags
& (MDOC_VALID
| MDOC_BREAK
) ||
920 n
->type
!= MDOC_BLOCK
)
922 if (tok
== MDOC_It
&& n
->tok
== MDOC_Bl
) {
924 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
925 mdoc
->parse
, line
, ppos
,
927 mdoc_macronames
[blk
->tok
]);
928 rew_pending(mdoc
, blk
);
933 if (mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
938 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
939 mdoc
->parse
, line
, ppos
,
941 mdoc_macronames
[tok
],
942 mdoc_macronames
[n
->tok
]);
943 rew_pending(mdoc
, n
);
946 /* Delay in case it's astray. */
955 /* Here, n is one of Sh Ss Nm Nd It. */
957 if (tok
!= MDOC_Sh
&& (n
->tok
== MDOC_Sh
||
958 (tok
!= MDOC_Ss
&& (n
->tok
== MDOC_Ss
||
959 (tok
!= MDOC_It
&& n
->tok
== MDOC_It
)))))
962 /* Item breaking an explicit block. */
965 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
966 mdoc
->parse
, line
, ppos
,
968 mdoc_macronames
[blk
->tok
]);
969 rew_pending(mdoc
, blk
);
973 /* Close out prior implicit scopes. */
978 /* Skip items outside lists. */
980 if (tok
== MDOC_It
&& (n
== NULL
|| n
->tok
!= MDOC_Bl
)) {
981 mandoc_vmsg(MANDOCERR_IT_STRAY
, mdoc
->parse
,
982 line
, ppos
, "It %s", buf
+ *pos
);
983 mdoc_elem_alloc(mdoc
, line
, ppos
, MDOC_br
, NULL
);
984 rew_elem(mdoc
, MDOC_br
);
990 * This routine accommodates implicitly- and explicitly-scoped
991 * macro openings. Implicit ones first close out prior scope
992 * (seen above). Delay opening the head until necessary to
993 * allow leading punctuation to print. Special consideration
994 * for `It -column', which has phrase-part syntax instead of
995 * regular child nodes.
998 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
999 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
);
1003 * Exception: Heads of `It' macros in `-diag' lists are not
1004 * parsed, even though `It' macros in general are parsed.
1007 parsed
= tok
!= MDOC_It
||
1008 mdoc
->last
->parent
->tok
!= MDOC_Bl
||
1009 mdoc
->last
->parent
->norm
->Bl
.type
!= LIST_diag
;
1012 * The `Nd' macro has all arguments in its body: it's a hybrid
1013 * of block partial-explicit and full-implicit. Stupid.
1016 if (tok
== MDOC_Nd
) {
1017 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1018 rew_last(mdoc
, head
);
1019 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1023 mdoc
->flags
|= MDOC_KEEP
;
1029 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1030 if (ac
== ARGS_EOLN
) {
1031 if (lac
!= ARGS_PPHRASE
&& lac
!= ARGS_PHRASE
)
1034 * This is necessary: if the last token on a
1035 * line is a `Ta' or tab, then we'll get
1036 * ARGS_EOLN, so we must be smart enough to
1037 * reopen our scope if the last parse was a
1038 * phrase or partial phrase.
1041 rew_last(mdoc
, body
);
1042 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1045 if (tok
== MDOC_Rs
) {
1046 mandoc_vmsg(MANDOCERR_ARG_SKIP
, mdoc
->parse
,
1047 line
, la
, "Rs %s", buf
+ la
);
1050 if (ac
== ARGS_PUNCT
)
1054 * Emit leading punctuation (i.e., punctuation before
1055 * the MDOC_HEAD) for non-phrase types.
1060 ac
!= ARGS_PHRASE
&&
1061 ac
!= ARGS_PPHRASE
&&
1063 mdoc_isdelim(p
) == DELIM_OPEN
) {
1064 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1068 /* Open a head if one hasn't been opened. */
1071 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1073 if (ac
== ARGS_PHRASE
||
1075 ac
== ARGS_PPHRASE
) {
1078 * If we haven't opened a body yet, rewind the
1079 * head; if we have, rewind that instead.
1082 rew_last(mdoc
, body
== NULL
? head
: body
);
1083 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1086 * Process phrases: set whether we're in a
1087 * partial-phrase (this effects line handling)
1088 * then call down into the phrase parser.
1091 if (ac
== ARGS_PPHRASE
)
1092 mdoc
->flags
|= MDOC_PPHRASE
;
1093 if (ac
== ARGS_PEND
&& lac
== ARGS_PPHRASE
)
1094 mdoc
->flags
|= MDOC_PPHRASE
;
1095 parse_rest(mdoc
, MDOC_MAX
, line
, &la
, buf
);
1096 mdoc
->flags
&= ~MDOC_PPHRASE
;
1100 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, parsed
))
1104 if (blk
->flags
& MDOC_VALID
)
1107 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1108 if (nl
&& tok
!= MDOC_Rs
)
1109 append_delims(mdoc
, line
, pos
, buf
);
1114 * If there is an open (i.e., unvalidated) sub-block requiring
1115 * explicit close-out, postpone switching the current block from
1116 * head to body until the rew_pending() call closing out that
1119 for (n
= mdoc
->last
; n
&& n
!= head
; n
= n
->parent
) {
1120 if (n
->type
== MDOC_BLOCK
&&
1121 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
&&
1122 ! (n
->flags
& MDOC_VALID
)) {
1128 /* Close out scopes to remain in a consistent state. */
1130 rew_last(mdoc
, head
);
1131 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1133 if (mdoc
->flags
& MDOC_FREECOL
) {
1134 rew_last(mdoc
, body
);
1135 rew_last(mdoc
, blk
);
1136 mdoc
->flags
&= ~MDOC_FREECOL
;
1141 blk_part_imp(MACRO_PROT_ARGS
)
1146 struct mdoc_node
*blk
; /* saved block context */
1147 struct mdoc_node
*body
; /* saved body context */
1148 struct mdoc_node
*n
;
1150 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1153 * A macro that spans to the end of the line. This is generally
1154 * (but not necessarily) called as the first macro. The block
1155 * has a head as the immediate child, which is always empty,
1156 * followed by zero or more opening punctuation nodes, then the
1157 * body (which may be empty, depending on the macro), then zero
1158 * or more closing punctuation nodes.
1161 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1162 rew_last(mdoc
, mdoc_head_alloc(mdoc
, line
, ppos
, tok
));
1165 * Open the body scope "on-demand", that is, after we've
1166 * processed all our the leading delimiters (open parenthesis,
1170 for (body
= NULL
; ; ) {
1172 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1173 if (ac
== ARGS_EOLN
|| ac
== ARGS_PUNCT
)
1176 if (body
== NULL
&& ac
!= ARGS_QWORD
&&
1177 mdoc_isdelim(p
) == DELIM_OPEN
) {
1178 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1183 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1185 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1189 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1192 * If there is an open sub-block requiring explicit close-out,
1193 * postpone closing out the current block until the
1194 * rew_pending() call closing out the sub-block.
1197 for (n
= mdoc
->last
; n
&& n
!= body
&& n
!= blk
->parent
;
1199 if (n
->type
== MDOC_BLOCK
&&
1200 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
&&
1201 ! (n
->flags
& MDOC_VALID
)) {
1202 make_pending(mdoc
, blk
, n
, line
, ppos
);
1203 mdoc_endbody_alloc(mdoc
, line
, ppos
,
1204 tok
, body
, ENDBODY_NOSPACE
);
1209 rew_last(mdoc
, body
);
1211 append_delims(mdoc
, line
, pos
, buf
);
1212 rew_pending(mdoc
, blk
);
1214 /* Move trailing .Ns out of scope. */
1216 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1218 if (n
&& n
->tok
== MDOC_Ns
)
1219 mdoc_node_relink(mdoc
, n
);
1223 blk_part_exp(MACRO_PROT_ARGS
)
1227 struct mdoc_node
*head
; /* keep track of head */
1230 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1233 * The opening of an explicit macro having zero or more leading
1234 * punctuation nodes; a head with optional single element (the
1235 * case of `Eo'); and a body that may be empty.
1238 mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1242 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1243 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
1246 /* Flush out leading punctuation. */
1248 if (head
== NULL
&& ac
!= ARGS_QWORD
&&
1249 mdoc_isdelim(p
) == DELIM_OPEN
) {
1250 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1255 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1256 if (tok
== MDOC_Eo
) /* Not parsed. */
1257 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 0);
1258 rew_last(mdoc
, head
);
1259 mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1264 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1268 /* Clean-up to leave in a consistent state. */
1271 rew_last(mdoc
, mdoc_head_alloc(mdoc
, line
, ppos
, tok
));
1272 mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1275 append_delims(mdoc
, line
, pos
, buf
);
1279 in_line_argn(MACRO_PROT_ARGS
)
1281 int la
, flushed
, j
, maxargs
, nl
;
1283 struct mdoc_arg
*arg
;
1287 nl
= mdoc
->flags
& MDOC_NEWLINE
;
1290 * A line macro that has a fixed number of arguments (maxargs).
1291 * Only open the scope once the first non-leading-punctuation is
1292 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1293 * keep it open until the maximum number of arguments are
1317 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1323 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1324 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
) {
1325 if (j
< 2 && tok
== MDOC_Pf
)
1326 mandoc_vmsg(MANDOCERR_PF_SKIP
,
1327 mdoc
->parse
, line
, ppos
, "Pf %s",
1328 p
== NULL
? "at eol" : p
);
1332 if ( ! (mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
) &&
1333 ac
!= ARGS_QWORD
&& j
== 0 &&
1334 mdoc_isdelim(p
) == DELIM_OPEN
) {
1335 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1338 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1340 if (j
== maxargs
&& ! flushed
) {
1341 rew_elem(mdoc
, tok
);
1345 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Pf
&& j
== 0)) ?
1346 MDOC_MAX
: lookup(mdoc
, tok
, line
, la
, p
);
1348 if (ntok
!= MDOC_MAX
) {
1350 rew_elem(mdoc
, tok
);
1352 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
1357 if ( ! (mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
) &&
1358 ac
!= ARGS_QWORD
&& ! flushed
&&
1359 mdoc_isdelim(p
) != DELIM_NONE
) {
1360 rew_elem(mdoc
, tok
);
1364 dword(mdoc
, line
, la
, p
, DELIM_MAX
,
1365 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
1370 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1371 if (ac
== ARGS_PUNCT
&& tok
== MDOC_Pf
)
1372 append_delims(mdoc
, line
, pos
, buf
);
1375 rew_elem(mdoc
, tok
);
1377 append_delims(mdoc
, line
, pos
, buf
);
1381 in_line_eoln(MACRO_PROT_ARGS
)
1383 struct mdoc_node
*n
;
1384 struct mdoc_arg
*arg
;
1386 if ((tok
== MDOC_Pp
|| tok
== MDOC_Lp
) &&
1387 ! (mdoc
->flags
& MDOC_SYNOPSIS
)) {
1389 if (mdoc
->next
== MDOC_NEXT_SIBLING
)
1391 if (n
->tok
== MDOC_Nm
)
1392 rew_last(mdoc
, mdoc
->last
->parent
);
1395 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1396 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1397 if (parse_rest(mdoc
, tok
, line
, pos
, buf
))
1399 rew_elem(mdoc
, tok
);
1403 * The simplest argument parser available: Parse the remaining
1404 * words until the end of the phrase or line and return 0
1405 * or until the next macro, call that macro, and return 1.
1408 parse_rest(struct mdoc
*mdoc
, enum mdoct tok
, int line
, int *pos
, char *buf
)
1414 if (mdoc_args(mdoc
, line
, pos
, buf
, tok
, NULL
) == ARGS_EOLN
)
1416 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1422 ctx_synopsis(MACRO_PROT_ARGS
)
1425 if (~mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_NEWLINE
))
1426 in_line(mdoc
, tok
, line
, ppos
, pos
, buf
);
1427 else if (tok
== MDOC_Nm
)
1428 blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
);
1430 assert(tok
== MDOC_Vt
);
1431 blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
);
1436 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1437 * They're unusual because they're basically free-form text until a
1438 * macro is encountered.
1441 phrase_ta(MACRO_PROT_ARGS
)
1443 struct mdoc_node
*body
, *n
;
1445 /* Make sure we are in a column list or ignore this macro. */
1448 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
1449 if (n
->flags
& (MDOC_VALID
| MDOC_BREAK
))
1451 if (n
->tok
== MDOC_It
&& n
->type
== MDOC_BODY
)
1453 if (n
->tok
== MDOC_Bl
)
1457 if (n
== NULL
|| n
->norm
->Bl
.type
!= LIST_column
) {
1458 mandoc_msg(MANDOCERR_TA_STRAY
, mdoc
->parse
,
1463 /* Advance to the next column. */
1465 rew_last(mdoc
, body
);
1466 mdoc_body_alloc(mdoc
, line
, ppos
, MDOC_It
);
1467 parse_rest(mdoc
, MDOC_MAX
, line
, pos
, buf
);