summaryrefslogtreecommitdiffstats
path: root/mdoc_macro.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-31 10:28:04 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-31 10:28:04 +0000
commit792720a705b86669c5d8a25a3250aa5619d8e1b1 (patch)
treef6265174a03a4dbecc183b23bc4730289cac99f8 /mdoc_macro.c
parentd00957f73a7baeeb808b27bb30f59463de6e147d (diff)
downloadmandoc-792720a705b86669c5d8a25a3250aa5619d8e1b1.tar.gz
Remove enum mdocargerr from phrase() (unused).
Add `Ta' macro, which is basically a NULL case everywhere but in mdoc_macro.c, where it closes out an existing `It' body scope and opens a new one, then continues parsing as in phrase() (TODO: merge these two?). Fix where scope-breaking was silently just dying instead of printing an error. Fix where trailing `Ta' or tab weren't creating a new MDOC_BODY context. We now support arbitrarily complex `It' contents for `Bl -column'.
Diffstat (limited to 'mdoc_macro.c')
-rw-r--r--mdoc_macro.c118
1 files changed, 96 insertions, 22 deletions
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 205512d6..20be5acb 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -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 = "<root>";
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, enum margserr ac)
}
+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);
+}