=================================================================== RCS file: /cvs/mandoc/mdoc_macro.c,v retrieving revision 1.74 retrieving revision 1.75 diff -u -p -r1.74 -r1.75 --- mandoc/mdoc_macro.c 2010/05/30 22:56:02 1.74 +++ mandoc/mdoc_macro.c 2010/05/31 10:28:04 1.75 @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.74 2010/05/30 22:56:02 kristaps Exp $ */ +/* $Id: mdoc_macro.c,v 1.75 2010/05/31 10:28:04 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -44,13 +44,13 @@ static int in_line_eoln(MACRO_PROT_ARGS); static int in_line_argn(MACRO_PROT_ARGS); static int in_line(MACRO_PROT_ARGS); static int obsolete(MACRO_PROT_ARGS); +static int phrase_ta(MACRO_PROT_ARGS); static int append_delims(struct mdoc *, int, int *, char *); static enum mdoct lookup(enum mdoct, const char *); static enum mdoct lookup_raw(const char *); -static int phrase(struct mdoc *, int, int, - char *, enum margserr); +static int phrase(struct mdoc *, int, int, char *); static enum mdoct rew_alt(enum mdoct); static int rew_dobreak(enum mdoct, const struct mdoc_node *); @@ -186,6 +186,7 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { in_line_eoln, 0 }, /* br */ { in_line_eoln, 0 }, /* sp */ { in_line_eoln, 0 }, /* %U */ + { phrase_ta, MDOC_CALLABLE | MDOC_PARSED }, /* Ta */ }; const struct mdoc_macro * const mdoc_macros = __mdoc_macros; @@ -196,7 +197,7 @@ swarn(struct mdoc *mdoc, enum mdoc_type type, int line, int pos, const struct mdoc_node *p) { const char *n, *t, *tt; - int rc; + enum mandocerr ec; n = t = ""; tt = "block"; @@ -229,11 +230,12 @@ swarn(struct mdoc *mdoc, enum mdoc_type type, break; } - rc = mdoc_vmsg(mdoc, MANDOCERR_SCOPE, line, pos, - "%s scope breaks %s of %s", tt, t, n); + ec = (MDOC_IGN_SCOPE & mdoc->pflags) ? + MANDOCERR_SCOPE : MANDOCERR_SYNTSCOPE; - /* FIXME: logic should be in driver. */ - return(MDOC_IGN_SCOPE & mdoc->pflags ? rc : 0); + return(mdoc_vmsg(mdoc, ec, line, pos, + "%s scope breaks %s of %s", + tt, t, n)); } @@ -1006,14 +1008,30 @@ blk_full(MACRO_PROT_ARGS) for ( ; ; ) { la = *pos; - /* Initialise last-phrase-type with ARGS_PHRASE. */ - lac = ARGS_ERROR == ac ? ARGS_PHRASE : ac; + /* Initialise last-phrase-type with ARGS_PEND. */ + lac = ARGS_ERROR == ac ? ARGS_PEND : ac; ac = mdoc_args(m, line, pos, buf, tok, &p); if (ARGS_ERROR == ac) return(0); - if (ARGS_EOLN == ac) + + if (ARGS_EOLN == ac) { + if (ARGS_PPHRASE != lac && ARGS_PHRASE != lac) + break; + /* + * This is necessary: if the last token on a + * line is a `Ta' or tab, then we'll get + * ARGS_EOLN, so we must be smart enough to + * reopen our scope if the last parse was a + * phrase or partial phrase. + */ + if ( ! rew_sub(MDOC_BODY, m, tok, line, ppos)) + return(0); + if ( ! mdoc_body_alloc(m, line, ppos, tok)) + return(0); + body = m->last; break; + } /* * Emit leading punctuation (i.e., punctuation before @@ -1068,10 +1086,7 @@ blk_full(MACRO_PROT_ARGS) if (ARGS_PEND == ac && ARGS_PPHRASE == lac) m->flags |= MDOC_PPHRASE; - if (ARGS_PEND == ac) { - if ( ! phrase(m, line, la, buf, lac)) - return(0); - } else if ( ! phrase(m, line, la, buf, ac)) + if ( ! phrase(m, line, la, buf)) return(0); m->flags &= ~MDOC_PPHRASE; @@ -1624,26 +1639,24 @@ obsolete(MACRO_PROT_ARGS) * macro is encountered. */ static int -phrase(struct mdoc *m, int line, int ppos, char *buf, enum margserr ac) +phrase(struct mdoc *m, int line, int ppos, char *buf) { int la, pos; - enum margserr aac; + enum margserr ac; enum mdoct ntok; char *p; - assert(ARGS_PHRASE == ac || ARGS_PPHRASE == ac); - for (pos = ppos; ; ) { la = pos; - aac = mdoc_zargs(m, line, &pos, buf, 0, &p); + ac = mdoc_zargs(m, line, &pos, buf, 0, &p); - if (ARGS_ERROR == aac) + if (ARGS_ERROR == ac) return(0); - if (ARGS_EOLN == aac) + if (ARGS_EOLN == ac) break; - ntok = ARGS_QWORD == aac ? MDOC_MAX : lookup_raw(p); + ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup_raw(p); if (MDOC_MAX == ntok) { if ( ! mdoc_word_alloc(m, line, la, p)) @@ -1660,3 +1673,64 @@ phrase(struct mdoc *m, int line, int ppos, char *buf, } +static int +phrase_ta(MACRO_PROT_ARGS) +{ + int la; + enum mdoct ntok; + enum margserr ac; + struct mdoc_node *n; + char *p; + + /* + * FIXME: this is overly restrictive: if the `Ta' is unexpected, + * it should simply error out with ARGSLOST. + */ + + n = m->last; + if ( ! rew_sub(MDOC_BODY, m, MDOC_It, line, ppos)) + return(0); + + /* + * FIXME: this is necessary in bogus constructions like + * .Bl -column foo bar + * .Sy foo Ta bar + * It is, however, an ugly way to do it. + * + * XXX; remove this when the above construct builds an implied + * `It' marker. + */ + if (NULL == m->last || + MDOC_BODY != m->last->type || + MDOC_It != m->last->tok) { + swarn(m, tok, line, ppos, n); + return(0); + } + + if ( ! mdoc_body_alloc(m, line, ppos, MDOC_It)) + return(0); + + for (;;) { + la = *pos; + ac = mdoc_zargs(m, line, pos, buf, 0, &p); + + if (ARGS_ERROR == ac) + return(0); + if (ARGS_EOLN == ac) + break; + + ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup_raw(p); + + if (MDOC_MAX == ntok) { + if ( ! mdoc_word_alloc(m, line, la, p)) + return(0); + continue; + } + + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) + return(0); + return(append_delims(m, line, pos, buf)); + } + + return(1); +}