]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.98 2010/12/06 11:01:19 kristaps Exp $ */
3 * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010 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.
31 #include "libmandoc.h"
33 enum rew
{ /* see rew_dohalt() */
42 static int blk_full(MACRO_PROT_ARGS
);
43 static int blk_exp_close(MACRO_PROT_ARGS
);
44 static int blk_part_exp(MACRO_PROT_ARGS
);
45 static int blk_part_imp(MACRO_PROT_ARGS
);
46 static int ctx_synopsis(MACRO_PROT_ARGS
);
47 static int in_line_eoln(MACRO_PROT_ARGS
);
48 static int in_line_argn(MACRO_PROT_ARGS
);
49 static int in_line(MACRO_PROT_ARGS
);
50 static int obsolete(MACRO_PROT_ARGS
);
51 static int phrase_ta(MACRO_PROT_ARGS
);
53 static int append_delims(struct mdoc
*,
55 static enum mdoct
lookup(enum mdoct
, const char *);
56 static enum mdoct
lookup_raw(const char *);
57 static int make_pending(struct mdoc_node
*, enum mdoct
,
58 struct mdoc
*, int, int);
59 static int phrase(struct mdoc
*, int, int, char *);
60 static enum mdoct
rew_alt(enum mdoct
);
61 static enum rew
rew_dohalt(enum mdoct
, enum mdoc_type
,
62 const struct mdoc_node
*);
63 static int rew_elem(struct mdoc
*, enum mdoct
);
64 static int rew_last(struct mdoc
*,
65 const struct mdoc_node
*);
66 static int rew_sub(enum mdoc_type
, struct mdoc
*,
67 enum mdoct
, int, int);
69 const struct mdoc_macro __mdoc_macros
[MDOC_MAX
] = {
70 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ap */
71 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
72 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
73 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
74 { blk_full
, 0 }, /* Sh */
75 { blk_full
, 0 }, /* Ss */
76 { in_line_eoln
, 0 }, /* Pp */
77 { blk_part_imp
, MDOC_PARSED
}, /* D1 */
78 { blk_part_imp
, MDOC_PARSED
}, /* Dl */
79 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
80 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ed */
81 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
82 { blk_exp_close
, MDOC_EXPLICIT
}, /* El */
83 { blk_full
, MDOC_PARSED
}, /* It */
84 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
85 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* An */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cd */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
89 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
90 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
91 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
92 { in_line_eoln
, 0 }, /* Ex */
93 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
94 { in_line_eoln
, 0 }, /* Fd */
95 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
96 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
97 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
98 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ic */
99 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
100 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Li */
101 { blk_full
, 0 }, /* Nd */
102 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
103 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
104 { obsolete
, 0 }, /* Ot */
105 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
106 { in_line_eoln
, 0 }, /* Rv */
107 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
108 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
109 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
110 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
111 { in_line_eoln
, 0 }, /* %A */
112 { in_line_eoln
, 0 }, /* %B */
113 { in_line_eoln
, 0 }, /* %D */
114 { in_line_eoln
, 0 }, /* %I */
115 { in_line_eoln
, 0 }, /* %J */
116 { in_line_eoln
, 0 }, /* %N */
117 { in_line_eoln
, 0 }, /* %O */
118 { in_line_eoln
, 0 }, /* %P */
119 { in_line_eoln
, 0 }, /* %R */
120 { in_line_eoln
, 0 }, /* %T */
121 { in_line_eoln
, 0 }, /* %V */
122 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Ac */
123 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ao */
124 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Aq */
125 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
126 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Bc */
127 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
128 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Bo */
129 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bq */
130 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
131 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
132 { in_line_eoln
, 0 }, /* Db */
133 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Dc */
134 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Do */
135 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dq */
136 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Ec */
137 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ef */
138 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Em */
139 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
140 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
141 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
142 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* No */
143 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Ns */
144 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
145 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
146 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Pc */
147 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
148 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Po */
149 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pq */
150 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Qc */
151 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ql */
152 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Qo */
153 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Qq */
154 { blk_exp_close
, MDOC_EXPLICIT
}, /* Re */
155 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
156 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Sc */
157 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* So */
158 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sq */
159 { in_line_eoln
, 0 }, /* Sm */
160 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sx */
161 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sy */
162 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
163 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ux */
164 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
165 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
166 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
167 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Fc */
168 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Oo */
169 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Oc */
170 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
171 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ek */
172 { in_line_eoln
, 0 }, /* Bt */
173 { in_line_eoln
, 0 }, /* Hf */
174 { obsolete
, 0 }, /* Fr */
175 { in_line_eoln
, 0 }, /* Ud */
176 { in_line
, 0 }, /* Lb */
177 { in_line_eoln
, 0 }, /* Lp */
178 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
179 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
180 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Brq */
181 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Bro */
182 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Brc */
183 { in_line_eoln
, 0 }, /* %C */
184 { obsolete
, 0 }, /* Es */
185 { obsolete
, 0 }, /* En */
186 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
187 { in_line_eoln
, 0 }, /* %Q */
188 { in_line_eoln
, 0 }, /* br */
189 { in_line_eoln
, 0 }, /* sp */
190 { in_line_eoln
, 0 }, /* %U */
191 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ta */
194 const struct mdoc_macro
* const mdoc_macros
= __mdoc_macros
;
198 * This is called at the end of parsing. It must traverse up the tree,
199 * closing out open [implicit] scopes. Obviously, open explicit scopes
203 mdoc_macroend(struct mdoc
*m
)
207 /* Scan for open explicit scopes. */
209 n
= MDOC_VALID
& m
->last
->flags
? m
->last
->parent
: m
->last
;
211 for ( ; n
; n
= n
->parent
)
212 if (MDOC_BLOCK
== n
->type
&&
213 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
)
214 mdoc_nmsg(m
, n
, MANDOCERR_SCOPEEXIT
);
216 /* Rewind to the first. */
218 return(rew_last(m
, m
->first
));
223 * Look up a macro from within a subsequent context.
226 lookup(enum mdoct from
, const char *p
)
228 /* FIXME: make -diag lists be un-PARSED. */
230 if ( ! (MDOC_PARSED
& mdoc_macros
[from
].flags
))
232 return(lookup_raw(p
));
237 * Lookup a macro following the initial line macro.
240 lookup_raw(const char *p
)
244 if (MDOC_MAX
== (res
= mdoc_hash_find(p
)))
246 if (MDOC_CALLABLE
& mdoc_macros
[res
].flags
)
253 rew_last(struct mdoc
*mdoc
, const struct mdoc_node
*to
)
257 mdoc
->next
= MDOC_NEXT_SIBLING
;
260 while (mdoc
->last
!= to
) {
261 if ( ! mdoc_valid_post(mdoc
))
263 mdoc
->last
= mdoc
->last
->parent
;
267 return(mdoc_valid_post(mdoc
));
272 * For a block closing macro, return the corresponding opening one.
273 * Otherwise, return the macro itself.
276 rew_alt(enum mdoct tok
)
319 * Rewinding to tok, how do we have to handle *p?
320 * REWIND_NONE: *p would delimit tok, but no tok scope is open
321 * inside *p, so there is no need to rewind anything at all.
322 * REWIND_THIS: *p matches tok, so rewind *p and nothing else.
323 * REWIND_MORE: *p is implicit, rewind it and keep searching for tok.
324 * REWIND_FORCE: *p is explicit, but tok is full, force rewinding *p.
325 * REWIND_LATER: *p is explicit and still open, postpone rewinding.
326 * REWIND_ERROR: No tok block is open at all.
329 rew_dohalt(enum mdoct tok
, enum mdoc_type type
,
330 const struct mdoc_node
*p
)
334 * No matching token, no delimiting block, no broken block.
335 * This can happen when full implicit macros are called for
336 * the first time but try to rewind their previous
339 if (MDOC_ROOT
== p
->type
)
340 return(MDOC_BLOCK
== type
&&
341 MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
?
342 REWIND_ERROR
: REWIND_NONE
);
345 * When starting to rewind, skip plain text
346 * and nodes that have already been rewound.
348 if (MDOC_TEXT
== p
->type
|| MDOC_VALID
& p
->flags
)
352 * The easiest case: Found a matching token.
353 * This applies to both blocks and elements.
357 return(p
->end
? REWIND_NONE
:
358 type
== p
->type
? REWIND_THIS
: REWIND_MORE
);
361 * While elements do require rewinding for themselves,
362 * they never affect rewinding of other nodes.
364 if (MDOC_ELEM
== p
->type
)
368 * Blocks delimited by our target token get REWIND_MORE.
369 * Blocks delimiting our target token get REWIND_NONE.
373 if (MDOC_It
== p
->tok
)
377 if (MDOC_BODY
== p
->type
&& MDOC_Bl
== p
->tok
)
381 * XXX Badly nested block handling still fails badly
382 * when one block is breaking two blocks of the same type.
383 * This is an incomplete and extremely ugly workaround,
384 * required to let the OpenBSD tree build.
387 if (MDOC_Op
== p
->tok
)
395 if (MDOC_BODY
== p
->type
&& MDOC_Sh
== p
->tok
)
399 if (MDOC_Nd
== p
->tok
|| MDOC_Ss
== p
->tok
||
408 * Default block rewinding rules.
409 * In particular, always skip block end markers,
410 * and let all blocks rewind Nm children.
412 if (ENDBODY_NOT
!= p
->end
|| MDOC_Nm
== p
->tok
||
413 (MDOC_BLOCK
== p
->type
&&
414 ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)))
418 * By default, closing out full blocks
419 * forces closing of broken explicit blocks,
420 * while closing out partial blocks
421 * allows delayed rewinding by default.
423 return (&blk_full
== mdoc_macros
[tok
].fp
?
424 REWIND_FORCE
: REWIND_LATER
);
429 rew_elem(struct mdoc
*mdoc
, enum mdoct tok
)
434 if (MDOC_ELEM
!= n
->type
)
436 assert(MDOC_ELEM
== n
->type
);
437 assert(tok
== n
->tok
);
439 return(rew_last(mdoc
, n
));
444 * We are trying to close a block identified by tok,
445 * but the child block *broken is still open.
446 * Thus, postpone closing the tok block
447 * until the rew_sub call closing *broken.
450 make_pending(struct mdoc_node
*broken
, enum mdoct tok
,
451 struct mdoc
*m
, int line
, int ppos
)
453 struct mdoc_node
*breaker
;
456 * Iterate backwards, searching for the block matching tok,
457 * that is, the block breaking the *broken block.
459 for (breaker
= broken
->parent
; breaker
; breaker
= breaker
->parent
) {
462 * If the *broken block had already been broken before
463 * and we encounter its breaker, make the tok block
464 * pending on the inner breaker.
465 * Graphically, "[A breaker=[B broken=[C->B B] tok=A] C]"
466 * becomes "[A broken=[B [C->B B] tok=A] C]"
467 * and finally "[A [B->A [C->B B] A] C]".
469 if (breaker
== broken
->pending
) {
474 if (REWIND_THIS
!= rew_dohalt(tok
, MDOC_BLOCK
, breaker
))
476 if (MDOC_BODY
== broken
->type
)
477 broken
= broken
->parent
;
481 * If another, outer breaker is already pending on
482 * the *broken block, we must not clobber the link
483 * to the outer breaker, but make it pending on the
484 * new, now inner breaker.
485 * Graphically, "[A breaker=[B broken=[C->A A] tok=B] C]"
486 * becomes "[A breaker=[B->A broken=[C A] tok=B] C]"
487 * and finally "[A [B->A [C->B A] B] C]".
489 if (broken
->pending
) {
490 struct mdoc_node
*taker
;
493 * If the breaker had also been broken before,
494 * it cannot take on the outer breaker itself,
495 * but must hand it on to its own breakers.
496 * Graphically, this is the following situation:
497 * "[A [B breaker=[C->B B] broken=[D->A A] tok=C] D]"
498 * "[A taker=[B->A breaker=[C->B B] [D->C A] C] D]"
501 while (taker
->pending
)
502 taker
= taker
->pending
;
503 taker
->pending
= broken
->pending
;
505 broken
->pending
= breaker
;
506 mdoc_vmsg(m
, MANDOCERR_SCOPENEST
, line
, ppos
,
507 "%s breaks %s", mdoc_macronames
[tok
],
508 mdoc_macronames
[broken
->tok
]);
513 * Found no matching block for tok.
514 * Are you trying to close a block that is not open?
521 rew_sub(enum mdoc_type t
, struct mdoc
*m
,
522 enum mdoct tok
, int line
, int ppos
)
528 switch (rew_dohalt(tok
, t
, n
)) {
534 mdoc_vmsg(m
, MANDOCERR_SCOPEBROKEN
, line
, ppos
,
535 "%s breaks %s", mdoc_macronames
[tok
],
536 mdoc_macronames
[n
->tok
]);
542 if (make_pending(n
, tok
, m
, line
, ppos
) ||
547 mdoc_pmsg(m
, line
, ppos
, MANDOCERR_NOSCOPE
);
554 if ( ! rew_last(m
, n
))
558 * The current block extends an enclosing block.
559 * Now that the current block ends, close the enclosing block, too.
561 while (NULL
!= (n
= n
->pending
)) {
562 if ( ! rew_last(m
, n
))
564 if (MDOC_HEAD
== n
->type
&&
565 ! mdoc_body_alloc(m
, n
->line
, n
->pos
, n
->tok
))
574 append_delims(struct mdoc
*m
, int line
, int *pos
, char *buf
)
580 if ('\0' == buf
[*pos
])
585 ac
= mdoc_zargs(m
, line
, pos
, buf
, ARGS_NOWARN
, &p
);
587 if (ARGS_ERROR
== ac
)
589 else if (ARGS_EOLN
== ac
)
592 assert(DELIM_NONE
!= mdoc_isdelim(p
));
593 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
597 * If we encounter end-of-sentence symbols, then trigger
600 * XXX: it's easy to allow this to propogate outward to
601 * the last symbol, such that `. )' will cause the
602 * correct double-spacing. However, (1) groff isn't
603 * smart enough to do this and (2) it would require
604 * knowing which symbols break this behaviour, for
605 * example, `. ;' shouldn't propogate the double-space.
607 if (mandoc_eos(p
, strlen(p
), 0))
608 m
->last
->flags
|= MDOC_EOS
;
616 * Close out block partial/full explicit.
619 blk_exp_close(MACRO_PROT_ARGS
)
621 struct mdoc_node
*body
; /* Our own body. */
622 struct mdoc_node
*later
; /* A sub-block starting later. */
623 struct mdoc_node
*n
; /* For searching backwards. */
625 int j
, lastarg
, maxargs
, flushed
, nl
;
627 enum mdoct atok
, ntok
;
630 nl
= MDOC_NEWLINE
& m
->flags
;
642 * Search backwards for beginnings of blocks,
643 * both of our own and of pending sub-blocks.
647 for (n
= m
->last
; n
; n
= n
->parent
) {
648 if (MDOC_VALID
& n
->flags
)
651 /* Remember the start of our own body. */
652 if (MDOC_BODY
== n
->type
&& atok
== n
->tok
) {
653 if (ENDBODY_NOT
== n
->end
)
658 if (MDOC_BLOCK
!= n
->type
|| MDOC_Nm
== n
->tok
)
660 if (atok
== n
->tok
) {
664 * Found the start of our own block.
665 * When there is no pending sub block,
666 * just proceed to closing out.
672 * When there is a pending sub block,
673 * postpone closing out the current block
674 * until the rew_sub() closing out the sub-block.
676 make_pending(later
, tok
, m
, line
, ppos
);
679 * Mark the place where the formatting - but not
680 * the scope - of the current block ends.
682 if ( ! mdoc_endbody_alloc(m
, line
, ppos
,
683 atok
, body
, ENDBODY_SPACE
))
689 * When finding an open sub block, remember the last
690 * open explicit block, or, in case there are only
691 * implicit ones, the first open implicit block.
694 MDOC_EXPLICIT
& mdoc_macros
[later
->tok
].flags
)
696 if (MDOC_CALLABLE
& mdoc_macros
[n
->tok
].flags
)
700 if ( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
)) {
701 /* FIXME: do this in validate */
703 if ( ! mdoc_pmsg(m
, line
, ppos
, MANDOCERR_ARGSLOST
))
706 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
708 return(rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
));
711 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
714 if (NULL
== later
&& maxargs
> 0)
715 if ( ! mdoc_tail_alloc(m
, line
, ppos
, rew_alt(tok
)))
718 for (flushed
= j
= 0; ; j
++) {
721 if (j
== maxargs
&& ! flushed
) {
722 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
727 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
729 if (ARGS_ERROR
== ac
)
731 if (ARGS_PUNCT
== ac
)
736 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
738 if (MDOC_MAX
== ntok
) {
739 if ( ! mdoc_word_alloc(m
, line
, lastarg
, p
))
745 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
749 if ( ! mdoc_macro(m
, ntok
, line
, lastarg
, pos
, buf
))
754 if ( ! flushed
&& ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
759 return(append_delims(m
, line
, pos
, buf
));
764 in_line(MACRO_PROT_ARGS
)
766 int la
, scope
, cnt
, nc
, nl
;
771 struct mdoc_arg
*arg
;
774 nl
= MDOC_NEWLINE
& m
->flags
;
777 * Whether we allow ignored elements (those without content,
778 * usually because of reserved words) to squeak by.
800 for (arg
= NULL
;; ) {
802 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
804 if (ARGV_WORD
== av
) {
817 for (cnt
= scope
= 0;; ) {
819 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
821 if (ARGS_ERROR
== ac
)
825 if (ARGS_PUNCT
== ac
)
828 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
831 * In this case, we've located a submacro and must
832 * execute it. Close out scope, if open. If no
833 * elements have been generated, either create one (nc)
834 * or raise a warning.
837 if (MDOC_MAX
!= ntok
) {
838 if (scope
&& ! rew_elem(m
, tok
))
840 if (nc
&& 0 == cnt
) {
841 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
843 if ( ! rew_last(m
, m
->last
))
845 } else if ( ! nc
&& 0 == cnt
) {
847 if ( ! mdoc_pmsg(m
, line
, ppos
, MANDOCERR_MACROEMPTY
))
850 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
854 return(append_delims(m
, line
, pos
, buf
));
858 * Non-quote-enclosed punctuation. Set up our scope, if
859 * a word; rewind the scope, if a delimiter; then append
863 d
= ARGS_QWORD
== ac
? DELIM_NONE
: mdoc_isdelim(p
);
865 if (DELIM_NONE
!= d
) {
867 * If we encounter closing punctuation, no word
868 * has been omitted, no scope is open, and we're
869 * allowed to have an empty element, then start
870 * a new scope. `Ar', `Fl', and `Li', only do
871 * this once per invocation. There may be more
872 * of these (all of them?).
874 if (0 == cnt
&& (nc
|| MDOC_Li
== tok
) &&
875 DELIM_CLOSE
== d
&& ! scope
) {
876 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
878 if (MDOC_Ar
== tok
|| MDOC_Li
== tok
||
884 * Close out our scope, if one is open, before
887 if (scope
&& ! rew_elem(m
, tok
))
890 } else if ( ! scope
) {
891 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
898 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
902 * `Fl' macros have their scope re-opened with each new
903 * word so that the `-' can be added to each one without
904 * having to parse out spaces.
906 if (scope
&& MDOC_Fl
== tok
) {
907 if ( ! rew_elem(m
, tok
))
913 if (scope
&& ! rew_elem(m
, tok
))
917 * If no elements have been collected and we're allowed to have
918 * empties (nc), open a scope and close it out. Otherwise,
922 if (nc
&& 0 == cnt
) {
923 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
925 if ( ! rew_last(m
, m
->last
))
927 } else if ( ! nc
&& 0 == cnt
) {
929 if ( ! mdoc_pmsg(m
, line
, ppos
, MANDOCERR_MACROEMPTY
))
935 return(append_delims(m
, line
, pos
, buf
));
940 blk_full(MACRO_PROT_ARGS
)
943 struct mdoc_arg
*arg
;
944 struct mdoc_node
*head
; /* save of head macro */
945 struct mdoc_node
*body
; /* save of body macro */
949 enum margserr ac
, lac
;
953 nl
= MDOC_NEWLINE
& m
->flags
;
955 /* Close out prior implicit scope. */
957 if ( ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)) {
958 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
960 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
965 * This routine accomodates implicitly- and explicitly-scoped
966 * macro openings. Implicit ones first close out prior scope
967 * (seen above). Delay opening the head until necessary to
968 * allow leading punctuation to print. Special consideration
969 * for `It -column', which has phrase-part syntax instead of
970 * regular child nodes.
973 for (arg
= NULL
;; ) {
975 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
977 if (ARGV_WORD
== av
) {
991 if ( ! mdoc_block_alloc(m
, line
, ppos
, tok
, arg
))
997 * The `Nd' macro has all arguments in its body: it's a hybrid
998 * of block partial-explicit and full-implicit. Stupid.
1001 if (MDOC_Nd
== tok
) {
1002 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1005 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1007 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1016 /* Initialise last-phrase-type with ARGS_PEND. */
1017 lac
= ARGS_ERROR
== ac
? ARGS_PEND
: ac
;
1018 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1020 if (ARGS_PUNCT
== ac
)
1023 if (ARGS_ERROR
== ac
)
1026 if (ARGS_EOLN
== ac
) {
1027 if (ARGS_PPHRASE
!= lac
&& ARGS_PHRASE
!= lac
)
1030 * This is necessary: if the last token on a
1031 * line is a `Ta' or tab, then we'll get
1032 * ARGS_EOLN, so we must be smart enough to
1033 * reopen our scope if the last parse was a
1034 * phrase or partial phrase.
1036 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
1038 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1045 * Emit leading punctuation (i.e., punctuation before
1046 * the MDOC_HEAD) for non-phrase types.
1051 ARGS_PHRASE
!= ac
&&
1052 ARGS_PPHRASE
!= ac
&&
1054 DELIM_OPEN
== mdoc_isdelim(p
)) {
1055 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1060 /* Open a head if one hasn't been opened. */
1063 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1068 if (ARGS_PHRASE
== ac
||
1070 ARGS_PPHRASE
== ac
) {
1072 * If we haven't opened a body yet, rewind the
1073 * head; if we have, rewind that instead.
1076 mtt
= body
? MDOC_BODY
: MDOC_HEAD
;
1077 if ( ! rew_sub(mtt
, m
, tok
, line
, ppos
))
1080 /* Then allocate our body context. */
1082 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1087 * Process phrases: set whether we're in a
1088 * partial-phrase (this effects line handling)
1089 * then call down into the phrase parser.
1092 if (ARGS_PPHRASE
== ac
)
1093 m
->flags
|= MDOC_PPHRASE
;
1094 if (ARGS_PEND
== ac
&& ARGS_PPHRASE
== lac
)
1095 m
->flags
|= MDOC_PPHRASE
;
1097 if ( ! phrase(m
, line
, la
, buf
))
1100 m
->flags
&= ~MDOC_PPHRASE
;
1104 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1106 if (MDOC_MAX
== ntok
) {
1107 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1112 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1118 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1123 if (nl
&& ! append_delims(m
, line
, pos
, buf
))
1126 /* If we've already opened our body, exit now. */
1132 * If there is an open (i.e., unvalidated) sub-block requiring
1133 * explicit close-out, postpone switching the current block from
1134 * head to body until the rew_sub() call closing out that
1137 for (n
= m
->last
; n
&& n
!= head
; n
= n
->parent
) {
1138 if (MDOC_BLOCK
== n
->type
&&
1139 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
&&
1140 ! (MDOC_VALID
& n
->flags
)) {
1146 /* Close out scopes to remain in a consistent state. */
1148 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1150 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1154 if ( ! (MDOC_FREECOL
& m
->flags
))
1157 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
1159 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
1162 m
->flags
&= ~MDOC_FREECOL
;
1168 blk_part_imp(MACRO_PROT_ARGS
)
1174 struct mdoc_node
*blk
; /* saved block context */
1175 struct mdoc_node
*body
; /* saved body context */
1176 struct mdoc_node
*n
;
1178 nl
= MDOC_NEWLINE
& m
->flags
;
1181 * A macro that spans to the end of the line. This is generally
1182 * (but not necessarily) called as the first macro. The block
1183 * has a head as the immediate child, which is always empty,
1184 * followed by zero or more opening punctuation nodes, then the
1185 * body (which may be empty, depending on the macro), then zero
1186 * or more closing punctuation nodes.
1189 if ( ! mdoc_block_alloc(m
, line
, ppos
, tok
, NULL
))
1194 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1196 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1200 * Open the body scope "on-demand", that is, after we've
1201 * processed all our the leading delimiters (open parenthesis,
1205 for (body
= NULL
; ; ) {
1207 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1209 if (ARGS_ERROR
== ac
)
1211 if (ARGS_EOLN
== ac
)
1213 if (ARGS_PUNCT
== ac
)
1216 if (NULL
== body
&& ARGS_QWORD
!= ac
&&
1217 DELIM_OPEN
== mdoc_isdelim(p
)) {
1218 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1224 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1229 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1231 if (MDOC_MAX
== ntok
) {
1232 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1237 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1242 /* Clean-ups to leave in a consistent state. */
1245 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1250 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1254 * End of sentence spacing: if the last node is a text node and
1255 * has a trailing period, then mark it as being end-of-sentence.
1258 if (n
&& MDOC_TEXT
== n
->type
&& n
->string
)
1259 if (mandoc_eos(n
->string
, strlen(n
->string
), 1))
1260 n
->flags
|= MDOC_EOS
;
1262 /* Up-propogate the end-of-space flag. */
1264 if (n
&& (MDOC_EOS
& n
->flags
)) {
1265 body
->flags
|= MDOC_EOS
;
1266 body
->parent
->flags
|= MDOC_EOS
;
1270 * If there is an open sub-block requiring explicit close-out,
1271 * postpone closing out the current block
1272 * until the rew_sub() call closing out the sub-block.
1274 for (n
= m
->last
; n
&& n
!= body
&& n
!= blk
->parent
; n
= n
->parent
) {
1275 if (MDOC_BLOCK
== n
->type
&&
1276 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
&&
1277 ! (MDOC_VALID
& n
->flags
)) {
1278 make_pending(n
, tok
, m
, line
, ppos
);
1279 if ( ! mdoc_endbody_alloc(m
, line
, ppos
,
1280 tok
, body
, ENDBODY_NOSPACE
))
1287 * If we can't rewind to our body, then our scope has already
1288 * been closed by another macro (like `Oc' closing `Op'). This
1289 * is ugly behaviour nodding its head to OpenBSD's overwhelming
1290 * crufty use of `Op' breakage.
1292 if (n
!= body
&& ! mdoc_vmsg(m
, MANDOCERR_SCOPENEST
,
1293 line
, ppos
, "%s broken", mdoc_macronames
[tok
]))
1296 if (n
&& ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
1299 /* Standard appending of delimiters. */
1301 if (nl
&& ! append_delims(m
, line
, pos
, buf
))
1304 /* Rewind scope, if applicable. */
1306 if (n
&& ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
1314 blk_part_exp(MACRO_PROT_ARGS
)
1318 struct mdoc_node
*head
; /* keep track of head */
1319 struct mdoc_node
*body
; /* keep track of body */
1323 nl
= MDOC_NEWLINE
& m
->flags
;
1326 * The opening of an explicit macro having zero or more leading
1327 * punctuation nodes; a head with optional single element (the
1328 * case of `Eo'); and a body that may be empty.
1331 if ( ! mdoc_block_alloc(m
, line
, ppos
, tok
, NULL
))
1334 for (head
= body
= NULL
; ; ) {
1336 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1338 if (ARGS_ERROR
== ac
)
1340 if (ARGS_PUNCT
== ac
)
1342 if (ARGS_EOLN
== ac
)
1345 /* Flush out leading punctuation. */
1347 if (NULL
== head
&& ARGS_QWORD
!= ac
&&
1348 DELIM_OPEN
== mdoc_isdelim(p
)) {
1349 assert(NULL
== body
);
1350 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1356 assert(NULL
== body
);
1357 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1363 * `Eo' gobbles any data into the head, but most other
1364 * macros just immediately close out and begin the body.
1369 /* No check whether it's a macro! */
1371 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1374 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1376 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1384 assert(NULL
!= head
&& NULL
!= body
);
1386 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1388 if (MDOC_MAX
== ntok
) {
1389 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1394 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1399 /* Clean-up to leave in a consistent state. */
1402 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1408 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1410 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1415 /* Standard appending of delimiters. */
1419 return(append_delims(m
, line
, pos
, buf
));
1425 in_line_argn(MACRO_PROT_ARGS
)
1427 int la
, flushed
, j
, maxargs
, nl
;
1430 struct mdoc_arg
*arg
;
1434 nl
= MDOC_NEWLINE
& m
->flags
;
1437 * A line macro that has a fixed number of arguments (maxargs).
1438 * Only open the scope once the first non-leading-punctuation is
1439 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1440 * keep it open until the maximum number of arguments are
1462 for (arg
= NULL
; ; ) {
1464 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
1466 if (ARGV_WORD
== av
) {
1471 if (ARGV_EOLN
== av
)
1476 mdoc_argv_free(arg
);
1480 for (flushed
= j
= 0; ; ) {
1482 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1484 if (ARGS_ERROR
== ac
)
1486 if (ARGS_PUNCT
== ac
)
1488 if (ARGS_EOLN
== ac
)
1491 if ( ! (MDOC_IGNDELIM
& mdoc_macros
[tok
].flags
) &&
1493 0 == j
&& DELIM_OPEN
== mdoc_isdelim(p
)) {
1494 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1498 if ( ! mdoc_elem_alloc(m
, line
, la
, tok
, arg
))
1501 if (j
== maxargs
&& ! flushed
) {
1502 if ( ! rew_elem(m
, tok
))
1507 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1509 if (MDOC_MAX
!= ntok
) {
1510 if ( ! flushed
&& ! rew_elem(m
, tok
))
1513 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1519 if ( ! (MDOC_IGNDELIM
& mdoc_macros
[tok
].flags
) &&
1522 DELIM_NONE
!= mdoc_isdelim(p
)) {
1523 if ( ! rew_elem(m
, tok
))
1529 * XXX: this is a hack to work around groff's ugliness
1530 * as regards `Xr' and extraneous arguments. It should
1531 * ideally be deprecated behaviour, but because this is
1532 * code is no here, it's unlikely to be removed.
1536 if (MDOC_Xr
== tok
&& j
== maxargs
) {
1537 if ( ! mdoc_elem_alloc(m
, line
, la
, MDOC_Ns
, NULL
))
1539 if ( ! rew_elem(m
, MDOC_Ns
))
1544 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1549 if (0 == j
&& ! mdoc_elem_alloc(m
, line
, la
, tok
, arg
))
1552 /* Close out in a consistent state. */
1554 if ( ! flushed
&& ! rew_elem(m
, tok
))
1558 return(append_delims(m
, line
, pos
, buf
));
1563 in_line_eoln(MACRO_PROT_ARGS
)
1568 struct mdoc_arg
*arg
;
1572 assert( ! (MDOC_PARSED
& mdoc_macros
[tok
].flags
));
1575 rew_sub(MDOC_BLOCK
, m
, MDOC_Nm
, line
, ppos
);
1577 /* Parse macro arguments. */
1579 for (arg
= NULL
; ; ) {
1581 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
1583 if (ARGV_WORD
== av
) {
1587 if (ARGV_EOLN
== av
)
1592 mdoc_argv_free(arg
);
1596 /* Open element scope. */
1598 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
1601 /* Parse argument terms. */
1605 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1607 if (ARGS_ERROR
== ac
)
1609 if (ARGS_EOLN
== ac
)
1612 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1614 if (MDOC_MAX
== ntok
) {
1615 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1620 if ( ! rew_elem(m
, tok
))
1622 return(mdoc_macro(m
, ntok
, line
, la
, pos
, buf
));
1625 /* Close out (no delimiters). */
1627 return(rew_elem(m
, tok
));
1633 ctx_synopsis(MACRO_PROT_ARGS
)
1637 nl
= MDOC_NEWLINE
& m
->flags
;
1639 /* If we're not in the SYNOPSIS, go straight to in-line. */
1640 if ( ! (MDOC_SYNOPSIS
& m
->flags
))
1641 return(in_line(m
, tok
, line
, ppos
, pos
, buf
));
1643 /* If we're a nested call, same place. */
1645 return(in_line(m
, tok
, line
, ppos
, pos
, buf
));
1648 * XXX: this will open a block scope; however, if later we end
1649 * up formatting the block scope, then child nodes will inherit
1650 * the formatting. Be careful.
1653 return(blk_full(m
, tok
, line
, ppos
, pos
, buf
));
1654 assert(MDOC_Vt
== tok
);
1655 return(blk_part_imp(m
, tok
, line
, ppos
, pos
, buf
));
1661 obsolete(MACRO_PROT_ARGS
)
1664 return(mdoc_pmsg(m
, line
, ppos
, MANDOCERR_MACROOBS
));
1669 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1670 * They're unusual because they're basically free-form text until a
1671 * macro is encountered.
1674 phrase(struct mdoc
*m
, int line
, int ppos
, char *buf
)
1681 for (pos
= ppos
; ; ) {
1684 ac
= mdoc_zargs(m
, line
, &pos
, buf
, 0, &p
);
1686 if (ARGS_ERROR
== ac
)
1688 if (ARGS_EOLN
== ac
)
1691 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup_raw(p
);
1693 if (MDOC_MAX
== ntok
) {
1694 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1699 if ( ! mdoc_macro(m
, ntok
, line
, la
, &pos
, buf
))
1701 return(append_delims(m
, line
, &pos
, buf
));
1710 phrase_ta(MACRO_PROT_ARGS
)
1718 * FIXME: this is overly restrictive: if the `Ta' is unexpected,
1719 * it should simply error out with ARGSLOST.
1722 if ( ! rew_sub(MDOC_BODY
, m
, MDOC_It
, line
, ppos
))
1724 if ( ! mdoc_body_alloc(m
, line
, ppos
, MDOC_It
))
1729 ac
= mdoc_zargs(m
, line
, pos
, buf
, 0, &p
);
1731 if (ARGS_ERROR
== ac
)
1733 if (ARGS_EOLN
== ac
)
1736 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup_raw(p
);
1738 if (MDOC_MAX
== ntok
) {
1739 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1744 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1746 return(append_delims(m
, line
, pos
, buf
));