source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Add a "last child" member of struct mdoc_node.
@ 2010-12-15 23:39 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-12-15 23:39 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add a "last child" member of struct mdoc_node.

Remove `Pp' or `Lp' if it is the FIRST or LAST child of an `Sh' or `Sh' body.

Make "skipping paragraph" be an error, not a warning, as information (an
invoked macro) is ignored.

Modified Files:
--------------
    mdocml:
        main.c
        mandoc.h
        mdoc.c
        mdoc.h
        mdoc_macro.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.139
retrieving revision 1.140
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.139 -r1.140
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -107,6 +107,7 @@ static	int	 post_it(POST_ARGS);
 static	int	 post_lb(POST_ARGS);
 static	int	 post_nm(POST_ARGS);
 static	int	 post_os(POST_ARGS);
+static	int	 post_ignpar(POST_ARGS);
 static	int	 post_prol(POST_ARGS);
 static	int	 post_root(POST_ARGS);
 static	int	 post_rs(POST_ARGS);
@@ -150,9 +151,9 @@ static	v_post	 posts_nm[] = { post_nm, N
 static	v_post	 posts_notext[] = { ewarn_eq0, NULL };
 static	v_post	 posts_os[] = { post_os, post_prol, NULL };
 static	v_post	 posts_rs[] = { berr_ge1, herr_eq0, post_rs, NULL };
-static	v_post	 posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL };
+static	v_post	 posts_sh[] = { post_ignpar, herr_ge1, bwarn_ge1, post_sh, NULL };
 static	v_post	 posts_sp[] = { eerr_le1, NULL };
-static	v_post	 posts_ss[] = { herr_ge1, NULL };
+static	v_post	 posts_ss[] = { post_ignpar, herr_ge1, bwarn_ge1, NULL };
 static	v_post	 posts_st[] = { eerr_eq1, post_st, NULL };
 static	v_post	 posts_std[] = { post_std, NULL };
 static	v_post	 posts_text[] = { eerr_ge1, NULL };
@@ -894,10 +895,6 @@ pre_it(PRE_ARGS)
 	if (MDOC_BLOCK != n->type)
 		return(1);
 
-	/* 
-	 * FIXME: this can probably be lifted if we make the It into
-	 * something else on-the-fly?
-	 */
 	return(check_parent(mdoc, n, MDOC_Bl, MDOC_BODY));
 }
 
@@ -1878,6 +1875,29 @@ post_sh_head(POST_ARGS)
 	default:
 		break;
 	}
+
+	return(1);
+}
+
+static int
+post_ignpar(POST_ARGS)
+{
+	struct mdoc_node *np;
+
+	if (MDOC_BODY != mdoc->last->type)
+		return(1);
+
+	if (NULL != (np = mdoc->last->child))
+		if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) {
+			mdoc_nmsg(mdoc, np, MANDOCERR_IGNPAR);
+			mdoc_node_delete(mdoc, np);
+		}
+
+	if (NULL != (np = mdoc->last->last))
+		if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) {
+			mdoc_nmsg(mdoc, np, MANDOCERR_IGNPAR);
+			mdoc_node_delete(mdoc, np);
+		}
 
 	return(1);
 }
Index: mdoc_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_macro.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.98 -r1.99
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -252,6 +252,7 @@ lookup_raw(const char *p)
 static int
 rew_last(struct mdoc *mdoc, const struct mdoc_node *to)
 {
+	struct mdoc_node *n;
 
 	assert(to);
 	mdoc->next = MDOC_NEXT_SIBLING;
@@ -260,8 +261,10 @@ rew_last(struct mdoc *mdoc, const struct
 	while (mdoc->last != to) {
 		if ( ! mdoc_valid_post(mdoc))
 			return(0);
+		n = mdoc->last;
 		mdoc->last = mdoc->last->parent;
 		assert(mdoc->last);
+		mdoc->last->last = n;
 	}
 
 	return(mdoc_valid_post(mdoc));
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.106
retrieving revision 1.107
diff -Lmdoc.h -Lmdoc.h -u -p -r1.106 -r1.107
--- mdoc.h
+++ mdoc.h
@@ -371,6 +371,7 @@ union mdoc_data {
 struct	mdoc_node {
 	struct mdoc_node *parent; /* parent AST node */
 	struct mdoc_node *child; /* first child AST node */
+	struct mdoc_node *last; /* last child AST node */
 	struct mdoc_node *next; /* sibling AST node */
 	struct mdoc_node *prev; /* prior sibling AST node */
 	int		  nchild; /* number children */
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.168
retrieving revision 1.169
diff -Lmdoc.c -Lmdoc.c -u -p -r1.168 -r1.169
--- mdoc.c
+++ mdoc.c
@@ -552,6 +552,8 @@ mdoc_node_unlink(struct mdoc *m, struct 
 		n->parent->nchild--;
 		if (n->parent->child == n)
 			n->parent->child = n->prev ? n->prev : n->next;
+		if (n->parent->last == n)
+			n->parent->last = n->prev ? n->prev : NULL;
 	}
 
 	/* Adjust parse point, if applicable. */
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -Lmandoc.h -Lmandoc.h -u -p -r1.33 -r1.34
--- mandoc.h
+++ mandoc.h
@@ -67,7 +67,6 @@ enum	mandocerr {
 
 	/* related to macros and nesting */
 	MANDOCERR_MACROOBS, /* skipping obsolete macro */
-	MANDOCERR_IGNPAR, /* skipping paragraph macro */
 	MANDOCERR_SCOPENEST, /* blocks badly nested */
 	MANDOCERR_CHILD, /* child violates parent syntax */
 	MANDOCERR_NESTEDDISP, /* nested displays are not portable */
@@ -105,6 +104,7 @@ enum	mandocerr {
 	MANDOCERR_BADCHAR, /* skipping bad character */
 	MANDOCERR_NOTEXT, /* skipping text before the first section header */
 	MANDOCERR_MACRO, /* skipping unknown macro */
+	MANDOCERR_IGNPAR, /* skipping paragraph macro */
 	MANDOCERR_REQUEST, /* NOT IMPLEMENTED: skipping request */
 	MANDOCERR_LINESCOPE, /* line scope broken */
 	MANDOCERR_ARGCOUNT, /* argument count wrong */
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.122
retrieving revision 1.123
diff -Lmain.c -Lmain.c -u -p -r1.122 -r1.123
--- main.c
+++ main.c
@@ -145,7 +145,6 @@ static	const char * const	mandocerrs[MAN
 
 	/* related to macros and nesting */
 	"skipping obsolete macro",
-	"skipping paragraph macro",
 	"blocks badly nested",
 	"child violates parent syntax",
 	"nested displays are not portable",
@@ -183,6 +182,7 @@ static	const char * const	mandocerrs[MAN
 	"skipping bad character",
 	"skipping text before the first section header",
 	"skipping unknown macro",
+	"skipping paragraph macro",
 	"NOT IMPLEMENTED: skipping request",
 	"line scope broken",
 	"argument count wrong",
--
 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-12-15 23:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-15 23:39 mdocml: Add a "last child" member of struct mdoc_node 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).