]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_macro.c
1 /* $Id: mdoc_macro.c,v 1.120 2012/11/18 00:05:35 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012 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.
32 #include "libmandoc.h"
34 enum rew
{ /* see rew_dohalt() */
43 static int blk_full(MACRO_PROT_ARGS
);
44 static int blk_exp_close(MACRO_PROT_ARGS
);
45 static int blk_part_exp(MACRO_PROT_ARGS
);
46 static int blk_part_imp(MACRO_PROT_ARGS
);
47 static int ctx_synopsis(MACRO_PROT_ARGS
);
48 static int in_line_eoln(MACRO_PROT_ARGS
);
49 static int in_line_argn(MACRO_PROT_ARGS
);
50 static int in_line(MACRO_PROT_ARGS
);
51 static int obsolete(MACRO_PROT_ARGS
);
52 static int phrase_ta(MACRO_PROT_ARGS
);
54 static int dword(struct mdoc
*, int, int,
55 const char *, enum mdelim
);
56 static int append_delims(struct mdoc
*,
58 static enum mdoct
lookup(enum mdoct
, const char *);
59 static enum mdoct
lookup_raw(const char *);
60 static int make_pending(struct mdoc_node
*, enum mdoct
,
61 struct mdoc
*, int, int);
62 static int phrase(struct mdoc
*, int, int, char *);
63 static enum mdoct
rew_alt(enum mdoct
);
64 static enum rew
rew_dohalt(enum mdoct
, enum mdoc_type
,
65 const struct mdoc_node
*);
66 static int rew_elem(struct mdoc
*, enum mdoct
);
67 static int rew_last(struct mdoc
*,
68 const struct mdoc_node
*);
69 static int rew_sub(enum mdoc_type
, struct mdoc
*,
70 enum mdoct
, int, int);
72 const struct mdoc_macro __mdoc_macros
[MDOC_MAX
] = {
73 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ap */
74 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dd */
75 { in_line_eoln
, MDOC_PROLOGUE
}, /* Dt */
76 { in_line_eoln
, MDOC_PROLOGUE
}, /* Os */
77 { blk_full
, MDOC_PARSED
}, /* Sh */
78 { blk_full
, MDOC_PARSED
}, /* Ss */
79 { in_line_eoln
, 0 }, /* Pp */
80 { blk_part_imp
, MDOC_PARSED
}, /* D1 */
81 { blk_part_imp
, MDOC_PARSED
}, /* Dl */
82 { blk_full
, MDOC_EXPLICIT
}, /* Bd */
83 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ed */
84 { blk_full
, MDOC_EXPLICIT
}, /* Bl */
85 { blk_exp_close
, MDOC_EXPLICIT
}, /* El */
86 { blk_full
, MDOC_PARSED
}, /* It */
87 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ad */
88 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* An */
89 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ar */
90 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cd */
91 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Cm */
92 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dv */
93 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Er */
94 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ev */
95 { in_line_eoln
, 0 }, /* Ex */
96 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fa */
97 { in_line_eoln
, 0 }, /* Fd */
98 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fl */
99 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fn */
100 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ft */
101 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ic */
102 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* In */
103 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Li */
104 { blk_full
, 0 }, /* Nd */
105 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nm */
106 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Op */
107 { obsolete
, 0 }, /* Ot */
108 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pa */
109 { in_line_eoln
, 0 }, /* Rv */
110 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* St */
111 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Va */
112 { ctx_synopsis
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Vt */
113 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Xr */
114 { in_line_eoln
, 0 }, /* %A */
115 { in_line_eoln
, 0 }, /* %B */
116 { in_line_eoln
, 0 }, /* %D */
117 { in_line_eoln
, 0 }, /* %I */
118 { in_line_eoln
, 0 }, /* %J */
119 { in_line_eoln
, 0 }, /* %N */
120 { in_line_eoln
, 0 }, /* %O */
121 { in_line_eoln
, 0 }, /* %P */
122 { in_line_eoln
, 0 }, /* %R */
123 { in_line_eoln
, 0 }, /* %T */
124 { in_line_eoln
, 0 }, /* %V */
125 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Ac */
126 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Ao */
127 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Aq */
128 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* At */
129 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Bc */
130 { blk_full
, MDOC_EXPLICIT
}, /* Bf */
131 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Bo */
132 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bq */
133 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bsx */
134 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Bx */
135 { in_line_eoln
, 0 }, /* Db */
136 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Dc */
137 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Do */
138 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dq */
139 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Ec */
140 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ef */
141 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Em */
142 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Eo */
143 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Fx */
144 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ms */
145 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* No */
146 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Ns */
147 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Nx */
148 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ox */
149 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Pc */
150 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_IGNDELIM
}, /* Pf */
151 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Po */
152 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Pq */
153 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Qc */
154 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ql */
155 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Qo */
156 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Qq */
157 { blk_exp_close
, MDOC_EXPLICIT
}, /* Re */
158 { blk_full
, MDOC_EXPLICIT
}, /* Rs */
159 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Sc */
160 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* So */
161 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sq */
162 { in_line_eoln
, 0 }, /* Sm */
163 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sx */
164 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Sy */
165 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Tn */
166 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ux */
167 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Xc */
168 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Xo */
169 { blk_full
, MDOC_EXPLICIT
| MDOC_CALLABLE
}, /* Fo */
170 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Fc */
171 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Oo */
172 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Oc */
173 { blk_full
, MDOC_EXPLICIT
}, /* Bk */
174 { blk_exp_close
, MDOC_EXPLICIT
}, /* Ek */
175 { in_line_eoln
, 0 }, /* Bt */
176 { in_line_eoln
, 0 }, /* Hf */
177 { obsolete
, 0 }, /* Fr */
178 { in_line_eoln
, 0 }, /* Ud */
179 { in_line
, 0 }, /* Lb */
180 { in_line_eoln
, 0 }, /* Lp */
181 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Lk */
182 { in_line
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Mt */
183 { blk_part_imp
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Brq */
184 { blk_part_exp
, MDOC_CALLABLE
| MDOC_PARSED
| MDOC_EXPLICIT
}, /* Bro */
185 { blk_exp_close
, MDOC_EXPLICIT
| MDOC_CALLABLE
| MDOC_PARSED
}, /* Brc */
186 { in_line_eoln
, 0 }, /* %C */
187 { obsolete
, 0 }, /* Es */
188 { obsolete
, 0 }, /* En */
189 { in_line_argn
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Dx */
190 { in_line_eoln
, 0 }, /* %Q */
191 { in_line_eoln
, 0 }, /* br */
192 { in_line_eoln
, 0 }, /* sp */
193 { in_line_eoln
, 0 }, /* %U */
194 { phrase_ta
, MDOC_CALLABLE
| MDOC_PARSED
}, /* Ta */
197 const struct mdoc_macro
* const mdoc_macros
= __mdoc_macros
;
201 * This is called at the end of parsing. It must traverse up the tree,
202 * closing out open [implicit] scopes. Obviously, open explicit scopes
206 mdoc_macroend(struct mdoc
*mdoc
)
210 /* Scan for open explicit scopes. */
212 n
= MDOC_VALID
& mdoc
->last
->flags
?
213 mdoc
->last
->parent
: mdoc
->last
;
215 for ( ; n
; n
= n
->parent
)
216 if (MDOC_BLOCK
== n
->type
&&
217 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
)
218 mdoc_nmsg(mdoc
, n
, MANDOCERR_SCOPEEXIT
);
220 /* Rewind to the first. */
222 return(rew_last(mdoc
, mdoc
->first
));
227 * Look up a macro from within a subsequent context.
230 lookup(enum mdoct from
, const char *p
)
233 if ( ! (MDOC_PARSED
& mdoc_macros
[from
].flags
))
235 return(lookup_raw(p
));
240 * Lookup a macro following the initial line macro.
243 lookup_raw(const char *p
)
247 if (MDOC_MAX
== (res
= mdoc_hash_find(p
)))
249 if (MDOC_CALLABLE
& mdoc_macros
[res
].flags
)
256 rew_last(struct mdoc
*mdoc
, const struct mdoc_node
*to
)
258 struct mdoc_node
*n
, *np
;
261 mdoc
->next
= MDOC_NEXT_SIBLING
;
264 while (mdoc
->last
!= to
) {
266 * Save the parent here, because we may delete the
267 * mdoc->last node in the post-validation phase and reset
268 * it to mdoc->last->parent, causing a step in the closing
271 np
= mdoc
->last
->parent
;
272 if ( ! mdoc_valid_post(mdoc
))
277 mdoc
->last
->last
= n
;
280 return(mdoc_valid_post(mdoc
));
285 * For a block closing macro, return the corresponding opening one.
286 * Otherwise, return the macro itself.
289 rew_alt(enum mdoct tok
)
332 * Rewinding to tok, how do we have to handle *p?
333 * REWIND_NONE: *p would delimit tok, but no tok scope is open
334 * inside *p, so there is no need to rewind anything at all.
335 * REWIND_THIS: *p matches tok, so rewind *p and nothing else.
336 * REWIND_MORE: *p is implicit, rewind it and keep searching for tok.
337 * REWIND_FORCE: *p is explicit, but tok is full, force rewinding *p.
338 * REWIND_LATER: *p is explicit and still open, postpone rewinding.
339 * REWIND_ERROR: No tok block is open at all.
342 rew_dohalt(enum mdoct tok
, enum mdoc_type type
,
343 const struct mdoc_node
*p
)
347 * No matching token, no delimiting block, no broken block.
348 * This can happen when full implicit macros are called for
349 * the first time but try to rewind their previous
352 if (MDOC_ROOT
== p
->type
)
353 return(MDOC_BLOCK
== type
&&
354 MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
?
355 REWIND_ERROR
: REWIND_NONE
);
358 * When starting to rewind, skip plain text
359 * and nodes that have already been rewound.
361 if (MDOC_TEXT
== p
->type
|| MDOC_VALID
& p
->flags
)
365 * The easiest case: Found a matching token.
366 * This applies to both blocks and elements.
370 return(p
->end
? REWIND_NONE
:
371 type
== p
->type
? REWIND_THIS
: REWIND_MORE
);
374 * While elements do require rewinding for themselves,
375 * they never affect rewinding of other nodes.
377 if (MDOC_ELEM
== p
->type
)
381 * Blocks delimited by our target token get REWIND_MORE.
382 * Blocks delimiting our target token get REWIND_NONE.
386 if (MDOC_It
== p
->tok
)
390 if (MDOC_BODY
== p
->type
&& MDOC_Bl
== p
->tok
)
394 * XXX Badly nested block handling still fails badly
395 * when one block is breaking two blocks of the same type.
396 * This is an incomplete and extremely ugly workaround,
397 * required to let the OpenBSD tree build.
400 if (MDOC_Op
== p
->tok
)
408 if (MDOC_BODY
== p
->type
&& MDOC_Sh
== p
->tok
)
412 if (MDOC_Nd
== p
->tok
|| MDOC_Ss
== p
->tok
||
421 * Default block rewinding rules.
422 * In particular, always skip block end markers,
423 * and let all blocks rewind Nm children.
425 if (ENDBODY_NOT
!= p
->end
|| MDOC_Nm
== p
->tok
||
426 (MDOC_BLOCK
== p
->type
&&
427 ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)))
431 * By default, closing out full blocks
432 * forces closing of broken explicit blocks,
433 * while closing out partial blocks
434 * allows delayed rewinding by default.
436 return (&blk_full
== mdoc_macros
[tok
].fp
?
437 REWIND_FORCE
: REWIND_LATER
);
442 rew_elem(struct mdoc
*mdoc
, enum mdoct tok
)
447 if (MDOC_ELEM
!= n
->type
)
449 assert(MDOC_ELEM
== n
->type
);
450 assert(tok
== n
->tok
);
452 return(rew_last(mdoc
, n
));
457 * We are trying to close a block identified by tok,
458 * but the child block *broken is still open.
459 * Thus, postpone closing the tok block
460 * until the rew_sub call closing *broken.
463 make_pending(struct mdoc_node
*broken
, enum mdoct tok
,
464 struct mdoc
*mdoc
, int line
, int ppos
)
466 struct mdoc_node
*breaker
;
469 * Iterate backwards, searching for the block matching tok,
470 * that is, the block breaking the *broken block.
472 for (breaker
= broken
->parent
; breaker
; breaker
= breaker
->parent
) {
475 * If the *broken block had already been broken before
476 * and we encounter its breaker, make the tok block
477 * pending on the inner breaker.
478 * Graphically, "[A breaker=[B broken=[C->B B] tok=A] C]"
479 * becomes "[A broken=[B [C->B B] tok=A] C]"
480 * and finally "[A [B->A [C->B B] A] C]".
482 if (breaker
== broken
->pending
) {
487 if (REWIND_THIS
!= rew_dohalt(tok
, MDOC_BLOCK
, breaker
))
489 if (MDOC_BODY
== broken
->type
)
490 broken
= broken
->parent
;
494 * If another, outer breaker is already pending on
495 * the *broken block, we must not clobber the link
496 * to the outer breaker, but make it pending on the
497 * new, now inner breaker.
498 * Graphically, "[A breaker=[B broken=[C->A A] tok=B] C]"
499 * becomes "[A breaker=[B->A broken=[C A] tok=B] C]"
500 * and finally "[A [B->A [C->B A] B] C]".
502 if (broken
->pending
) {
503 struct mdoc_node
*taker
;
506 * If the breaker had also been broken before,
507 * it cannot take on the outer breaker itself,
508 * but must hand it on to its own breakers.
509 * Graphically, this is the following situation:
510 * "[A [B breaker=[C->B B] broken=[D->A A] tok=C] D]"
511 * "[A taker=[B->A breaker=[C->B B] [D->C A] C] D]"
514 while (taker
->pending
)
515 taker
= taker
->pending
;
516 taker
->pending
= broken
->pending
;
518 broken
->pending
= breaker
;
519 mandoc_vmsg(MANDOCERR_SCOPENEST
, mdoc
->parse
, line
, ppos
,
520 "%s breaks %s", mdoc_macronames
[tok
],
521 mdoc_macronames
[broken
->tok
]);
526 * Found no matching block for tok.
527 * Are you trying to close a block that is not open?
534 rew_sub(enum mdoc_type t
, struct mdoc
*mdoc
,
535 enum mdoct tok
, int line
, int ppos
)
541 switch (rew_dohalt(tok
, t
, n
)) {
547 mandoc_vmsg(MANDOCERR_SCOPEBROKEN
, mdoc
->parse
,
548 line
, ppos
, "%s breaks %s",
549 mdoc_macronames
[tok
],
550 mdoc_macronames
[n
->tok
]);
556 if (make_pending(n
, tok
, mdoc
, line
, ppos
) ||
561 mdoc_pmsg(mdoc
, line
, ppos
, MANDOCERR_NOSCOPE
);
568 if ( ! rew_last(mdoc
, n
))
572 * The current block extends an enclosing block.
573 * Now that the current block ends, close the enclosing block, too.
575 while (NULL
!= (n
= n
->pending
)) {
576 if ( ! rew_last(mdoc
, n
))
578 if (MDOC_HEAD
== n
->type
&&
579 ! mdoc_body_alloc(mdoc
, n
->line
, n
->pos
, n
->tok
))
587 * Allocate a word and check whether it's punctuation or not.
588 * Punctuation consists of those tokens found in mdoc_isdelim().
591 dword(struct mdoc
*mdoc
, int line
,
592 int col
, const char *p
, enum mdelim d
)
598 if ( ! mdoc_word_alloc(mdoc
, line
, col
, p
))
602 mdoc
->last
->flags
|= MDOC_DELIMO
;
605 * Closing delimiters only suppress the preceding space
606 * when they follow something, not when they start a new
607 * block or element, and not when they follow `No'.
609 * XXX Explicitly special-casing MDOC_No here feels
610 * like a layering violation. Find a better way
611 * and solve this in the code related to `No'!
614 else if (DELIM_CLOSE
== d
&& mdoc
->last
->prev
&&
615 mdoc
->last
->prev
->tok
!= MDOC_No
&&
616 mdoc
->last
->parent
->tok
!= MDOC_Fd
)
617 mdoc
->last
->flags
|= MDOC_DELIMC
;
623 append_delims(struct mdoc
*mdoc
, int line
, int *pos
, char *buf
)
629 if ('\0' == buf
[*pos
])
634 ac
= mdoc_zargs(mdoc
, line
, pos
, buf
, &p
);
636 if (ARGS_ERROR
== ac
)
638 else if (ARGS_EOLN
== ac
)
641 dword(mdoc
, line
, la
, p
, DELIM_MAX
);
644 * If we encounter end-of-sentence symbols, then trigger
647 * XXX: it's easy to allow this to propagate outward to
648 * the last symbol, such that `. )' will cause the
649 * correct double-spacing. However, (1) groff isn't
650 * smart enough to do this and (2) it would require
651 * knowing which symbols break this behaviour, for
652 * example, `. ;' shouldn't propagate the double-space.
654 if (mandoc_eos(p
, strlen(p
), 0))
655 mdoc
->last
->flags
|= MDOC_EOS
;
663 * Close out block partial/full explicit.
666 blk_exp_close(MACRO_PROT_ARGS
)
668 struct mdoc_node
*body
; /* Our own body. */
669 struct mdoc_node
*later
; /* A sub-block starting later. */
670 struct mdoc_node
*n
; /* For searching backwards. */
672 int j
, lastarg
, maxargs
, flushed
, nl
;
674 enum mdoct atok
, ntok
;
677 nl
= MDOC_NEWLINE
& mdoc
->flags
;
689 * Search backwards for beginnings of blocks,
690 * both of our own and of pending sub-blocks.
694 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
695 if (MDOC_VALID
& n
->flags
)
698 /* Remember the start of our own body. */
699 if (MDOC_BODY
== n
->type
&& atok
== n
->tok
) {
700 if (ENDBODY_NOT
== n
->end
)
705 if (MDOC_BLOCK
!= n
->type
|| MDOC_Nm
== n
->tok
)
707 if (atok
== n
->tok
) {
711 * Found the start of our own block.
712 * When there is no pending sub block,
713 * just proceed to closing out.
719 * When there is a pending sub block,
720 * postpone closing out the current block
721 * until the rew_sub() closing out the sub-block.
723 make_pending(later
, tok
, mdoc
, line
, ppos
);
726 * Mark the place where the formatting - but not
727 * the scope - of the current block ends.
729 if ( ! mdoc_endbody_alloc(mdoc
, line
, ppos
,
730 atok
, body
, ENDBODY_SPACE
))
736 * When finding an open sub block, remember the last
737 * open explicit block, or, in case there are only
738 * implicit ones, the first open implicit block.
741 MDOC_EXPLICIT
& mdoc_macros
[later
->tok
].flags
)
743 if (MDOC_It
!= n
->tok
)
747 if ( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
)) {
748 /* FIXME: do this in validate */
750 mdoc_pmsg(mdoc
, line
, ppos
, MANDOCERR_ARGSLOST
);
752 if ( ! rew_sub(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
754 return(rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
));
757 if ( ! rew_sub(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
760 if (NULL
== later
&& maxargs
> 0)
761 if ( ! mdoc_tail_alloc(mdoc
, line
, ppos
, rew_alt(tok
)))
764 for (flushed
= j
= 0; ; j
++) {
767 if (j
== maxargs
&& ! flushed
) {
768 if ( ! rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
))
773 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
775 if (ARGS_ERROR
== ac
)
777 if (ARGS_PUNCT
== ac
)
782 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
784 if (MDOC_MAX
== ntok
) {
785 if ( ! dword(mdoc
, line
, lastarg
, p
, DELIM_MAX
))
791 if ( ! rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
))
795 if ( ! mdoc_macro(mdoc
, ntok
, line
, lastarg
, pos
, buf
))
800 if ( ! flushed
&& ! rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
))
805 return(append_delims(mdoc
, line
, pos
, buf
));
810 in_line(MACRO_PROT_ARGS
)
812 int la
, scope
, cnt
, nc
, nl
;
817 struct mdoc_arg
*arg
;
820 nl
= MDOC_NEWLINE
& mdoc
->flags
;
823 * Whether we allow ignored elements (those without content,
824 * usually because of reserved words) to squeak by.
846 for (arg
= NULL
;; ) {
848 av
= mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
850 if (ARGV_WORD
== av
) {
863 for (cnt
= scope
= 0;; ) {
865 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
867 if (ARGS_ERROR
== ac
)
871 if (ARGS_PUNCT
== ac
)
874 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
877 * In this case, we've located a submacro and must
878 * execute it. Close out scope, if open. If no
879 * elements have been generated, either create one (nc)
880 * or raise a warning.
883 if (MDOC_MAX
!= ntok
) {
884 if (scope
&& ! rew_elem(mdoc
, tok
))
886 if (nc
&& 0 == cnt
) {
887 if ( ! mdoc_elem_alloc(mdoc
, line
,
890 if ( ! rew_last(mdoc
, mdoc
->last
))
892 } else if ( ! nc
&& 0 == cnt
) {
894 mdoc_pmsg(mdoc
, line
, ppos
,
895 MANDOCERR_MACROEMPTY
);
898 if ( ! mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
))
902 return(append_delims(mdoc
, line
, pos
, buf
));
906 * Non-quote-enclosed punctuation. Set up our scope, if
907 * a word; rewind the scope, if a delimiter; then append
911 d
= ARGS_QWORD
== ac
? DELIM_NONE
: mdoc_isdelim(p
);
913 if (DELIM_NONE
!= d
) {
915 * If we encounter closing punctuation, no word
916 * has been omitted, no scope is open, and we're
917 * allowed to have an empty element, then start
918 * a new scope. `Ar', `Fl', and `Li', only do
919 * this once per invocation. There may be more
920 * of these (all of them?).
922 if (0 == cnt
&& (nc
|| MDOC_Li
== tok
) &&
923 DELIM_CLOSE
== d
&& ! scope
) {
924 if ( ! mdoc_elem_alloc(mdoc
, line
,
927 if (MDOC_Ar
== tok
|| MDOC_Li
== tok
||
933 * Close out our scope, if one is open, before
936 if (scope
&& ! rew_elem(mdoc
, tok
))
939 } else if ( ! scope
) {
940 if ( ! mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
))
948 if ( ! dword(mdoc
, line
, la
, p
, d
))
952 * `Fl' macros have their scope re-opened with each new
953 * word so that the `-' can be added to each one without
954 * having to parse out spaces.
956 if (scope
&& MDOC_Fl
== tok
) {
957 if ( ! rew_elem(mdoc
, tok
))
963 if (scope
&& ! rew_elem(mdoc
, tok
))
967 * If no elements have been collected and we're allowed to have
968 * empties (nc), open a scope and close it out. Otherwise,
972 if (nc
&& 0 == cnt
) {
973 if ( ! mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
))
975 if ( ! rew_last(mdoc
, mdoc
->last
))
977 } else if ( ! nc
&& 0 == cnt
) {
979 mdoc_pmsg(mdoc
, line
, ppos
, MANDOCERR_MACROEMPTY
);
984 return(append_delims(mdoc
, line
, pos
, buf
));
989 blk_full(MACRO_PROT_ARGS
)
992 struct mdoc_arg
*arg
;
993 struct mdoc_node
*head
; /* save of head macro */
994 struct mdoc_node
*body
; /* save of body macro */
998 enum margserr ac
, lac
;
1002 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1004 /* Close out prior implicit scope. */
1006 if ( ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)) {
1007 if ( ! rew_sub(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
1009 if ( ! rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
))
1014 * This routine accommodates implicitly- and explicitly-scoped
1015 * macro openings. Implicit ones first close out prior scope
1016 * (seen above). Delay opening the head until necessary to
1017 * allow leading punctuation to print. Special consideration
1018 * for `It -column', which has phrase-part syntax instead of
1019 * regular child nodes.
1022 for (arg
= NULL
;; ) {
1024 av
= mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1026 if (ARGV_WORD
== av
) {
1031 if (ARGV_EOLN
== av
)
1036 mdoc_argv_free(arg
);
1040 if ( ! mdoc_block_alloc(mdoc
, line
, ppos
, tok
, arg
))
1046 * Exception: Heads of `It' macros in `-diag' lists are not
1047 * parsed, even though `It' macros in general are parsed.
1049 nparsed
= MDOC_It
== tok
&&
1050 MDOC_Bl
== mdoc
->last
->parent
->tok
&&
1051 LIST_diag
== mdoc
->last
->parent
->norm
->Bl
.type
;
1054 * The `Nd' macro has all arguments in its body: it's a hybrid
1055 * of block partial-explicit and full-implicit. Stupid.
1058 if (MDOC_Nd
== tok
) {
1059 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
1062 if ( ! rew_sub(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
1064 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1073 /* Initialise last-phrase-type with ARGS_PEND. */
1074 lac
= ARGS_ERROR
== ac
? ARGS_PEND
: ac
;
1075 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1077 if (ARGS_PUNCT
== ac
)
1080 if (ARGS_ERROR
== ac
)
1083 if (ARGS_EOLN
== ac
) {
1084 if (ARGS_PPHRASE
!= lac
&& ARGS_PHRASE
!= lac
)
1087 * This is necessary: if the last token on a
1088 * line is a `Ta' or tab, then we'll get
1089 * ARGS_EOLN, so we must be smart enough to
1090 * reopen our scope if the last parse was a
1091 * phrase or partial phrase.
1093 if ( ! rew_sub(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
1095 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1102 * Emit leading punctuation (i.e., punctuation before
1103 * the MDOC_HEAD) for non-phrase types.
1108 ARGS_PHRASE
!= ac
&&
1109 ARGS_PPHRASE
!= ac
&&
1111 DELIM_OPEN
== mdoc_isdelim(p
)) {
1112 if ( ! dword(mdoc
, line
, la
, p
, DELIM_OPEN
))
1117 /* Open a head if one hasn't been opened. */
1120 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
1125 if (ARGS_PHRASE
== ac
||
1127 ARGS_PPHRASE
== ac
) {
1129 * If we haven't opened a body yet, rewind the
1130 * head; if we have, rewind that instead.
1133 mtt
= body
? MDOC_BODY
: MDOC_HEAD
;
1134 if ( ! rew_sub(mtt
, mdoc
, tok
, line
, ppos
))
1137 /* Then allocate our body context. */
1139 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1144 * Process phrases: set whether we're in a
1145 * partial-phrase (this effects line handling)
1146 * then call down into the phrase parser.
1149 if (ARGS_PPHRASE
== ac
)
1150 mdoc
->flags
|= MDOC_PPHRASE
;
1151 if (ARGS_PEND
== ac
&& ARGS_PPHRASE
== lac
)
1152 mdoc
->flags
|= MDOC_PPHRASE
;
1154 if ( ! phrase(mdoc
, line
, la
, buf
))
1157 mdoc
->flags
&= ~MDOC_PPHRASE
;
1161 ntok
= nparsed
|| ARGS_QWORD
== ac
?
1162 MDOC_MAX
: lookup(tok
, p
);
1164 if (MDOC_MAX
== ntok
) {
1165 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1170 if ( ! mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
))
1176 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
1181 if (nl
&& ! append_delims(mdoc
, line
, pos
, buf
))
1184 /* If we've already opened our body, exit now. */
1190 * If there is an open (i.e., unvalidated) sub-block requiring
1191 * explicit close-out, postpone switching the current block from
1192 * head to body until the rew_sub() call closing out that
1195 for (n
= mdoc
->last
; n
&& n
!= head
; n
= n
->parent
) {
1196 if (MDOC_BLOCK
== n
->type
&&
1197 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
&&
1198 ! (MDOC_VALID
& n
->flags
)) {
1204 /* Close out scopes to remain in a consistent state. */
1206 if ( ! rew_sub(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
1208 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1212 if ( ! (MDOC_FREECOL
& mdoc
->flags
))
1215 if ( ! rew_sub(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
1217 if ( ! rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
))
1220 mdoc
->flags
&= ~MDOC_FREECOL
;
1226 blk_part_imp(MACRO_PROT_ARGS
)
1232 struct mdoc_node
*blk
; /* saved block context */
1233 struct mdoc_node
*body
; /* saved body context */
1234 struct mdoc_node
*n
;
1236 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1239 * A macro that spans to the end of the line. This is generally
1240 * (but not necessarily) called as the first macro. The block
1241 * has a head as the immediate child, which is always empty,
1242 * followed by zero or more opening punctuation nodes, then the
1243 * body (which may be empty, depending on the macro), then zero
1244 * or more closing punctuation nodes.
1247 if ( ! mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
))
1252 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
1254 if ( ! rew_sub(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
1258 * Open the body scope "on-demand", that is, after we've
1259 * processed all our the leading delimiters (open parenthesis,
1263 for (body
= NULL
; ; ) {
1265 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1267 if (ARGS_ERROR
== ac
)
1269 if (ARGS_EOLN
== ac
)
1271 if (ARGS_PUNCT
== ac
)
1274 if (NULL
== body
&& ARGS_QWORD
!= ac
&&
1275 DELIM_OPEN
== mdoc_isdelim(p
)) {
1276 if ( ! dword(mdoc
, line
, la
, p
, DELIM_OPEN
))
1282 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1287 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1289 if (MDOC_MAX
== ntok
) {
1290 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1295 if ( ! mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
))
1300 /* Clean-ups to leave in a consistent state. */
1303 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1308 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1312 * End of sentence spacing: if the last node is a text node and
1313 * has a trailing period, then mark it as being end-of-sentence.
1316 if (n
&& MDOC_TEXT
== n
->type
&& n
->string
)
1317 if (mandoc_eos(n
->string
, strlen(n
->string
), 1))
1318 n
->flags
|= MDOC_EOS
;
1320 /* Up-propagate the end-of-space flag. */
1322 if (n
&& (MDOC_EOS
& n
->flags
)) {
1323 body
->flags
|= MDOC_EOS
;
1324 body
->parent
->flags
|= MDOC_EOS
;
1328 * If there is an open sub-block requiring explicit close-out,
1329 * postpone closing out the current block
1330 * until the rew_sub() call closing out the sub-block.
1332 for (n
= mdoc
->last
; n
&& n
!= body
&& n
!= blk
->parent
;
1334 if (MDOC_BLOCK
== n
->type
&&
1335 MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
&&
1336 ! (MDOC_VALID
& n
->flags
)) {
1337 make_pending(n
, tok
, mdoc
, line
, ppos
);
1338 if ( ! mdoc_endbody_alloc(mdoc
, line
, ppos
,
1339 tok
, body
, ENDBODY_NOSPACE
))
1346 * If we can't rewind to our body, then our scope has already
1347 * been closed by another macro (like `Oc' closing `Op'). This
1348 * is ugly behaviour nodding its head to OpenBSD's overwhelming
1349 * crufty use of `Op' breakage.
1352 mandoc_vmsg(MANDOCERR_SCOPENEST
, mdoc
->parse
, line
, ppos
,
1353 "%s broken", mdoc_macronames
[tok
]);
1355 if (n
&& ! rew_sub(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
1358 /* Standard appending of delimiters. */
1360 if (nl
&& ! append_delims(mdoc
, line
, pos
, buf
))
1363 /* Rewind scope, if applicable. */
1365 if (n
&& ! rew_sub(MDOC_BLOCK
, mdoc
, tok
, line
, ppos
))
1368 /* Move trailing .Ns out of scope. */
1370 for (n
= body
->child
; n
&& n
->next
; n
= n
->next
)
1372 if (n
&& MDOC_Ns
== n
->tok
)
1373 mdoc_node_relink(mdoc
, n
);
1380 blk_part_exp(MACRO_PROT_ARGS
)
1384 struct mdoc_node
*head
; /* keep track of head */
1385 struct mdoc_node
*body
; /* keep track of body */
1389 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1392 * The opening of an explicit macro having zero or more leading
1393 * punctuation nodes; a head with optional single element (the
1394 * case of `Eo'); and a body that may be empty.
1397 if ( ! mdoc_block_alloc(mdoc
, line
, ppos
, tok
, NULL
))
1400 for (head
= body
= NULL
; ; ) {
1402 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1404 if (ARGS_ERROR
== ac
)
1406 if (ARGS_PUNCT
== ac
)
1408 if (ARGS_EOLN
== ac
)
1411 /* Flush out leading punctuation. */
1413 if (NULL
== head
&& ARGS_QWORD
!= ac
&&
1414 DELIM_OPEN
== mdoc_isdelim(p
)) {
1415 assert(NULL
== body
);
1416 if ( ! dword(mdoc
, line
, la
, p
, DELIM_OPEN
))
1422 assert(NULL
== body
);
1423 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
1429 * `Eo' gobbles any data into the head, but most other
1430 * macros just immediately close out and begin the body.
1435 /* No check whether it's a macro! */
1437 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1440 if ( ! rew_sub(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
1442 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1450 assert(NULL
!= head
&& NULL
!= body
);
1452 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1454 if (MDOC_MAX
== ntok
) {
1455 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1460 if ( ! mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
))
1465 /* Clean-up to leave in a consistent state. */
1468 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
1472 if ( ! rew_sub(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
1474 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
1478 /* Standard appending of delimiters. */
1482 return(append_delims(mdoc
, line
, pos
, buf
));
1488 in_line_argn(MACRO_PROT_ARGS
)
1490 int la
, flushed
, j
, maxargs
, nl
;
1493 struct mdoc_arg
*arg
;
1497 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1500 * A line macro that has a fixed number of arguments (maxargs).
1501 * Only open the scope once the first non-leading-punctuation is
1502 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1503 * keep it open until the maximum number of arguments are
1527 for (arg
= NULL
; ; ) {
1529 av
= mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1531 if (ARGV_WORD
== av
) {
1536 if (ARGV_EOLN
== av
)
1541 mdoc_argv_free(arg
);
1545 for (flushed
= j
= 0; ; ) {
1547 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1549 if (ARGS_ERROR
== ac
)
1551 if (ARGS_PUNCT
== ac
)
1553 if (ARGS_EOLN
== ac
)
1556 if ( ! (MDOC_IGNDELIM
& mdoc_macros
[tok
].flags
) &&
1557 ARGS_QWORD
!= ac
&& 0 == j
&&
1558 DELIM_OPEN
== mdoc_isdelim(p
)) {
1559 if ( ! dword(mdoc
, line
, la
, p
, DELIM_OPEN
))
1563 if ( ! mdoc_elem_alloc(mdoc
, line
, la
, tok
, arg
))
1566 if (j
== maxargs
&& ! flushed
) {
1567 if ( ! rew_elem(mdoc
, tok
))
1572 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1574 if (MDOC_MAX
!= ntok
) {
1575 if ( ! flushed
&& ! rew_elem(mdoc
, tok
))
1578 if ( ! mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
))
1584 if ( ! (MDOC_IGNDELIM
& mdoc_macros
[tok
].flags
) &&
1587 DELIM_NONE
!= mdoc_isdelim(p
)) {
1588 if ( ! rew_elem(mdoc
, tok
))
1593 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1598 if (0 == j
&& ! mdoc_elem_alloc(mdoc
, line
, la
, tok
, arg
))
1601 /* Close out in a consistent state. */
1603 if ( ! flushed
&& ! rew_elem(mdoc
, tok
))
1607 return(append_delims(mdoc
, line
, pos
, buf
));
1612 in_line_eoln(MACRO_PROT_ARGS
)
1617 struct mdoc_arg
*arg
;
1621 assert( ! (MDOC_PARSED
& mdoc_macros
[tok
].flags
));
1624 rew_sub(MDOC_BLOCK
, mdoc
, MDOC_Nm
, line
, ppos
);
1626 /* Parse macro arguments. */
1628 for (arg
= NULL
; ; ) {
1630 av
= mdoc_argv(mdoc
, line
, tok
, &arg
, pos
, buf
);
1632 if (ARGV_WORD
== av
) {
1636 if (ARGV_EOLN
== av
)
1641 mdoc_argv_free(arg
);
1645 /* Open element scope. */
1647 if ( ! mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, arg
))
1650 /* Parse argument terms. */
1654 ac
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1656 if (ARGS_ERROR
== ac
)
1658 if (ARGS_EOLN
== ac
)
1661 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup(tok
, p
);
1663 if (MDOC_MAX
== ntok
) {
1664 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1669 if ( ! rew_elem(mdoc
, tok
))
1671 return(mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
));
1674 /* Close out (no delimiters). */
1676 return(rew_elem(mdoc
, tok
));
1682 ctx_synopsis(MACRO_PROT_ARGS
)
1686 nl
= MDOC_NEWLINE
& mdoc
->flags
;
1688 /* If we're not in the SYNOPSIS, go straight to in-line. */
1689 if ( ! (MDOC_SYNOPSIS
& mdoc
->flags
))
1690 return(in_line(mdoc
, tok
, line
, ppos
, pos
, buf
));
1692 /* If we're a nested call, same place. */
1694 return(in_line(mdoc
, tok
, line
, ppos
, pos
, buf
));
1697 * XXX: this will open a block scope; however, if later we end
1698 * up formatting the block scope, then child nodes will inherit
1699 * the formatting. Be careful.
1702 return(blk_full(mdoc
, tok
, line
, ppos
, pos
, buf
));
1703 assert(MDOC_Vt
== tok
);
1704 return(blk_part_imp(mdoc
, tok
, line
, ppos
, pos
, buf
));
1710 obsolete(MACRO_PROT_ARGS
)
1713 mdoc_pmsg(mdoc
, line
, ppos
, MANDOCERR_MACROOBS
);
1719 * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1720 * They're unusual because they're basically free-form text until a
1721 * macro is encountered.
1724 phrase(struct mdoc
*mdoc
, int line
, int ppos
, char *buf
)
1731 for (pos
= ppos
; ; ) {
1734 ac
= mdoc_zargs(mdoc
, line
, &pos
, buf
, &p
);
1736 if (ARGS_ERROR
== ac
)
1738 if (ARGS_EOLN
== ac
)
1741 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup_raw(p
);
1743 if (MDOC_MAX
== ntok
) {
1744 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1749 if ( ! mdoc_macro(mdoc
, ntok
, line
, la
, &pos
, buf
))
1751 return(append_delims(mdoc
, line
, &pos
, buf
));
1760 phrase_ta(MACRO_PROT_ARGS
)
1768 * FIXME: this is overly restrictive: if the `Ta' is unexpected,
1769 * it should simply error out with ARGSLOST.
1772 if ( ! rew_sub(MDOC_BODY
, mdoc
, MDOC_It
, line
, ppos
))
1774 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, MDOC_It
))
1779 ac
= mdoc_zargs(mdoc
, line
, pos
, buf
, &p
);
1781 if (ARGS_ERROR
== ac
)
1783 if (ARGS_EOLN
== ac
)
1786 ntok
= ARGS_QWORD
== ac
? MDOC_MAX
: lookup_raw(p
);
1788 if (MDOC_MAX
== ntok
) {
1789 if ( ! dword(mdoc
, line
, la
, p
, DELIM_MAX
))
1794 if ( ! mdoc_macro(mdoc
, ntok
, line
, la
, pos
, buf
))
1796 return(append_delims(mdoc
, line
, pos
, buf
));