]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.95 2010/10/01 21:51:13 schwarze 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() */
41 static int blk_full(MACRO_PROT_ARGS
);
42 static int blk_exp_close(MACRO_PROT_ARGS
);
43 static int blk_part_exp(MACRO_PROT_ARGS
);
44 static int blk_part_imp(MACRO_PROT_ARGS
);
45 static int ctx_synopsis(MACRO_PROT_ARGS
);
46 static int in_line_eoln(MACRO_PROT_ARGS
);
47 static int in_line_argn(MACRO_PROT_ARGS
);
48 static int in_line(MACRO_PROT_ARGS
);
49 static int obsolete(MACRO_PROT_ARGS
);
50 static int phrase_ta(MACRO_PROT_ARGS
);
52 static int append_delims(struct mdoc
*,
54 static enum mdoct
lookup(enum mdoct
, const char *);
55 static enum mdoct
lookup_raw(const char *);
56 static int make_pending(struct mdoc_node
*, enum mdoct
,
57 struct mdoc
*, int, int);
58 static int phrase(struct mdoc
*, int, int, char *);
59 static enum mdoct
rew_alt(enum mdoct
);
60 static enum rew
rew_dohalt(enum mdoct
, enum mdoc_type
,
61 const struct mdoc_node
*);
62 static int rew_elem(struct mdoc
*, enum mdoct
);
63 static int rew_last(struct mdoc
*,
64 const struct mdoc_node
*);
65 static int rew_sub(enum mdoc_type
, struct mdoc
*,
66 enum mdoct
, int, int);
68 const struct mdoc_macro __mdoc_macros
[MDOC_MAX
] = {
69 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ap */
70 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
71 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
72 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
73 { blk_full
, 0 }, /* Sh */
74 { blk_full
, 0 }, /* Ss */
75 { in_line_eoln
, 0 }, /* Pp */
76 { blk_part_imp
, MDOC_PARSED
}, /* D1 */
77 { blk_part_imp
, MDOC_PARSED
}, /* Dl */
78 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
79 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ed */
80 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
81 { blk_exp_close
, MDOC_EXPLICIT
}, /* El */
82 { blk_full
, MDOC_PARSED
}, /* It */
83 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
84 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* An */
85 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
86 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cd */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
89 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
90 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
91 { in_line_eoln
, 0 }, /* Ex */
92 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
93 { in_line_eoln
, 0 }, /* Fd */
94 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
95 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
96 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
97 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ic */
98 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
99 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Li */
100 { blk_full
, 0 }, /* Nd */
101 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
102 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
103 { obsolete
, 0 }, /* Ot */
104 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
105 { in_line_eoln
, 0 }, /* Rv */
106 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
107 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
108 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
109 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
110 { in_line_eoln
, 0 }, /* %A */
111 { in_line_eoln
, 0 }, /* %B */
112 { in_line_eoln
, 0 }, /* %D */
113 { in_line_eoln
, 0 }, /* %I */
114 { in_line_eoln
, 0 }, /* %J */
115 { in_line_eoln
, 0 }, /* %N */
116 { in_line_eoln
, 0 }, /* %O */
117 { in_line_eoln
, 0 }, /* %P */
118 { in_line_eoln
, 0 }, /* %R */
119 { in_line_eoln
, 0 }, /* %T */
120 { in_line_eoln
, 0 }, /* %V */
121 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Ac */
122 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ao */
123 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Aq */
124 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
125 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Bc */
126 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
127 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Bo */
128 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bq */
129 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
130 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
131 { in_line_eoln
, 0 }, /* Db */
132 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Dc */
133 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Do */
134 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dq */
135 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Ec */
136 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ef */
137 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Em */
138 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
139 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
140 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
141 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* No */
142 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Ns */
143 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
144 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
145 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Pc */
146 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
147 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Po */
148 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pq */
149 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Qc */
150 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ql */
151 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Qo */
152 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Qq */
153 { blk_exp_close
, MDOC_EXPLICIT
}, /* Re */
154 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
155 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Sc */
156 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* So */
157 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sq */
158 { in_line_eoln
, 0 }, /* Sm */
159 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sx */
160 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sy */
161 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
162 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ux */
163 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
164 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
165 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
166 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Fc */
167 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Oo */
168 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Oc */
169 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
170 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ek */
171 { in_line_eoln
, 0 }, /* Bt */
172 { in_line_eoln
, 0 }, /* Hf */
173 { obsolete
, 0 }, /* Fr */
174 { in_line_eoln
, 0 }, /* Ud */
175 { in_line
, 0 }, /* Lb */
176 { in_line_eoln
, 0 }, /* Lp */
177 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
178 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
179 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Brq */
180 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Bro */
181 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Brc */
182 { in_line_eoln
, 0 }, /* %C */
183 { obsolete
, 0 }, /* Es */
184 { obsolete
, 0 }, /* En */
185 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
186 { in_line_eoln
, 0 }, /* %Q */
187 { in_line_eoln
, 0 }, /* br */
188 { in_line_eoln
, 0 }, /* sp */
189 { in_line_eoln
, 0 }, /* %U */
190 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ta */
193 const struct mdoc_macro
* const mdoc_macros
= __mdoc_macros
;
197 * This is called at the end of parsing. It must traverse up the tree,
198 * closing out open [implicit] scopes. Obviously, open explicit scopes
202 mdoc_macroend(struct mdoc
*m
)
206 /* Scan for open explicit scopes. */
208 n
= MDOC_VALID
& m
->last
->flags
? m
->last
->parent
: m
->last
;
210 for ( ; n
; n
= n
->parent
)
211 if (MDOC_BLOCK
== n
->type
&&
212 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
)
213 mdoc_nmsg(m
, n
, MANDOCERR_SCOPEEXIT
);
215 /* Rewind to the first. */
217 return(rew_last(m
, m
->first
));
222 * Look up a macro from within a subsequent context.
225 lookup(enum mdoct from
, const char *p
)
227 /* FIXME: make -diag lists be un-PARSED. */
229 if ( ! (MDOC_PARSED
& mdoc_macros
[from
].flags
))
231 return(lookup_raw(p
));
236 * Lookup a macro following the initial line macro.
239 lookup_raw(const char *p
)
243 if (MDOC_MAX
== (res
= mdoc_hash_find(p
)))
245 if (MDOC_CALLABLE
& mdoc_macros
[res
].flags
)
252 rew_last(struct mdoc
*mdoc
, const struct mdoc_node
*to
)
256 mdoc
->next
= MDOC_NEXT_SIBLING
;
259 while (mdoc
->last
!= to
) {
260 if ( ! mdoc_valid_post(mdoc
))
262 if ( ! mdoc_action_post(mdoc
))
264 mdoc
->last
= mdoc
->last
->parent
;
268 if ( ! mdoc_valid_post(mdoc
))
270 return(mdoc_action_post(mdoc
));
275 * For a block closing macro, return the corresponding opening one.
276 * Otherwise, return the macro itself.
279 rew_alt(enum mdoct tok
)
322 * Rewinding to tok, how do we have to handle *p?
323 * REWIND_NONE: *p would delimit tok, but no tok scope is open
324 * inside *p, so there is no need to rewind anything at all.
325 * REWIND_THIS: *p matches tok, so rewind *p and nothing else.
326 * REWIND_MORE: *p is implicit, rewind it and keep searching for tok.
327 * REWIND_LATER: *p is explicit and still open, postpone rewinding.
328 * REWIND_ERROR: No tok block is open at all.
331 rew_dohalt(enum mdoct tok
, enum mdoc_type type
,
332 const struct mdoc_node
*p
)
336 * No matching token, no delimiting block, no broken block.
337 * This can happen when full implicit macros are called for
338 * the first time but try to rewind their previous
341 if (MDOC_ROOT
== p
->type
)
342 return(MDOC_BLOCK
== type
&&
343 MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
?
344 REWIND_ERROR
: REWIND_NONE
);
347 * When starting to rewind, skip plain text
348 * and nodes that have already been rewound.
350 if (MDOC_TEXT
== p
->type
|| MDOC_VALID
& p
->flags
)
354 * The easiest case: Found a matching token.
355 * This applies to both blocks and elements.
359 return(p
->end
? REWIND_NONE
:
360 type
== p
->type
? REWIND_THIS
: REWIND_MORE
);
363 * While elements do require rewinding for themselves,
364 * they never affect rewinding of other nodes.
366 if (MDOC_ELEM
== p
->type
)
370 * Blocks delimited by our target token get REWIND_MORE.
371 * Blocks delimiting our target token get REWIND_NONE.
375 if (MDOC_It
== p
->tok
)
379 if (MDOC_BODY
== p
->type
&& MDOC_Bl
== p
->tok
)
383 * XXX Badly nested block handling still fails badly
384 * when one block is breaking two blocks of the same type.
385 * This is an incomplete and extremely ugly workaround,
386 * required to let the OpenBSD tree build.
389 if (MDOC_Op
== p
->tok
)
397 if (MDOC_BODY
== p
->type
&& MDOC_Sh
== p
->tok
)
401 if (MDOC_Nd
== p
->tok
|| MDOC_Ss
== p
->tok
||
410 * Default block rewinding rules.
411 * In particular, always skip block end markers,
412 * and let all blocks rewind Nm children.
414 if (ENDBODY_NOT
!= p
->end
|| MDOC_Nm
== p
->tok
||
415 (MDOC_BLOCK
== p
->type
&&
416 ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)))
420 * Partial blocks allow delayed rewinding by default.
422 if (&blk_full
!= mdoc_macros
[tok
].fp
)
423 return (REWIND_LATER
);
426 * Full blocks can only be rewound when matching
427 * or when there is an explicit rule.
429 return(REWIND_ERROR
);
434 rew_elem(struct mdoc
*mdoc
, enum mdoct tok
)
439 if (MDOC_ELEM
!= n
->type
)
441 assert(MDOC_ELEM
== n
->type
);
442 assert(tok
== n
->tok
);
444 return(rew_last(mdoc
, n
));
449 * We are trying to close a block identified by tok,
450 * but the child block *broken is still open.
451 * Thus, postpone closing the tok block
452 * until the rew_sub call closing *broken.
455 make_pending(struct mdoc_node
*broken
, enum mdoct tok
,
456 struct mdoc
*m
, int line
, int ppos
)
458 struct mdoc_node
*breaker
;
461 * Iterate backwards, searching for the block matching tok,
462 * that is, the block breaking the *broken block.
464 for (breaker
= broken
->parent
; breaker
; breaker
= breaker
->parent
) {
467 * If the *broken block had already been broken before
468 * and we encounter its breaker, make the tok block
469 * pending on the inner breaker.
470 * Graphically, "[A breaker=[B broken=[C->B B] tok=A] C]"
471 * becomes "[A broken=[B [C->B B] tok=A] C]"
472 * and finally "[A [B->A [C->B B] A] C]".
474 if (breaker
== broken
->pending
) {
479 if (REWIND_THIS
!= rew_dohalt(tok
, MDOC_BLOCK
, breaker
))
481 if (MDOC_BODY
== broken
->type
)
482 broken
= broken
->parent
;
486 * If another, outer breaker is already pending on
487 * the *broken block, we must not clobber the link
488 * to the outer breaker, but make it pending on the
489 * new, now inner breaker.
490 * Graphically, "[A breaker=[B broken=[C->A A] tok=B] C]"
491 * becomes "[A breaker=[B->A broken=[C A] tok=B] C]"
492 * and finally "[A [B->A [C->B A] B] C]".
494 if (broken
->pending
) {
495 struct mdoc_node
*taker
;
498 * If the breaker had also been broken before,
499 * it cannot take on the outer breaker itself,
500 * but must hand it on to its own breakers.
501 * Graphically, this is the following situation:
502 * "[A [B breaker=[C->B B] broken=[D->A A] tok=C] D]"
503 * "[A taker=[B->A breaker=[C->B B] [D->C A] C] D]"
506 while (taker
->pending
)
507 taker
= taker
->pending
;
508 taker
->pending
= broken
->pending
;
510 broken
->pending
= breaker
;
511 mdoc_vmsg(m
, MANDOCERR_SCOPENEST
, line
, ppos
,
512 "%s breaks %s", mdoc_macronames
[tok
],
513 mdoc_macronames
[broken
->tok
]);
518 * Found no matching block for tok.
519 * Are you trying to close a block that is not open?
520 * XXX Make this non-fatal.
522 mdoc_pmsg(m
, line
, ppos
, MANDOCERR_SYNTNOSCOPE
);
528 rew_sub(enum mdoc_type t
, struct mdoc
*m
,
529 enum mdoct tok
, int line
, int ppos
)
535 switch (rew_dohalt(tok
, t
, n
)) {
544 return(make_pending(n
, tok
, m
, line
, ppos
));
546 /* XXX Make this non-fatal. */
547 mdoc_vmsg(m
, MANDOCERR_SCOPEFATAL
, line
, ppos
,
548 "%s cannot break %s", mdoc_macronames
[tok
],
549 mdoc_macronames
[n
->tok
]);
556 if ( ! rew_last(m
, n
))
560 * The current block extends an enclosing block.
561 * Now that the current block ends, close the enclosing block, too.
563 while (NULL
!= (n
= n
->pending
)) {
564 if ( ! rew_last(m
, n
))
566 if (MDOC_HEAD
== n
->type
&&
567 ! mdoc_body_alloc(m
, n
->line
, n
->pos
, n
->tok
))
576 append_delims(struct mdoc
*m
, int line
, int *pos
, char *buf
)
582 if ('\0' == buf
[*pos
])
587 ac
= mdoc_zargs(m
, line
, pos
, buf
, ARGS_NOWARN
, &p
);
589 if (ARGS_ERROR
== ac
)
591 else if (ARGS_EOLN
== ac
)
594 assert(DELIM_NONE
!= mdoc_isdelim(p
));
595 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
599 * If we encounter end-of-sentence symbols, then trigger
602 * XXX: it's easy to allow this to propogate outward to
603 * the last symbol, such that `. )' will cause the
604 * correct double-spacing. However, (1) groff isn't
605 * smart enough to do this and (2) it would require
606 * knowing which symbols break this behaviour, for
607 * example, `. ;' shouldn't propogate the double-space.
609 if (mandoc_eos(p
, strlen(p
), 0))
610 m
->last
->flags
|= MDOC_EOS
;
618 * Close out block partial/full explicit.
621 blk_exp_close(MACRO_PROT_ARGS
)
623 struct mdoc_node
*body
; /* Our own body. */
624 struct mdoc_node
*later
; /* A sub-block starting later. */
625 struct mdoc_node
*n
; /* For searching backwards. */
627 int j
, lastarg
, maxargs
, flushed
, nl
;
629 enum mdoct atok
, ntok
;
632 nl
= MDOC_NEWLINE
& m
->flags
;
644 * Search backwards for beginnings of blocks,
645 * both of our own and of pending sub-blocks.
649 for (n
= m
->last
; n
; n
= n
->parent
) {
650 if (MDOC_VALID
& n
->flags
)
653 /* Remember the start of our own body. */
654 if (MDOC_BODY
== n
->type
&& atok
== n
->tok
) {
655 if (ENDBODY_NOT
== n
->end
)
660 if (MDOC_BLOCK
!= n
->type
|| MDOC_Nm
== n
->tok
)
662 if (atok
== n
->tok
) {
666 * Found the start of our own block.
667 * When there is no pending sub block,
668 * just proceed to closing out.
674 * When there is a pending sub block,
675 * postpone closing out the current block
676 * until the rew_sub() closing out the sub-block.
678 if ( ! make_pending(later
, tok
, m
, line
, ppos
))
682 * Mark the place where the formatting - but not
683 * the scope - of the current block ends.
685 if ( ! mdoc_endbody_alloc(m
, line
, ppos
,
686 atok
, body
, ENDBODY_SPACE
))
692 * When finding an open sub block, remember the last
693 * open explicit block, or, in case there are only
694 * implicit ones, the first open implicit block.
697 MDOC_EXPLICIT
& mdoc_macros
[later
->tok
].flags
)
699 if (MDOC_CALLABLE
& mdoc_macros
[n
->tok
].flags
) {
700 assert( ! (MDOC_ACTED
& n
->flags
));
705 if ( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
)) {
706 /* FIXME: do this in validate */
708 if ( ! mdoc_pmsg(m
, line
, ppos
, MANDOCERR_ARGSLOST
))
711 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
713 return(rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
));
716 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
719 if (NULL
== later
&& maxargs
> 0)
720 if ( ! mdoc_tail_alloc(m
, line
, ppos
, rew_alt(tok
)))
723 for (flushed
= j
= 0; ; j
++) {
726 if (j
== maxargs
&& ! flushed
) {
727 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
732 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
734 if (ARGS_ERROR
== ac
)
736 if (ARGS_PUNCT
== ac
)
741 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
743 if (MDOC_MAX
== ntok
) {
744 if ( ! mdoc_word_alloc(m
, line
, lastarg
, p
))
750 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
754 if ( ! mdoc_macro(m
, ntok
, line
, lastarg
, pos
, buf
))
759 if ( ! flushed
&& ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
764 return(append_delims(m
, line
, pos
, buf
));
769 in_line(MACRO_PROT_ARGS
)
771 int la
, scope
, cnt
, nc
, nl
;
776 struct mdoc_arg
*arg
;
779 nl
= MDOC_NEWLINE
& m
->flags
;
782 * Whether we allow ignored elements (those without content,
783 * usually because of reserved words) to squeak by.
805 for (arg
= NULL
;; ) {
807 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
809 if (ARGV_WORD
== av
) {
822 for (cnt
= scope
= 0;; ) {
824 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
826 if (ARGS_ERROR
== ac
)
830 if (ARGS_PUNCT
== ac
)
833 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
836 * In this case, we've located a submacro and must
837 * execute it. Close out scope, if open. If no
838 * elements have been generated, either create one (nc)
839 * or raise a warning.
842 if (MDOC_MAX
!= ntok
) {
843 if (scope
&& ! rew_elem(m
, tok
))
845 if (nc
&& 0 == cnt
) {
846 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
848 if ( ! rew_last(m
, m
->last
))
850 } else if ( ! nc
&& 0 == cnt
) {
852 if ( ! mdoc_pmsg(m
, line
, ppos
, MANDOCERR_MACROEMPTY
))
855 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
859 return(append_delims(m
, line
, pos
, buf
));
863 * Non-quote-enclosed punctuation. Set up our scope, if
864 * a word; rewind the scope, if a delimiter; then append
868 d
= ARGS_QWORD
== ac
? DELIM_NONE
: mdoc_isdelim(p
);
870 if (DELIM_NONE
!= d
) {
872 * If we encounter closing punctuation, no word
873 * has been omitted, no scope is open, and we're
874 * allowed to have an empty element, then start
875 * a new scope. `Ar', `Fl', and `Li', only do
876 * this once per invocation. There may be more
877 * of these (all of them?).
879 if (0 == cnt
&& (nc
|| MDOC_Li
== tok
) &&
880 DELIM_CLOSE
== d
&& ! scope
) {
881 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
883 if (MDOC_Ar
== tok
|| MDOC_Li
== tok
||
889 * Close out our scope, if one is open, before
892 if (scope
&& ! rew_elem(m
, tok
))
895 } else if ( ! scope
) {
896 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
903 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
907 * `Fl' macros have their scope re-opened with each new
908 * word so that the `-' can be added to each one without
909 * having to parse out spaces.
911 if (scope
&& MDOC_Fl
== tok
) {
912 if ( ! rew_elem(m
, tok
))
918 if (scope
&& ! rew_elem(m
, tok
))
922 * If no elements have been collected and we're allowed to have
923 * empties (nc), open a scope and close it out. Otherwise,
927 if (nc
&& 0 == cnt
) {
928 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
930 if ( ! rew_last(m
, m
->last
))
932 } else if ( ! nc
&& 0 == cnt
) {
934 if ( ! mdoc_pmsg(m
, line
, ppos
, MANDOCERR_MACROEMPTY
))
940 return(append_delims(m
, line
, pos
, buf
));
945 blk_full(MACRO_PROT_ARGS
)
948 struct mdoc_arg
*arg
;
949 struct mdoc_node
*head
; /* save of head macro */
950 struct mdoc_node
*body
; /* save of body macro */
954 enum margserr ac
, lac
;
958 nl
= MDOC_NEWLINE
& m
->flags
;
960 /* Close out prior implicit scope. */
962 if ( ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)) {
963 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
965 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
970 * This routine accomodates implicitly- and explicitly-scoped
971 * macro openings. Implicit ones first close out prior scope
972 * (seen above). Delay opening the head until necessary to
973 * allow leading punctuation to print. Special consideration
974 * for `It -column', which has phrase-part syntax instead of
975 * regular child nodes.
978 for (arg
= NULL
;; ) {
980 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
982 if (ARGV_WORD
== av
) {
996 if ( ! mdoc_block_alloc(m
, line
, ppos
, tok
, arg
))
1002 * The `Nd' macro has all arguments in its body: it's a hybrid
1003 * of block partial-explicit and full-implicit. Stupid.
1006 if (MDOC_Nd
== tok
) {
1007 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1010 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1012 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1021 /* Initialise last-phrase-type with ARGS_PEND. */
1022 lac
= ARGS_ERROR
== ac
? ARGS_PEND
: ac
;
1023 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1025 if (ARGS_PUNCT
== ac
)
1028 if (ARGS_ERROR
== ac
)
1031 if (ARGS_EOLN
== ac
) {
1032 if (ARGS_PPHRASE
!= lac
&& ARGS_PHRASE
!= lac
)
1035 * This is necessary: if the last token on a
1036 * line is a `Ta' or tab, then we'll get
1037 * ARGS_EOLN, so we must be smart enough to
1038 * reopen our scope if the last parse was a
1039 * phrase or partial phrase.
1041 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
1043 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1050 * Emit leading punctuation (i.e., punctuation before
1051 * the MDOC_HEAD) for non-phrase types.
1056 ARGS_PHRASE
!= ac
&&
1057 ARGS_PPHRASE
!= ac
&&
1059 DELIM_OPEN
== mdoc_isdelim(p
)) {
1060 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1065 /* Open a head if one hasn't been opened. */
1068 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1073 if (ARGS_PHRASE
== ac
||
1075 ARGS_PPHRASE
== ac
) {
1077 * If we haven't opened a body yet, rewind the
1078 * head; if we have, rewind that instead.
1081 mtt
= body
? MDOC_BODY
: MDOC_HEAD
;
1082 if ( ! rew_sub(mtt
, m
, tok
, line
, ppos
))
1085 /* Then allocate our body context. */
1087 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1092 * Process phrases: set whether we're in a
1093 * partial-phrase (this effects line handling)
1094 * then call down into the phrase parser.
1097 if (ARGS_PPHRASE
== ac
)
1098 m
->flags
|= MDOC_PPHRASE
;
1099 if (ARGS_PEND
== ac
&& ARGS_PPHRASE
== lac
)
1100 m
->flags
|= MDOC_PPHRASE
;
1102 if ( ! phrase(m
, line
, la
, buf
))
1105 m
->flags
&= ~MDOC_PPHRASE
;
1109 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1111 if (MDOC_MAX
== ntok
) {
1112 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1117 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1123 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1128 if (nl
&& ! append_delims(m
, line
, pos
, buf
))
1131 /* If we've already opened our body, exit now. */
1137 * If there is an open (i.e., unvalidated) sub-block requiring
1138 * explicit close-out, postpone switching the current block from
1139 * head to body until the rew_sub() call closing out that
1142 for (n
= m
->last
; n
&& n
!= head
; n
= n
->parent
) {
1143 if (MDOC_BLOCK
== n
->type
&&
1144 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
&&
1145 ! (MDOC_VALID
& n
->flags
)) {
1146 assert( ! (MDOC_ACTED
& n
->flags
));
1152 /* Close out scopes to remain in a consistent state. */
1154 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1156 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1160 if ( ! (MDOC_FREECOL
& m
->flags
))
1163 if ( ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
1165 if ( ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
1168 m
->flags
&= ~MDOC_FREECOL
;
1174 blk_part_imp(MACRO_PROT_ARGS
)
1180 struct mdoc_node
*blk
; /* saved block context */
1181 struct mdoc_node
*body
; /* saved body context */
1182 struct mdoc_node
*n
;
1184 nl
= MDOC_NEWLINE
& m
->flags
;
1187 * A macro that spans to the end of the line. This is generally
1188 * (but not necessarily) called as the first macro. The block
1189 * has a head as the immediate child, which is always empty,
1190 * followed by zero or more opening punctuation nodes, then the
1191 * body (which may be empty, depending on the macro), then zero
1192 * or more closing punctuation nodes.
1195 if ( ! mdoc_block_alloc(m
, line
, ppos
, tok
, NULL
))
1200 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1202 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1206 * Open the body scope "on-demand", that is, after we've
1207 * processed all our the leading delimiters (open parenthesis,
1211 for (body
= NULL
; ; ) {
1213 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1215 if (ARGS_ERROR
== ac
)
1217 if (ARGS_EOLN
== ac
)
1219 if (ARGS_PUNCT
== ac
)
1222 if (NULL
== body
&& ARGS_QWORD
!= ac
&&
1223 DELIM_OPEN
== mdoc_isdelim(p
)) {
1224 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1230 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1235 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1237 if (MDOC_MAX
== ntok
) {
1238 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1243 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1248 /* Clean-ups to leave in a consistent state. */
1251 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1256 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1260 * End of sentence spacing: if the last node is a text node and
1261 * has a trailing period, then mark it as being end-of-sentence.
1264 if (n
&& MDOC_TEXT
== n
->type
&& n
->string
)
1265 if (mandoc_eos(n
->string
, strlen(n
->string
), 1))
1266 n
->flags
|= MDOC_EOS
;
1268 /* Up-propogate the end-of-space flag. */
1270 if (n
&& (MDOC_EOS
& n
->flags
)) {
1271 body
->flags
|= MDOC_EOS
;
1272 body
->parent
->flags
|= MDOC_EOS
;
1276 * If there is an open sub-block requiring explicit close-out,
1277 * postpone closing out the current block
1278 * until the rew_sub() call closing out the sub-block.
1280 for (n
= m
->last
; n
&& n
!= body
&& n
!= blk
->parent
; n
= n
->parent
) {
1281 if (MDOC_BLOCK
== n
->type
&&
1282 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
&&
1283 ! (MDOC_VALID
& n
->flags
)) {
1284 assert( ! (MDOC_ACTED
& n
->flags
));
1285 if ( ! make_pending(n
, tok
, m
, line
, ppos
))
1287 if ( ! mdoc_endbody_alloc(m
, line
, ppos
,
1288 tok
, body
, ENDBODY_NOSPACE
))
1295 * If we can't rewind to our body, then our scope has already
1296 * been closed by another macro (like `Oc' closing `Op'). This
1297 * is ugly behaviour nodding its head to OpenBSD's overwhelming
1298 * crufty use of `Op' breakage.
1300 if (n
!= body
&& ! mdoc_vmsg(m
, MANDOCERR_SCOPENEST
,
1301 line
, ppos
, "%s broken", mdoc_macronames
[tok
]))
1304 if (n
&& ! rew_sub(MDOC_BODY
, m
, tok
, line
, ppos
))
1307 /* Standard appending of delimiters. */
1309 if (nl
&& ! append_delims(m
, line
, pos
, buf
))
1312 /* Rewind scope, if applicable. */
1314 if (n
&& ! rew_sub(MDOC_BLOCK
, m
, tok
, line
, ppos
))
1322 blk_part_exp(MACRO_PROT_ARGS
)
1326 struct mdoc_node
*head
; /* keep track of head */
1327 struct mdoc_node
*body
; /* keep track of body */
1331 nl
= MDOC_NEWLINE
& m
->flags
;
1334 * The opening of an explicit macro having zero or more leading
1335 * punctuation nodes; a head with optional single element (the
1336 * case of `Eo'); and a body that may be empty.
1339 if ( ! mdoc_block_alloc(m
, line
, ppos
, tok
, NULL
))
1342 for (head
= body
= NULL
; ; ) {
1344 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1346 if (ARGS_ERROR
== ac
)
1348 if (ARGS_PUNCT
== ac
)
1350 if (ARGS_EOLN
== ac
)
1353 /* Flush out leading punctuation. */
1355 if (NULL
== head
&& ARGS_QWORD
!= ac
&&
1356 DELIM_OPEN
== mdoc_isdelim(p
)) {
1357 assert(NULL
== body
);
1358 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1364 assert(NULL
== body
);
1365 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1371 * `Eo' gobbles any data into the head, but most other
1372 * macros just immediately close out and begin the body.
1377 /* No check whether it's a macro! */
1379 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1382 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1384 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1392 assert(NULL
!= head
&& NULL
!= body
);
1394 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1396 if (MDOC_MAX
== ntok
) {
1397 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1402 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1407 /* Clean-up to leave in a consistent state. */
1410 if ( ! mdoc_head_alloc(m
, line
, ppos
, tok
))
1416 if ( ! rew_sub(MDOC_HEAD
, m
, tok
, line
, ppos
))
1418 if ( ! mdoc_body_alloc(m
, line
, ppos
, tok
))
1423 /* Standard appending of delimiters. */
1427 return(append_delims(m
, line
, pos
, buf
));
1433 in_line_argn(MACRO_PROT_ARGS
)
1435 int la
, flushed
, j
, maxargs
, nl
;
1438 struct mdoc_arg
*arg
;
1442 nl
= MDOC_NEWLINE
& m
->flags
;
1445 * A line macro that has a fixed number of arguments (maxargs).
1446 * Only open the scope once the first non-leading-punctuation is
1447 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1448 * keep it open until the maximum number of arguments are
1470 for (arg
= NULL
; ; ) {
1472 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
1474 if (ARGV_WORD
== av
) {
1479 if (ARGV_EOLN
== av
)
1484 mdoc_argv_free(arg
);
1488 for (flushed
= j
= 0; ; ) {
1490 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1492 if (ARGS_ERROR
== ac
)
1494 if (ARGS_PUNCT
== ac
)
1496 if (ARGS_EOLN
== ac
)
1499 if ( ! (MDOC_IGNDELIM
& mdoc_macros
[tok
].flags
) &&
1501 0 == j
&& DELIM_OPEN
== mdoc_isdelim(p
)) {
1502 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1506 if ( ! mdoc_elem_alloc(m
, line
, la
, tok
, arg
))
1509 if (j
== maxargs
&& ! flushed
) {
1510 if ( ! rew_elem(m
, tok
))
1515 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1517 if (MDOC_MAX
!= ntok
) {
1518 if ( ! flushed
&& ! rew_elem(m
, tok
))
1521 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1527 if ( ! (MDOC_IGNDELIM
& mdoc_macros
[tok
].flags
) &&
1530 DELIM_NONE
!= mdoc_isdelim(p
)) {
1531 if ( ! rew_elem(m
, tok
))
1537 * XXX: this is a hack to work around groff's ugliness
1538 * as regards `Xr' and extraneous arguments. It should
1539 * ideally be deprecated behaviour, but because this is
1540 * code is no here, it's unlikely to be removed.
1544 if (MDOC_Xr
== tok
&& j
== maxargs
) {
1545 if ( ! mdoc_elem_alloc(m
, line
, la
, MDOC_Ns
, NULL
))
1547 if ( ! rew_elem(m
, MDOC_Ns
))
1552 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1557 if (0 == j
&& ! mdoc_elem_alloc(m
, line
, la
, tok
, arg
))
1560 /* Close out in a consistent state. */
1562 if ( ! flushed
&& ! rew_elem(m
, tok
))
1566 return(append_delims(m
, line
, pos
, buf
));
1571 in_line_eoln(MACRO_PROT_ARGS
)
1576 struct mdoc_arg
*arg
;
1580 assert( ! (MDOC_PARSED
& mdoc_macros
[tok
].flags
));
1583 rew_sub(MDOC_BLOCK
, m
, MDOC_Nm
, line
, ppos
);
1585 /* Parse macro arguments. */
1587 for (arg
= NULL
; ; ) {
1589 av
= mdoc_argv(m
, line
, tok
, &arg
, pos
, buf
);
1591 if (ARGV_WORD
== av
) {
1595 if (ARGV_EOLN
== av
)
1600 mdoc_argv_free(arg
);
1604 /* Open element scope. */
1606 if ( ! mdoc_elem_alloc(m
, line
, ppos
, tok
, arg
))
1609 /* Parse argument terms. */
1613 ac
= mdoc_args(m
, line
, pos
, buf
, tok
, &p
);
1615 if (ARGS_ERROR
== ac
)
1617 if (ARGS_EOLN
== ac
)
1620 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1622 if (MDOC_MAX
== ntok
) {
1623 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1628 if ( ! rew_elem(m
, tok
))
1630 return(mdoc_macro(m
, ntok
, line
, la
, pos
, buf
));
1633 /* Close out (no delimiters). */
1635 return(rew_elem(m
, tok
));
1641 ctx_synopsis(MACRO_PROT_ARGS
)
1645 nl
= MDOC_NEWLINE
& m
->flags
;
1647 /* If we're not in the SYNOPSIS, go straight to in-line. */
1648 if ( ! (MDOC_SYNOPSIS
& m
->flags
))
1649 return(in_line(m
, tok
, line
, ppos
, pos
, buf
));
1651 /* If we're a nested call, same place. */
1653 return(in_line(m
, tok
, line
, ppos
, pos
, buf
));
1656 * XXX: this will open a block scope; however, if later we end
1657 * up formatting the block scope, then child nodes will inherit
1658 * the formatting. Be careful.
1661 return(blk_full(m
, tok
, line
, ppos
, pos
, buf
));
1662 assert(MDOC_Vt
== tok
);
1663 return(blk_part_imp(m
, tok
, line
, ppos
, pos
, buf
));
1669 obsolete(MACRO_PROT_ARGS
)
1672 return(mdoc_pmsg(m
, line
, ppos
, MANDOCERR_MACROOBS
));
1677 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1678 * They're unusual because they're basically free-form text until a
1679 * macro is encountered.
1682 phrase(struct mdoc
*m
, int line
, int ppos
, char *buf
)
1689 for (pos
= ppos
; ; ) {
1692 ac
= mdoc_zargs(m
, line
, &pos
, buf
, 0, &p
);
1694 if (ARGS_ERROR
== ac
)
1696 if (ARGS_EOLN
== ac
)
1699 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup_raw(p
);
1701 if (MDOC_MAX
== ntok
) {
1702 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1707 if ( ! mdoc_macro(m
, ntok
, line
, la
, &pos
, buf
))
1709 return(append_delims(m
, line
, &pos
, buf
));
1718 phrase_ta(MACRO_PROT_ARGS
)
1726 * FIXME: this is overly restrictive: if the `Ta' is unexpected,
1727 * it should simply error out with ARGSLOST.
1730 if ( ! rew_sub(MDOC_BODY
, m
, MDOC_It
, line
, ppos
))
1732 if ( ! mdoc_body_alloc(m
, line
, ppos
, MDOC_It
))
1737 ac
= mdoc_zargs(m
, line
, pos
, buf
, 0, &p
);
1739 if (ARGS_ERROR
== ac
)
1741 if (ARGS_EOLN
== ac
)
1744 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup_raw(p
);
1746 if (MDOC_MAX
== ntok
) {
1747 if ( ! mdoc_word_alloc(m
, line
, la
, p
))
1752 if ( ! mdoc_macro(m
, ntok
, line
, la
, pos
, buf
))
1754 return(append_delims(m
, line
, pos
, buf
));