]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.184 2015/04/02 21:36:50 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 AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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"
35 static void blk_full(MACRO_PROT_ARGS
);
36 static void blk_exp_close(MACRO_PROT_ARGS
);
37 static void blk_part_exp(MACRO_PROT_ARGS
);
38 static void blk_part_imp(MACRO_PROT_ARGS
);
39 static void ctx_synopsis(MACRO_PROT_ARGS
);
40 static void in_line_eoln(MACRO_PROT_ARGS
);
41 static void in_line_argn(MACRO_PROT_ARGS
);
42 static void in_line(MACRO_PROT_ARGS
);
43 static void phrase_ta(MACRO_PROT_ARGS
);
45 static void dword(struct mdoc
*, int, int, const char *,
47 static void append_delims(struct mdoc
*, int, int *, char *);
48 static enum mdoct
lookup(struct mdoc
*, enum mdoct
,
49 int, int, const char *);
50 static int macro_or_word(MACRO_PROT_ARGS
, int);
51 static int parse_rest(struct mdoc
*, enum mdoct
,
53 static enum mdoct
rew_alt(enum mdoct
);
54 static void rew_elem(struct mdoc
*, enum mdoct
);
55 static void rew_last(struct mdoc
*, const struct mdoc_node
*);
56 static void rew_pending(struct mdoc
*, const struct mdoc_node
*);
58 const struct mdoc_macro __mdoc_macros
[MDOC_MAX
] = {
59 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ap */
60 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
61 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
62 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
63 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Sh */
64 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* Ss */
65 { in_line_eoln
, 0 }, /* Pp */
66 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* D1 */
67 { blk_part_imp
, MDOC_PARSED
| MDOC_JOIN
}, /* Dl */
68 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
69 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ed */
70 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
71 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* El */
72 { blk_full
, MDOC_PARSED
| MDOC_JOIN
}, /* It */
73 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
74 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* An */
75 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
76 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Cd */
77 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
78 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
79 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
80 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
81 { in_line_eoln
, 0 }, /* Ex */
82 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
83 { in_line_eoln
, 0 }, /* Fd */
84 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
85 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ic */
88 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
89 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Li */
90 { blk_full
, MDOC_JOIN
}, /* Nd */
91 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
92 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
93 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ot */
94 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
95 { in_line_eoln
, 0 }, /* Rv */
96 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
97 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
98 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
99 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
100 { in_line_eoln
, MDOC_JOIN
}, /* %A */
101 { in_line_eoln
, MDOC_JOIN
}, /* %B */
102 { in_line_eoln
, MDOC_JOIN
}, /* %D */
103 { in_line_eoln
, MDOC_JOIN
}, /* %I */
104 { in_line_eoln
, MDOC_JOIN
}, /* %J */
105 { in_line_eoln
, 0 }, /* %N */
106 { in_line_eoln
, MDOC_JOIN
}, /* %O */
107 { in_line_eoln
, 0 }, /* %P */
108 { in_line_eoln
, MDOC_JOIN
}, /* %R */
109 { in_line_eoln
, MDOC_JOIN
}, /* %T */
110 { in_line_eoln
, 0 }, /* %V */
111 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
112 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ac */
113 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
114 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ao */
115 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Aq */
116 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
117 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
118 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bc */
119 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
120 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
121 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bo */
122 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Bq */
123 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
124 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
125 { in_line_eoln
, 0 }, /* Db */
126 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
127 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Dc */
128 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
129 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Do */
130 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Dq */
131 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ec */
132 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ef */
133 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Em */
134 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
135 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
136 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
137 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* No */
138 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
|
139 MDOC_IGNDELIM
| MDOC_JOIN
}, /* Ns */
140 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
141 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
142 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
143 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Pc */
144 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
145 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
146 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Po */
147 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Pq */
148 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
149 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qc */
150 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ql */
151 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
152 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Qo */
153 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Qq */
154 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Re */
155 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
156 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
157 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Sc */
158 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
159 MDOC_EXPLICIT
| MDOC_JOIN
}, /* So */
160 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sq */
161 { in_line_argn
, 0 }, /* Sm */
162 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sx */
163 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Sy */
164 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
165 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ux */
166 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
167 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
168 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
169 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
170 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Fc */
171 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
172 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oo */
173 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
174 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Oc */
175 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
176 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_JOIN
}, /* Ek */
177 { in_line_eoln
, 0 }, /* Bt */
178 { in_line_eoln
, 0 }, /* Hf */
179 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fr */
180 { in_line_eoln
, 0 }, /* Ud */
181 { in_line
, 0 }, /* Lb */
182 { in_line_eoln
, 0 }, /* Lp */
183 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
184 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
185 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Brq */
186 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
|
187 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Bro */
188 { blk_exp_close
, MDOC_CALLABLE
| MDOC_PARSED
|
189 MDOC_EXPLICIT
| MDOC_JOIN
}, /* Brc */
190 { in_line_eoln
, MDOC_JOIN
}, /* %C */
191 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Es */
192 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* En */
193 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
194 { in_line_eoln
, MDOC_JOIN
}, /* %Q */
195 { in_line_eoln
, 0 }, /* br */
196 { in_line_eoln
, 0 }, /* sp */
197 { in_line_eoln
, 0 }, /* %U */
198 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_JOIN
}, /* Ta */
199 { in_line_eoln
, MDOC_PROLOGUE
}, /* ll */
202 const struct mdoc_macro
* const mdoc_macros
= __mdoc_macros
;
206 * This is called at the end of parsing. It must traverse up the tree,
207 * closing out open [implicit] scopes. Obviously, open explicit scopes
211 mdoc_macroend(struct mdoc
*mdoc
)
215 /* Scan for open explicit scopes. */
217 n
= mdoc
->last
->flags
& MDOC_VALID
?
218 mdoc
->last
->parent
: mdoc
->last
;
220 for ( ; n
; n
= n
->parent
)
221 if (n
->type
== ROFFT_BLOCK
&&
222 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
)
223 mandoc_msg(MANDOCERR_BLK_NOEND
, mdoc
->parse
,
224 n
->line
, n
->pos
, mdoc_macronames
[n
->tok
]);
226 /* Rewind to the first. */
228 rew_last(mdoc
, mdoc
->first
);
232 * Look up the macro at *p called by "from",
233 * or as a line macro if from == MDOC_MAX.
236 lookup(struct mdoc
*mdoc
, enum mdoct from
, int line
, int ppos
, const char *p
)
240 if (from
== MDOC_MAX
|| mdoc_macros
[from
].flags
& MDOC_PARSED
) {
241 res
= mdoc_hash_find(p
);
242 if (res
!= MDOC_MAX
) {
243 if (mdoc_macros
[res
].flags
& MDOC_CALLABLE
)
245 if (res
!= MDOC_br
&& res
!= MDOC_sp
&& res
!= MDOC_ll
)
246 mandoc_msg(MANDOCERR_MACRO_CALL
,
247 mdoc
->parse
, line
, ppos
, p
);
254 * Rewind up to and including a specific node.
257 rew_last(struct mdoc
*mdoc
, const struct mdoc_node
*to
)
259 struct mdoc_node
*n
, *np
;
262 mdoc
->next
= MDOC_NEXT_SIBLING
;
263 while (mdoc
->last
!= to
) {
265 * Save the parent here, because we may delete the
266 * mdoc->last node in the post-validation phase and reset
267 * it to mdoc->last->parent, causing a step in the closing
270 np
= mdoc
->last
->parent
;
271 mdoc_valid_post(mdoc
);
275 mdoc
->last
->last
= n
;
277 mdoc_valid_post(mdoc
);
281 * Rewind up to a specific block, including all blocks that broke it.
284 rew_pending(struct mdoc
*mdoc
, const struct mdoc_node
*n
)
292 mdoc_body_alloc(mdoc
, n
->line
, n
->pos
, n
->tok
);
300 if ( ! (n
->flags
& MDOC_BROKEN
))
304 if ((n
= n
->parent
) == NULL
)
307 if (n
->type
== ROFFT_BLOCK
||
308 n
->type
== ROFFT_HEAD
) {
309 if (n
->flags
& MDOC_ENDED
)
319 * For a block closing macro, return the corresponding opening one.
320 * Otherwise, return the macro itself.
323 rew_alt(enum mdoct tok
)
365 rew_elem(struct mdoc
*mdoc
, enum mdoct tok
)
370 if (n
->type
!= ROFFT_ELEM
)
372 assert(n
->type
== ROFFT_ELEM
);
373 assert(tok
== n
->tok
);
378 * Allocate a word and check whether it's punctuation or not.
379 * Punctuation consists of those tokens found in mdoc_isdelim().
382 dword(struct mdoc
*mdoc
, int line
, int col
, const char *p
,
383 enum mdelim d
, int may_append
)
390 ! (mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_KEEP
| MDOC_SMOFF
)) &&
391 d
== DELIM_NONE
&& mdoc
->last
->type
== ROFFT_TEXT
&&
392 mdoc_isdelim(mdoc
->last
->string
) == DELIM_NONE
) {
393 mdoc_word_append(mdoc
, p
);
397 mdoc_word_alloc(mdoc
, line
, col
, p
);
400 * If the word consists of a bare delimiter,
401 * flag the new node accordingly,
402 * unless doing so was vetoed by the invoking macro.
403 * Always clear the veto, it is only valid for one word.
407 mdoc
->last
->flags
|= MDOC_DELIMO
;
408 else if (d
== DELIM_CLOSE
&&
409 ! (mdoc
->flags
& MDOC_NODELIMC
) &&
410 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
411 mdoc
->last
->flags
|= MDOC_DELIMC
;
412 mdoc
->flags
&= ~MDOC_NODELIMC
;
416 append_delims(struct mdoc
*mdoc
, int line
, int *pos
, char *buf
)
421 if (buf
[*pos
] == '\0')
426 if (mdoc_args(mdoc
, line
, pos
, buf
, MDOC_MAX
, &p
) == ARGS_EOLN
)
428 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 1);
431 * If we encounter end-of-sentence symbols, then trigger
434 * XXX: it's easy to allow this to propagate outward to
435 * the last symbol, such that `. )' will cause the
436 * correct double-spacing. However, (1) groff isn't
437 * smart enough to do this and (2) it would require
438 * knowing which symbols break this behaviour, for
439 * example, `. ;' shouldn't propagate the double-space.
442 if (mandoc_eos(p
, strlen(p
)))
443 mdoc
->last
->flags
|= MDOC_EOS
;
449 * If it is a macro, call it and return 1.
450 * Otherwise, allocate it and return 0.
453 macro_or_word(MACRO_PROT_ARGS
, int parsed
)
462 else if (parsed
&& ! (mdoc
->flags
& MDOC_PHRASELIT
))
463 ntok
= lookup(mdoc
, tok
, line
, ppos
, p
);
465 if (ntok
== MDOC_MAX
) {
466 dword(mdoc
, line
, ppos
, p
, DELIM_MAX
, tok
== MDOC_MAX
||
467 mdoc_macros
[tok
].flags
& MDOC_JOIN
);
470 if (mdoc_macros
[tok
].fp
== in_line_eoln
)
472 mdoc_macro(mdoc
, ntok
, line
, ppos
, pos
, buf
);
474 append_delims(mdoc
, line
, pos
, buf
);
480 * Close out block partial/full explicit.
483 blk_exp_close(MACRO_PROT_ARGS
)
485 struct mdoc_node
*body
; /* Our own body. */
486 struct mdoc_node
*endbody
; /* Our own end marker. */
487 struct mdoc_node
*itblk
; /* An It block starting later. */
488 struct mdoc_node
*later
; /* A sub-block starting later. */
489 struct mdoc_node
*n
; /* Search back to our block. */
491 int j
, lastarg
, maxargs
, nl
;
493 enum mdoct atok
, ntok
;
496 nl
= MDOC_NEWLINE
& mdoc
->flags
;
503 mdoc
->flags
&= ~MDOC_KEEP
;
511 * Search backwards for beginnings of blocks,
512 * both of our own and of pending sub-blocks.
516 body
= endbody
= itblk
= later
= NULL
;
517 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
518 if (n
->flags
& MDOC_ENDED
) {
519 if ( ! (n
->flags
& MDOC_VALID
))
520 n
->flags
|= MDOC_BROKEN
;
524 /* Remember the start of our own body. */
526 if (n
->type
== ROFFT_BODY
&& atok
== n
->tok
) {
527 if (n
->end
== ENDBODY_NOT
)
532 if (n
->type
!= ROFFT_BLOCK
|| n
->tok
== MDOC_Nm
)
535 if (n
->tok
== MDOC_It
) {
540 if (atok
== n
->tok
) {
544 * Found the start of our own block.
545 * When there is no pending sub block,
546 * just proceed to closing out.
550 (tok
== MDOC_El
&& itblk
== NULL
))
554 * When there is a pending sub block, postpone
555 * closing out the current block until the
556 * rew_pending() closing out the sub-block.
557 * Mark the place where the formatting - but not
558 * the scope - of the current block ends.
561 mandoc_vmsg(MANDOCERR_BLK_NEST
, mdoc
->parse
,
562 line
, ppos
, "%s breaks %s",
563 mdoc_macronames
[atok
],
564 mdoc_macronames
[later
->tok
]);
566 endbody
= mdoc_endbody_alloc(mdoc
, line
, ppos
,
567 atok
, body
, ENDBODY_SPACE
);
570 itblk
->flags
|= MDOC_ENDED
| MDOC_BROKEN
;
573 * If a block closing macro taking arguments
574 * breaks another block, put the arguments
575 * into the end marker.
579 mdoc
->next
= MDOC_NEXT_CHILD
;
583 /* Explicit blocks close out description lines. */
585 if (n
->tok
== MDOC_Nd
) {
590 /* Breaking an open sub block. */
592 n
->flags
|= MDOC_BROKEN
;
598 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, mdoc
->parse
,
599 line
, ppos
, mdoc_macronames
[tok
]);
600 if (maxargs
&& endbody
== NULL
) {
602 * Stray .Ec without previous .Eo:
603 * Break the output line, keep the arguments.
605 mdoc_elem_alloc(mdoc
, line
, ppos
, MDOC_br
, NULL
);
606 rew_elem(mdoc
, MDOC_br
);
608 } else if (endbody
== NULL
) {
609 rew_last(mdoc
, body
);
611 mdoc_tail_alloc(mdoc
, line
, ppos
, atok
);
614 if ( ! (mdoc_macros
[tok
].flags
& MDOC_PARSED
)) {
615 if (buf
[*pos
] != '\0')
616 mandoc_vmsg(MANDOCERR_ARG_SKIP
,
617 mdoc
->parse
, line
, ppos
,
618 "%s %s", mdoc_macronames
[tok
],
620 if (endbody
== NULL
&& n
!= NULL
)
621 rew_pending(mdoc
, n
);
630 if (j
== maxargs
&& n
!= NULL
) {
631 rew_pending(mdoc
, n
);
635 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
636 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
639 ntok
= ac
== ARGS_QWORD
? MDOC_MAX
:
640 lookup(mdoc
, tok
, line
, lastarg
, p
);
642 if (ntok
== MDOC_MAX
) {
643 dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
,
644 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
649 rew_pending(mdoc
, n
);
652 mdoc
->flags
&= ~MDOC_NEWLINE
;
653 mdoc_macro(mdoc
, ntok
, line
, lastarg
, pos
, buf
);
658 rew_pending(mdoc
, n
);
660 append_delims(mdoc
, line
, pos
, buf
);
664 in_line(MACRO_PROT_ARGS
)
666 int la
, scope
, cnt
, firstarg
, mayopen
, nc
, nl
;
670 struct mdoc_arg
*arg
;
673 nl
= MDOC_NEWLINE
& mdoc
->flags
;
676 * Whether we allow ignored elements (those without content,
677 * usually because of reserved words) to squeak by.
699 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
704 for (cnt
= scope
= 0;; ) {
706 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
709 * At the end of a macro line,
710 * opening delimiters do not suppress spacing.
713 if (ac
== ARGS_EOLN
) {
715 mdoc
->last
->flags
&= ~MDOC_DELIMO
;
720 * The rest of the macro line is only punctuation,
721 * to be handled by append_delims().
722 * If there were no other arguments,
723 * do not allow the first one to suppress spacing,
724 * even if it turns out to be a closing one.
727 if (ac
== ARGS_PUNCT
) {
728 if (cnt
== 0 && (nc
== 0 || tok
== MDOC_An
))
729 mdoc
->flags
|= MDOC_NODELIMC
;
733 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Fn
&& !cnt
)) ?
734 MDOC_MAX
: lookup(mdoc
, tok
, line
, la
, p
);
737 * In this case, we've located a submacro and must
738 * execute it. Close out scope, if open. If no
739 * elements have been generated, either create one (nc)
740 * or raise a warning.
743 if (ntok
!= MDOC_MAX
) {
747 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
748 rew_last(mdoc
, mdoc
->last
);
749 } else if ( ! nc
&& ! cnt
) {
751 mandoc_msg(MANDOCERR_MACRO_EMPTY
,
752 mdoc
->parse
, line
, ppos
,
753 mdoc_macronames
[tok
]);
755 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
757 append_delims(mdoc
, line
, pos
, buf
);
762 * Non-quote-enclosed punctuation. Set up our scope, if
763 * a word; rewind the scope, if a delimiter; then append
767 d
= ac
== ARGS_QWORD
? DELIM_NONE
: mdoc_isdelim(p
);
769 if (DELIM_NONE
!= d
) {
771 * If we encounter closing punctuation, no word
772 * has been emitted, no scope is open, and we're
773 * allowed to have an empty element, then start
776 if ((d
== DELIM_CLOSE
||
777 (d
== DELIM_MIDDLE
&& tok
== MDOC_Fl
)) &&
778 !cnt
&& !scope
&& nc
&& mayopen
) {
779 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
786 * Close out our scope, if one is open, before
794 } else if (mayopen
&& !scope
) {
795 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
800 dword(mdoc
, line
, la
, p
, d
,
801 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
804 * If the first argument is a closing delimiter,
805 * do not suppress spacing before it.
808 if (firstarg
&& d
== DELIM_CLOSE
&& !nc
)
809 mdoc
->last
->flags
&= ~MDOC_DELIMC
;
813 * `Fl' macros have their scope re-opened with each new
814 * word so that the `-' can be added to each one without
815 * having to parse out spaces.
817 if (scope
&& tok
== MDOC_Fl
) {
827 * If no elements have been collected and we're allowed to have
828 * empties (nc), open a scope and close it out. Otherwise,
834 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
835 rew_last(mdoc
, mdoc
->last
);
838 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
839 line
, ppos
, mdoc_macronames
[tok
]);
843 append_delims(mdoc
, line
, pos
, buf
);
847 blk_full(MACRO_PROT_ARGS
)
850 struct mdoc_arg
*arg
;
851 struct mdoc_node
*blk
; /* Our own or a broken block. */
852 struct mdoc_node
*head
; /* Our own head. */
853 struct mdoc_node
*body
; /* Our own body. */
855 enum margserr ac
, lac
;
858 nl
= MDOC_NEWLINE
& mdoc
->flags
;
860 if (buf
[*pos
] == '\0' && (tok
== MDOC_Sh
|| tok
== MDOC_Ss
)) {
861 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
862 line
, ppos
, mdoc_macronames
[tok
]);
866 if ( ! (mdoc_macros
[tok
].flags
& MDOC_EXPLICIT
)) {
868 /* Here, tok is one of Sh Ss Nm Nd It. */
871 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
872 if (n
->flags
& MDOC_ENDED
) {
873 if ( ! (n
->flags
& MDOC_VALID
))
874 n
->flags
|= MDOC_BROKEN
;
877 if (n
->type
!= ROFFT_BLOCK
)
880 if (tok
== MDOC_It
&& n
->tok
== MDOC_Bl
) {
882 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
883 mdoc
->parse
, line
, ppos
,
885 mdoc_macronames
[blk
->tok
]);
886 rew_pending(mdoc
, blk
);
891 if (mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
896 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
897 mdoc
->parse
, line
, ppos
,
899 mdoc_macronames
[tok
],
900 mdoc_macronames
[n
->tok
]);
901 rew_pending(mdoc
, n
);
905 /* Delay in case it's astray. */
914 /* Here, n is one of Sh Ss Nm Nd It. */
916 if (tok
!= MDOC_Sh
&& (n
->tok
== MDOC_Sh
||
917 (tok
!= MDOC_Ss
&& (n
->tok
== MDOC_Ss
||
918 (tok
!= MDOC_It
&& n
->tok
== MDOC_It
)))))
921 /* Item breaking an explicit block. */
924 mandoc_vmsg(MANDOCERR_BLK_BROKEN
,
925 mdoc
->parse
, line
, ppos
,
927 mdoc_macronames
[blk
->tok
]);
928 rew_pending(mdoc
, blk
);
932 /* Close out prior implicit scopes. */
937 /* Skip items outside lists. */
939 if (tok
== MDOC_It
&& (n
== NULL
|| n
->tok
!= MDOC_Bl
)) {
940 mandoc_vmsg(MANDOCERR_IT_STRAY
, mdoc
->parse
,
941 line
, ppos
, "It %s", buf
+ *pos
);
942 mdoc_elem_alloc(mdoc
, line
, ppos
, MDOC_br
, NULL
);
943 rew_elem(mdoc
, MDOC_br
);
949 * This routine accommodates implicitly- and explicitly-scoped
950 * macro openings. Implicit ones first close out prior scope
951 * (seen above). Delay opening the head until necessary to
952 * allow leading punctuation to print. Special consideration
953 * for `It -column', which has phrase-part syntax instead of
954 * regular child nodes.
957 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
958 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
);
962 * Exception: Heads of `It' macros in `-diag' lists are not
963 * parsed, even though `It' macros in general are parsed.
966 parsed
= tok
!= MDOC_It
||
967 mdoc
->last
->parent
->tok
!= MDOC_Bl
||
968 mdoc
->last
->parent
->norm
->Bl
.type
!= LIST_diag
;
971 * The `Nd' macro has all arguments in its body: it's a hybrid
972 * of block partial-explicit and full-implicit. Stupid.
975 if (tok
== MDOC_Nd
) {
976 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
977 rew_last(mdoc
, head
);
978 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
982 mdoc
->flags
|= MDOC_KEEP
;
988 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
989 if (ac
== ARGS_EOLN
) {
990 if (lac
!= ARGS_PPHRASE
&& lac
!= ARGS_PHRASE
)
993 * This is necessary: if the last token on a
994 * line is a `Ta' or tab, then we'll get
995 * ARGS_EOLN, so we must be smart enough to
996 * reopen our scope if the last parse was a
997 * phrase or partial phrase.
1000 rew_last(mdoc
, body
);
1001 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1004 if (tok
== MDOC_Bd
|| tok
== MDOC_Bk
) {
1005 mandoc_vmsg(MANDOCERR_ARG_EXCESS
,
1006 mdoc
->parse
, line
, la
, "%s ... %s",
1007 mdoc_macronames
[tok
], buf
+ la
);
1010 if (tok
== MDOC_Rs
) {
1011 mandoc_vmsg(MANDOCERR_ARG_SKIP
, mdoc
->parse
,
1012 line
, la
, "Rs %s", buf
+ la
);
1015 if (ac
== ARGS_PUNCT
)
1019 * Emit leading punctuation (i.e., punctuation before
1020 * the ROFFT_HEAD) for non-phrase types.
1025 ac
!= ARGS_PHRASE
&&
1026 ac
!= ARGS_PPHRASE
&&
1028 mdoc_isdelim(p
) == DELIM_OPEN
) {
1029 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1033 /* Open a head if one hasn't been opened. */
1036 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1038 if (ac
== ARGS_PHRASE
||
1040 ac
== ARGS_PPHRASE
) {
1043 * If we haven't opened a body yet, rewind the
1044 * head; if we have, rewind that instead.
1047 rew_last(mdoc
, body
== NULL
? head
: body
);
1048 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1051 * Process phrases: set whether we're in a
1052 * partial-phrase (this effects line handling)
1053 * then call down into the phrase parser.
1056 if (ac
== ARGS_PPHRASE
)
1057 mdoc
->flags
|= MDOC_PPHRASE
;
1058 if (ac
== ARGS_PEND
&& lac
== ARGS_PPHRASE
)
1059 mdoc
->flags
|= MDOC_PPHRASE
;
1060 parse_rest(mdoc
, MDOC_MAX
, line
, &la
, buf
);
1061 mdoc
->flags
&= ~MDOC_PPHRASE
;
1065 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, parsed
))
1069 if (blk
->flags
& MDOC_VALID
)
1072 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1073 if (nl
&& tok
!= MDOC_Bd
&& tok
!= MDOC_Bl
&& tok
!= MDOC_Rs
)
1074 append_delims(mdoc
, line
, pos
, buf
);
1079 * If there is an open (i.e., unvalidated) sub-block requiring
1080 * explicit close-out, postpone switching the current block from
1081 * head to body until the rew_pending() call closing out that
1084 for (n
= mdoc
->last
; n
&& n
!= head
; n
= n
->parent
) {
1085 if (n
->flags
& MDOC_ENDED
) {
1086 if ( ! (n
->flags
& MDOC_VALID
))
1087 n
->flags
|= MDOC_BROKEN
;
1090 if (n
->type
== ROFFT_BLOCK
&&
1091 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
1092 n
->flags
= MDOC_BROKEN
;
1093 head
->flags
= MDOC_ENDED
;
1096 if (head
->flags
& MDOC_ENDED
)
1099 /* Close out scopes to remain in a consistent state. */
1101 rew_last(mdoc
, head
);
1102 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1104 if (mdoc
->flags
& MDOC_FREECOL
) {
1105 rew_last(mdoc
, body
);
1106 rew_last(mdoc
, blk
);
1107 mdoc
->flags
&= ~MDOC_FREECOL
;
1112 blk_part_imp(MACRO_PROT_ARGS
)
1117 struct mdoc_node
*blk
; /* saved block context */
1118 struct mdoc_node
*body
; /* saved body context */
1119 struct mdoc_node
*n
;
1121 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1124 * A macro that spans to the end of the line. This is generally
1125 * (but not necessarily) called as the first macro. The block
1126 * has a head as the immediate child, which is always empty,
1127 * followed by zero or more opening punctuation nodes, then the
1128 * body (which may be empty, depending on the macro), then zero
1129 * or more closing punctuation nodes.
1132 blk
= mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1133 rew_last(mdoc
, mdoc_head_alloc(mdoc
, line
, ppos
, tok
));
1136 * Open the body scope "on-demand", that is, after we've
1137 * processed all our the leading delimiters (open parenthesis,
1141 for (body
= NULL
; ; ) {
1143 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1144 if (ac
== ARGS_EOLN
|| ac
== ARGS_PUNCT
)
1147 if (body
== NULL
&& ac
!= ARGS_QWORD
&&
1148 mdoc_isdelim(p
) == DELIM_OPEN
) {
1149 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1154 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1156 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1160 body
= mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1163 * If there is an open sub-block requiring explicit close-out,
1164 * postpone closing out the current block until the
1165 * rew_pending() call closing out the sub-block.
1168 for (n
= mdoc
->last
; n
&& n
!= body
&& n
!= blk
->parent
;
1170 if (n
->flags
& MDOC_ENDED
) {
1171 if ( ! (n
->flags
& MDOC_VALID
))
1172 n
->flags
|= MDOC_BROKEN
;
1175 if (n
->type
== ROFFT_BLOCK
&&
1176 mdoc_macros
[n
->tok
].flags
& MDOC_EXPLICIT
) {
1177 n
->flags
|= MDOC_BROKEN
;
1178 if ( ! (body
->flags
& MDOC_ENDED
)) {
1179 mandoc_vmsg(MANDOCERR_BLK_NEST
,
1180 mdoc
->parse
, line
, ppos
,
1181 "%s breaks %s", mdoc_macronames
[tok
],
1182 mdoc_macronames
[n
->tok
]);
1183 mdoc_endbody_alloc(mdoc
, line
, ppos
,
1184 tok
, body
, ENDBODY_NOSPACE
);
1189 if (body
->flags
& MDOC_ENDED
)
1192 rew_last(mdoc
, body
);
1194 append_delims(mdoc
, line
, pos
, buf
);
1195 rew_pending(mdoc
, blk
);
1197 /* Move trailing .Ns out of scope. */
1199 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1201 if (n
&& n
->tok
== MDOC_Ns
)
1202 mdoc_node_relink(mdoc
, n
);
1206 blk_part_exp(MACRO_PROT_ARGS
)
1210 struct mdoc_node
*head
; /* keep track of head */
1213 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1216 * The opening of an explicit macro having zero or more leading
1217 * punctuation nodes; a head with optional single element (the
1218 * case of `Eo'); and a body that may be empty.
1221 mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
);
1225 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1226 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
)
1229 /* Flush out leading punctuation. */
1231 if (head
== NULL
&& ac
!= ARGS_QWORD
&&
1232 mdoc_isdelim(p
) == DELIM_OPEN
) {
1233 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1238 head
= mdoc_head_alloc(mdoc
, line
, ppos
, tok
);
1239 if (tok
== MDOC_Eo
) /* Not parsed. */
1240 dword(mdoc
, line
, la
, p
, DELIM_MAX
, 0);
1241 rew_last(mdoc
, head
);
1242 mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1247 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1251 /* Clean-up to leave in a consistent state. */
1254 rew_last(mdoc
, mdoc_head_alloc(mdoc
, line
, ppos
, tok
));
1255 mdoc_body_alloc(mdoc
, line
, ppos
, tok
);
1258 append_delims(mdoc
, line
, pos
, buf
);
1262 in_line_argn(MACRO_PROT_ARGS
)
1264 struct mdoc_arg
*arg
;
1268 int state
; /* arg#; -1: not yet open; -2: closed */
1269 int la
, maxargs
, nl
;
1271 nl
= mdoc
->flags
& MDOC_NEWLINE
;
1274 * A line macro that has a fixed number of arguments (maxargs).
1275 * Only open the scope once the first non-leading-punctuation is
1276 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1277 * keep it open until the maximum number of arguments are
1301 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1307 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1309 if (ac
== ARGS_WORD
&& state
== -1 &&
1310 ! (mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
) &&
1311 mdoc_isdelim(p
) == DELIM_OPEN
) {
1312 dword(mdoc
, line
, la
, p
, DELIM_OPEN
, 0);
1316 if (state
== -1 && tok
!= MDOC_In
&&
1317 tok
!= MDOC_St
&& tok
!= MDOC_Xr
) {
1318 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1322 if (ac
== ARGS_PUNCT
|| ac
== ARGS_EOLN
) {
1323 if (abs(state
) < 2 && tok
== MDOC_Pf
)
1324 mandoc_vmsg(MANDOCERR_PF_SKIP
,
1325 mdoc
->parse
, line
, ppos
, "Pf %s",
1326 p
== NULL
? "at eol" : p
);
1330 if (state
== maxargs
) {
1331 rew_elem(mdoc
, tok
);
1335 ntok
= (ac
== ARGS_QWORD
|| (tok
== MDOC_Pf
&& state
== 0)) ?
1336 MDOC_MAX
: lookup(mdoc
, tok
, line
, la
, p
);
1338 if (ntok
!= MDOC_MAX
) {
1340 rew_elem(mdoc
, tok
);
1343 mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
);
1347 if (ac
== ARGS_QWORD
||
1348 mdoc_macros
[tok
].flags
& MDOC_IGNDELIM
||
1349 mdoc_isdelim(p
) == DELIM_NONE
) {
1351 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1353 } else if (state
>= 0)
1355 } else if (state
>= 0) {
1356 rew_elem(mdoc
, tok
);
1360 dword(mdoc
, line
, la
, p
, DELIM_MAX
,
1361 MDOC_JOIN
& mdoc_macros
[tok
].flags
);
1365 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
1366 line
, ppos
, mdoc_macronames
[tok
]);
1370 if (state
== 0 && tok
== MDOC_Pf
)
1371 append_delims(mdoc
, line
, pos
, buf
);
1373 rew_elem(mdoc
, tok
);
1375 append_delims(mdoc
, line
, pos
, buf
);
1379 in_line_eoln(MACRO_PROT_ARGS
)
1381 struct mdoc_node
*n
;
1382 struct mdoc_arg
*arg
;
1384 if ((tok
== MDOC_Pp
|| tok
== MDOC_Lp
) &&
1385 ! (mdoc
->flags
& MDOC_SYNOPSIS
)) {
1387 if (mdoc
->next
== MDOC_NEXT_SIBLING
)
1389 if (n
->tok
== MDOC_Nm
)
1390 rew_last(mdoc
, mdoc
->last
->parent
);
1393 if (buf
[*pos
] == '\0' &&
1394 (tok
== MDOC_Fd
|| mdoc_macronames
[tok
][0] == '%')) {
1395 mandoc_msg(MANDOCERR_MACRO_EMPTY
, mdoc
->parse
,
1396 line
, ppos
, mdoc_macronames
[tok
]);
1400 mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1401 mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
);
1402 if (parse_rest(mdoc
, tok
, line
, pos
, buf
))
1404 rew_elem(mdoc
, tok
);
1408 * The simplest argument parser available: Parse the remaining
1409 * words until the end of the phrase or line and return 0
1410 * or until the next macro, call that macro, and return 1.
1413 parse_rest(struct mdoc
*mdoc
, enum mdoct tok
, int line
, int *pos
, char *buf
)
1419 if (mdoc_args(mdoc
, line
, pos
, buf
, tok
, NULL
) == ARGS_EOLN
)
1421 if (macro_or_word(mdoc
, tok
, line
, la
, pos
, buf
, 1))
1427 ctx_synopsis(MACRO_PROT_ARGS
)
1430 if (~mdoc
->flags
& (MDOC_SYNOPSIS
| MDOC_NEWLINE
))
1431 in_line(mdoc
, tok
, line
, ppos
, pos
, buf
);
1432 else if (tok
== MDOC_Nm
)
1433 blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
);
1435 assert(tok
== MDOC_Vt
);
1436 blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
);
1441 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1442 * They're unusual because they're basically free-form text until a
1443 * macro is encountered.
1446 phrase_ta(MACRO_PROT_ARGS
)
1448 struct mdoc_node
*body
, *n
;
1450 /* Make sure we are in a column list or ignore this macro. */
1453 for (n
= mdoc
->last
; n
!= NULL
; n
= n
->parent
) {
1454 if (n
->flags
& MDOC_ENDED
)
1456 if (n
->tok
== MDOC_It
&& n
->type
== ROFFT_BODY
)
1458 if (n
->tok
== MDOC_Bl
)
1462 if (n
== NULL
|| n
->norm
->Bl
.type
!= LIST_column
) {
1463 mandoc_msg(MANDOCERR_TA_STRAY
, mdoc
->parse
,
1468 /* Advance to the next column. */
1470 rew_last(mdoc
, body
);
1471 mdoc_body_alloc(mdoc
, line
, ppos
, MDOC_It
);
1472 parse_rest(mdoc
, MDOC_MAX
, line
, pos
, buf
);