source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Remove enum mdocargerr from phrase() (unused).
@ 2010-05-31 10:28 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-05-31 10:28 UTC (permalink / raw)
  To: source

Log Message:
-----------
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'.

Modified Files:
--------------
    mdocml:
        mdoc.c
        mdoc.h
        mdoc_action.c
        mdoc_argv.c
        mdoc_html.c
        mdoc_macro.c
        mdoc_term.c
        mdoc_validate.c

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.87 -r1.88
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -268,6 +268,7 @@ const	struct valids mdoc_valids[MDOC_MAX
 	{ NULL, posts_notext },			/* br */
 	{ NULL, posts_sp },			/* sp */
 	{ NULL, posts_text1 },			/* %U */
+	{ NULL, NULL },				/* Ta */
 };
 
 
Index: mdoc_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_macro.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.74 -r1.75
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -44,13 +44,13 @@ static	int	  	in_line_eoln(MACRO_PROT_AR
 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[MD
 	{ 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 
 		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 
 		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 ppo
 }
 
 
+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);
+}
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.70 -r1.71
--- mdoc_html.c
+++ mdoc_html.c
@@ -255,6 +255,7 @@ static	const struct htmlmdoc mdocs[MDOC_
 	{mdoc_sp_pre, NULL}, /* br */
 	{mdoc_sp_pre, NULL}, /* sp */ 
 	{mdoc__x_pre, mdoc__x_post}, /* %U */ 
+	{NULL, NULL}, /* Ta */ 
 };
 
 
Index: mdoc_action.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_action.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -Lmdoc_action.c -Lmdoc_action.c -u -p -r1.63 -r1.64
--- mdoc_action.c
+++ mdoc_action.c
@@ -194,6 +194,7 @@ static	const struct actions mdoc_actions
 	{ NULL, NULL }, /* br */
 	{ NULL, NULL }, /* sp */
 	{ NULL, NULL }, /* %U */
+	{ NULL, NULL }, /* Ta */
 };
 
 #define	RSORD_MAX 14
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.134 -r1.135
--- mdoc_term.c
+++ mdoc_term.c
@@ -260,6 +260,7 @@ static	const struct termact termacts[MDO
 	{ termp_sp_pre, NULL }, /* br */
 	{ termp_sp_pre, NULL }, /* sp */ 
 	{ termp_under_pre, termp____post }, /* %U */ 
+	{ NULL, NULL }, /* Ta */ 
 };
 
 
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.82
retrieving revision 1.83
diff -Lmdoc.h -Lmdoc.h -u -p -r1.82 -r1.83
--- mdoc.h
+++ mdoc.h
@@ -149,6 +149,7 @@ enum	mdoct {
 	MDOC_br,
 	MDOC_sp,
 	MDOC__U,
+	MDOC_Ta,
 	MDOC_MAX
 };
 
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.140
retrieving revision 1.141
diff -Lmdoc.c -Lmdoc.c -u -p -r1.140 -r1.141
--- mdoc.c
+++ mdoc.c
@@ -69,7 +69,7 @@ const	char *const __mdoc_macronames[MDOC
 	/* LINTED */
 	"Dx",		"%Q",		"br",		"sp",
 	/* LINTED */
-	"%U"
+	"%U",		"Ta"
 	};
 
 const	char *const __mdoc_argnames[MDOC_ARG_MAX] = {		 
Index: mdoc_argv.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_argv.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -Lmdoc_argv.c -Lmdoc_argv.c -u -p -r1.50 -r1.51
--- mdoc_argv.c
+++ mdoc_argv.c
@@ -210,6 +210,7 @@ static	int mdoc_argflags[MDOC_MAX] = {
 	0, /* br */
 	0, /* sp */
 	0, /* %U */
+	0, /* Ta */
 };
 
 
@@ -347,6 +348,13 @@ mdoc_args(struct mdoc *m, int line, int 
 	if (MDOC_It != tok)
 		return(args(m, line, pos, buf, fl, v));
 
+	/*
+	 * We know that we're in an `It', so it's reasonable to expect
+	 * us to be sitting in a `Bl'.  Someday this may not be the case
+	 * (if we allow random `It's sitting out there), so provide a
+	 * safe fall-back into the default behaviour.
+	 */
+
 	for (n = m->last; n; n = n->parent)
 		if (MDOC_Bl == n->tok)
 			break;
@@ -455,7 +463,7 @@ args(struct mdoc *m, int line, int *pos,
 					break;
 				if (pp > *v && ' ' != *(pp - 1))
 					continue;
-				if (' ' == *(pp + 2) || 0 == *(pp + 2))
+				if (' ' == *(pp + 2) || '\0' == *(pp + 2))
 					break;
 			}
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-05-31 10:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-31 10:28 mdocml: Remove enum mdocargerr from phrase() (unused) kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).