]>
git.cameronkatri.com Git - mandoc.git/blob - macro.c
1 /* $Id: macro.c,v 1.48 2009/01/20 20:56:21 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
29 * This has scanning/parsing routines, each of which extract a macro and
30 * its arguments and parameters, then know how to progress to the next
31 * macro. Macros are parsed according as follows:
33 * ELEMENT: TEXT | epsilon
34 * BLOCK: HEAD PUNCT BODY PUNCT BLOCK_TAIL PUNCT
35 * BLOCK_TAIL: TAIL | epsilon
36 * HEAD: ELEMENT | TEXT | BLOCK | epsilon
37 * BODY: ELEMENT | TEXT | BLOCK | epsilon
38 * TAIL: TEXT | epsilon
39 * PUNCT: TEXT (delimiters) | epsilon
41 * These are arranged into a parse tree, an example of which follows:
51 * TEXT (`mdoc macro compiler')
66 * These types are always per-line except for block bodies, which may
67 * span multiple lines. Macros are assigned a parsing routine, which
68 * corresponds to the type, in the mdoc_macros table.
70 * Note that types are general: there can be several parsing routines
71 * corresponding to a single type. The macro_text function, for
72 * example, parses an ELEMENT type (see the function definition for
73 * details) that may be interrupted by further macros; the
74 * macro_constant function, on the other hand, parses an ELEMENT type
75 * spanning a single line.
80 #define REWIND_REWIND (1 << 0)
81 #define REWIND_NOHALT (1 << 1)
82 #define REWIND_HALT (1 << 2)
83 static int rewind_dohalt(int, enum mdoc_type
,
84 const struct mdoc_node
*);
85 static int rewind_alt(int);
86 static int rewind_dobreak(int, const struct mdoc_node
*);
87 static int rewind_elem(struct mdoc
*, int);
88 static int rewind_impblock(struct mdoc
*, int, int, int);
89 static int rewind_expblock(struct mdoc
*, int, int, int);
90 static int rewind_subblock(enum mdoc_type
,
91 struct mdoc
*, int, int, int);
92 static int rewind_last(struct mdoc
*, struct mdoc_node
*);
93 static int append_delims(struct mdoc
*, int, int *, char *);
94 static int lookup(struct mdoc
*, int, int, int, const char *);
98 lookup(struct mdoc
*mdoc
, int line
, int pos
, int from
, const char *p
)
102 res
= mdoc_find(mdoc
, p
);
103 if (MDOC_PARSED
& mdoc_macros
[from
].flags
)
107 if ( ! mdoc_pwarn(mdoc
, line
, pos
, WARN_SYNTAX
, "macro-like parameter"))
114 rewind_last(struct mdoc
*mdoc
, struct mdoc_node
*to
)
118 mdoc
->next
= MDOC_NEXT_SIBLING
;
120 while (mdoc
->last
!= to
) {
121 if ( ! mdoc_valid_post(mdoc
))
123 if ( ! mdoc_action_post(mdoc
))
125 mdoc
->last
= mdoc
->last
->parent
;
129 if ( ! mdoc_valid_post(mdoc
))
131 return(mdoc_action_post(mdoc
));
178 rewind_dohalt(int tok
, enum mdoc_type type
, const struct mdoc_node
*p
)
181 if (MDOC_ROOT
== p
->type
)
183 if (MDOC_VALID
& p
->flags
)
184 return(REWIND_NOHALT
);
187 /* One-liner implicit-scope. */
207 assert(MDOC_HEAD
!= type
);
208 assert(MDOC_TAIL
!= type
);
209 if (type
== p
->type
&& tok
== p
->tok
)
210 return(REWIND_REWIND
);
213 /* Multi-line implicit-scope. */
215 assert(MDOC_TAIL
!= type
);
216 if (type
== p
->type
&& tok
== p
->tok
)
217 return(REWIND_REWIND
);
218 if (MDOC_BODY
== p
->type
&& MDOC_Bl
== p
->tok
)
222 if (type
== p
->type
&& tok
== p
->tok
)
223 return(REWIND_REWIND
);
226 assert(MDOC_TAIL
!= type
);
227 if (type
== p
->type
&& tok
== p
->tok
)
228 return(REWIND_REWIND
);
229 if (MDOC_BODY
== p
->type
&& MDOC_Sh
== p
->tok
)
233 /* Multi-line explicit scope start. */
263 if (type
== p
->type
&& tok
== p
->tok
)
264 return(REWIND_REWIND
);
267 /* Multi-line explicit scope close. */
297 if (type
== p
->type
&& rewind_alt(tok
) == p
->tok
)
298 return(REWIND_REWIND
);
305 return(REWIND_NOHALT
);
310 rewind_dobreak(int tok
, const struct mdoc_node
*p
)
313 assert(MDOC_ROOT
!= p
->type
);
314 if (MDOC_ELEM
== p
->type
)
316 if (MDOC_TEXT
== p
->type
)
318 if (MDOC_VALID
& p
->flags
)
322 /* Implicit rules. */
324 return(MDOC_It
== p
->tok
);
326 return(MDOC_Ss
== p
->tok
);
328 if (MDOC_Ss
== p
->tok
)
330 return(MDOC_Sh
== p
->tok
);
332 /* Extra scope rules. */
334 if (MDOC_It
== p
->tok
)
341 if (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)
342 return(p
->tok
== rewind_alt(tok
));
343 else if (MDOC_BLOCK
== p
->type
)
346 return(tok
== p
->tok
);
351 rewind_elem(struct mdoc
*mdoc
, int tok
)
356 if (MDOC_ELEM
!= n
->type
)
358 assert(MDOC_ELEM
== n
->type
);
359 assert(tok
== n
->tok
);
361 return(rewind_last(mdoc
, n
));
366 rewind_subblock(enum mdoc_type type
, struct mdoc
*mdoc
,
367 int tok
, int line
, int ppos
)
373 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
374 c
= rewind_dohalt(tok
, type
, n
);
375 if (REWIND_HALT
== c
)
377 if (REWIND_REWIND
== c
)
379 else if (rewind_dobreak(tok
, n
))
381 return(mdoc_perr(mdoc
, line
, ppos
, "scope breaks prior %s", mdoc_node2a(n
)));
385 return(rewind_last(mdoc
, n
));
390 rewind_expblock(struct mdoc
*mdoc
, int tok
, int line
, int ppos
)
396 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
397 c
= rewind_dohalt(tok
, MDOC_BLOCK
, n
);
398 if (REWIND_HALT
== c
)
399 return(mdoc_perr(mdoc
, line
, ppos
, "closing macro has no context"));
400 if (REWIND_REWIND
== c
)
402 else if (rewind_dobreak(tok
, n
))
404 return(mdoc_perr(mdoc
, line
, ppos
, "scope breaks prior %s", mdoc_node2a(n
)));
408 return(rewind_last(mdoc
, n
));
413 rewind_impblock(struct mdoc
*mdoc
, int tok
, int line
, int ppos
)
419 for (n
= mdoc
->last
; n
; n
= n
->parent
) {
420 c
= rewind_dohalt(tok
, MDOC_BLOCK
, n
);
421 if (REWIND_HALT
== c
)
423 else if (REWIND_REWIND
== c
)
425 else if (rewind_dobreak(tok
, n
))
427 return(mdoc_perr(mdoc
, line
, ppos
, "scope breaks prior %s", mdoc_node2a(n
)));
431 return(rewind_last(mdoc
, n
));
436 append_delims(struct mdoc
*mdoc
, int line
, int *pos
, char *buf
)
446 c
= mdoc_args(mdoc
, line
, pos
, buf
, 0, &p
);
449 else if (ARGS_EOLN
== c
)
451 assert(mdoc_isdelim(p
));
452 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
454 mdoc
->next
= MDOC_NEXT_SIBLING
;
462 * Close out an explicit scope. This optionally parses a TAIL type with
463 * a set number of TEXT children.
466 macro_scoped_close(MACRO_PROT_ARGS
)
468 int tt
, j
, c
, lastarg
, maxargs
, flushed
;
480 tt
= rewind_alt(tok
);
482 mdoc_msg(mdoc
, "parse: %s closing %s",
483 mdoc_macronames
[tok
], mdoc_macronames
[tt
]);
485 if ( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
)) {
486 if (0 == buf
[*pos
]) {
487 if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
489 return(rewind_expblock(mdoc
, tok
, line
, ppos
));
491 return(mdoc_perr(mdoc
, line
, ppos
, "macro expects no parameters"));
494 if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
501 if ( ! mdoc_tail_alloc(mdoc
, line
, ppos
, tt
))
503 mdoc
->next
= MDOC_NEXT_CHILD
;
506 for (j
= 0; /* No sentinel. */; j
++) {
509 if (j
== maxargs
&& ! flushed
) {
510 if ( ! rewind_expblock(mdoc
, tok
, line
, ppos
))
515 c
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
523 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
525 else if (MDOC_MAX
!= c
) {
527 if ( ! rewind_expblock(mdoc
, tok
, line
, ppos
))
531 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
536 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
538 mdoc
->next
= MDOC_NEXT_SIBLING
;
541 if ( ! flushed
&& ! rewind_expblock(mdoc
, tok
, line
, ppos
))
546 return(append_delims(mdoc
, line
, pos
, buf
));
551 * A general text macro. This is a complex case because of punctuation.
552 * If a text macro is followed by words, then punctuation, the macro is
553 * "stopped" and "reopened" following the punctuation. Thus, the
564 * This must handle the following situations:
575 macro_text(MACRO_PROT_ARGS
)
577 int la
, lastpunct
, c
, w
, argc
;
578 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
584 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
586 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
589 if (ARGV_WORD
== c
) {
592 } else if (ARGV_ARG
== c
)
595 mdoc_argv_free(argc
, argv
);
599 if (MDOC_LINEARG_MAX
== argc
) {
600 mdoc_argv_free(argc
- 1, argv
);
601 return(mdoc_perr(mdoc
, line
, ppos
, "parameter hard-limit exceeded"));
604 c
= mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, argc
, argv
);
607 mdoc_argv_free(argc
, argv
);
611 mdoc
->next
= MDOC_NEXT_CHILD
;
616 w
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
617 if (ARGS_ERROR
== w
) {
618 mdoc_argv_free(argc
, argv
);
627 c
= ARGS_QWORD
== w
? MDOC_MAX
:
628 lookup(mdoc
, line
, la
, tok
, p
);
630 if (MDOC_MAX
!= c
&& -1 != c
) {
631 if (0 == lastpunct
&& ! rewind_elem(mdoc
, tok
)) {
632 mdoc_argv_free(argc
, argv
);
635 mdoc_argv_free(argc
, argv
);
636 c
= mdoc_macro(mdoc
, c
, line
, la
, pos
, buf
);
641 return(append_delims(mdoc
, line
, pos
, buf
));
642 } else if (-1 == c
) {
643 mdoc_argv_free(argc
, argv
);
647 if (ARGS_QWORD
!= w
&& mdoc_isdelim(p
)) {
648 if (0 == lastpunct
&& ! rewind_elem(mdoc
, tok
)) {
649 mdoc_argv_free(argc
, argv
);
653 } else if (lastpunct
) {
654 c
= mdoc_elem_alloc(mdoc
, line
,
655 ppos
, tok
, argc
, argv
);
657 mdoc_argv_free(argc
, argv
);
660 mdoc
->next
= MDOC_NEXT_CHILD
;
664 if ( ! mdoc_word_alloc(mdoc
, line
, la
, p
))
666 mdoc
->next
= MDOC_NEXT_SIBLING
;
669 mdoc_argv_free(argc
, argv
);
671 if (0 == lastpunct
&& ! rewind_elem(mdoc
, tok
))
675 return(append_delims(mdoc
, line
, pos
, buf
));
680 * Handle explicit-scope (having a different closure token) and implicit
681 * scope (closing out prior scopes when re-invoked) macros. These
682 * constitute the BLOCK type and usually span multiple lines. These
683 * always have HEAD and sometimes have BODY types. In the multi-line
700 * Note that the `.It' macro, possibly the most difficult (as it has
701 * embedded scope, etc.) is handled by this routine.
704 macro_scoped(MACRO_PROT_ARGS
)
706 int c
, lastarg
, argc
;
707 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
710 assert ( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
));
712 /* First rewind extant implicit scope. */
714 if ( ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)) {
715 if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
717 if ( ! rewind_impblock(mdoc
, tok
, line
, ppos
))
721 /* Parse arguments. */
723 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
725 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
728 if (ARGV_WORD
== c
) {
731 } else if (ARGV_ARG
== c
)
733 mdoc_argv_free(argc
, argv
);
737 if (MDOC_LINEARG_MAX
== argc
) {
738 mdoc_argv_free(argc
- 1, argv
);
739 return(mdoc_perr(mdoc
, line
, ppos
, "parameter hard-limit exceeded"));
742 c
= mdoc_block_alloc(mdoc
, line
, ppos
,
743 tok
, (size_t)argc
, argv
);
744 mdoc_argv_free(argc
, argv
);
749 mdoc
->next
= MDOC_NEXT_CHILD
;
751 if (0 == buf
[*pos
]) {
752 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
754 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
756 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
758 mdoc
->next
= MDOC_NEXT_CHILD
;
762 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
764 mdoc
->next
= MDOC_NEXT_CHILD
;
768 c
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
777 /* FIXME: if .It -column, the lookup must be for a
778 * sub-line component. BLAH. */
780 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
784 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
786 mdoc
->next
= MDOC_NEXT_SIBLING
;
790 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
795 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
797 if (1 == ppos
&& ! append_delims(mdoc
, line
, pos
, buf
))
800 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
802 mdoc
->next
= MDOC_NEXT_CHILD
;
809 * This handles a case of implicitly-scoped macro (BLOCK) limited to a
810 * single line. Instead of being closed out by a subsequent call to
811 * another macro, the scope is closed at the end of line. These don't
812 * have BODY or TAIL types. Notice that the punctuation falls outside
815 * .Qq a Fl b Ar d ; ;
828 macro_scoped_line(MACRO_PROT_ARGS
)
833 if ( ! mdoc_block_alloc(mdoc
, line
, ppos
, tok
, 0, NULL
))
835 mdoc
->next
= MDOC_NEXT_CHILD
;
837 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
839 mdoc
->next
= MDOC_NEXT_SIBLING
;
840 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
842 mdoc
->next
= MDOC_NEXT_CHILD
;
844 /* XXX - no known argument macros. */
849 c
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
858 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
860 else if (MDOC_MAX
== c
) {
861 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
863 mdoc
->next
= MDOC_NEXT_SIBLING
;
867 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
873 if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
875 if ( ! append_delims(mdoc
, line
, pos
, buf
))
877 } else if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
, line
, ppos
))
879 return(rewind_impblock(mdoc
, tok
, line
, ppos
));
884 * A constant-scoped macro is like a simple-scoped macro (mdoc_scoped)
885 * except that it doesn't handle implicit scopes and explicit ones have
886 * a fixed number of TEXT children to the BODY.
899 macro_constant_scoped(MACRO_PROT_ARGS
)
901 int lastarg
, flushed
, j
, c
, maxargs
;
916 if ( ! mdoc_block_alloc(mdoc
, line
, ppos
, tok
, 0, NULL
))
918 mdoc
->next
= MDOC_NEXT_CHILD
;
921 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
923 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
925 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
928 } else if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
931 mdoc
->next
= MDOC_NEXT_CHILD
;
933 for (j
= 0; /* No sentinel. */; j
++) {
936 if (j
== maxargs
&& ! flushed
) {
937 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
940 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
942 mdoc
->next
= MDOC_NEXT_CHILD
;
945 c
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
953 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
955 else if (MDOC_MAX
!= c
) {
957 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
960 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
962 mdoc
->next
= MDOC_NEXT_CHILD
;
964 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
969 if ( ! flushed
&& mdoc_isdelim(p
)) {
970 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
973 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
975 mdoc
->next
= MDOC_NEXT_CHILD
;
978 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
980 mdoc
->next
= MDOC_NEXT_SIBLING
;
984 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
, line
, ppos
))
986 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
988 mdoc
->next
= MDOC_NEXT_CHILD
;
993 return(append_delims(mdoc
, line
, pos
, buf
));
998 * A delimited constant is very similar to the macros parsed by
999 * macro_text except that, in the event of punctuation, the macro isn't
1000 * "re-opened" as it is in macro_text. Also, these macros have a fixed
1001 * number of parameters.
1011 macro_constant_delimited(MACRO_PROT_ARGS
)
1013 int lastarg
, flushed
, j
, c
, maxargs
, argc
;
1014 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
1037 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
1039 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
1042 if (ARGV_WORD
== c
) {
1045 } else if (ARGV_ARG
== c
)
1047 mdoc_argv_free(argc
, argv
);
1051 if (MDOC_LINEARG_MAX
== argc
) {
1052 mdoc_argv_free(argc
- 1, argv
);
1053 return(mdoc_perr(mdoc
, line
, ppos
, "parameter hard-limit exceeded"));
1056 c
= mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, argc
, argv
);
1057 mdoc_argv_free(argc
, argv
);
1062 mdoc
->next
= MDOC_NEXT_CHILD
;
1064 for (j
= 0; /* No sentinel. */; j
++) {
1067 if (j
== maxargs
&& ! flushed
) {
1068 if ( ! rewind_elem(mdoc
, tok
))
1073 c
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1074 if (ARGS_ERROR
== c
)
1076 if (ARGS_PUNCT
== c
)
1081 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
1083 else if (MDOC_MAX
!= c
) {
1084 if ( ! flushed
&& ! rewind_elem(mdoc
, tok
))
1087 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
1092 if ( ! flushed
&& mdoc_isdelim(p
)) {
1093 if ( ! rewind_elem(mdoc
, tok
))
1098 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
1100 mdoc
->next
= MDOC_NEXT_SIBLING
;
1103 if ( ! flushed
&& ! rewind_elem(mdoc
, tok
))
1108 return(append_delims(mdoc
, line
, pos
, buf
));
1113 * A constant macro is the simplest classification. It spans an entire
1117 macro_constant(MACRO_PROT_ARGS
)
1120 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
1123 assert( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
));
1125 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
1127 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
1130 if (ARGV_WORD
== c
) {
1133 } else if (ARGV_ARG
== c
)
1136 mdoc_argv_free(argc
, argv
);
1140 if (MDOC_LINEARG_MAX
== argc
) {
1141 mdoc_argv_free(argc
- 1, argv
);
1142 return(mdoc_perr(mdoc
, line
, ppos
, "parameter hard-limit exceeded"));
1145 c
= mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, argc
, argv
);
1146 mdoc_argv_free(argc
, argv
);
1151 mdoc
->next
= MDOC_NEXT_CHILD
;
1155 w
= mdoc_args(mdoc
, line
, pos
, buf
, tok
, &p
);
1156 if (ARGS_ERROR
== w
)
1161 c
= ARGS_QWORD
== w
? MDOC_MAX
:
1162 lookup(mdoc
, line
, la
, tok
, p
);
1164 if (MDOC_MAX
!= c
&& -1 != c
) {
1165 if ( ! rewind_elem(mdoc
, tok
))
1167 return(mdoc_macro(mdoc
, c
, line
, la
, pos
, buf
));
1171 if ( ! mdoc_word_alloc(mdoc
, line
, la
, p
))
1173 mdoc
->next
= MDOC_NEXT_SIBLING
;
1176 return(rewind_elem(mdoc
, tok
));
1182 macro_obsolete(MACRO_PROT_ARGS
)
1185 return(mdoc_pwarn(mdoc
, line
, ppos
, WARN_SYNTAX
, "macro is obsolete"));
1190 * This is called at the end of parsing. It must traverse up the tree,
1191 * closing out open [implicit] scopes. Obviously, open explicit scopes
1195 macro_end(struct mdoc
*mdoc
)
1197 struct mdoc_node
*n
;
1199 assert(mdoc
->first
);
1202 /* Scan for open explicit scopes. */
1204 n
= MDOC_VALID
& mdoc
->last
->flags
?
1205 mdoc
->last
->parent
: mdoc
->last
;
1207 for ( ; n
; n
= n
->parent
) {
1208 if (MDOC_BLOCK
!= n
->type
)
1210 if ( ! (MDOC_EXPLICIT
& mdoc_macros
[n
->tok
].flags
))
1212 return(mdoc_nerr(mdoc
, n
, "macro scope still open on exit"));
1215 return(rewind_last(mdoc
, mdoc
->first
));