source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Add matrix support.
@ 2011-07-23 12:01 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-07-23 12:01 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add matrix support.  Also remove "above" notion, as all elements in a
list are delimited by their "aboveness" and it's superfluous.

Modified Files:
--------------
    mdocml:
        eqn.7
        eqn.c
        eqn_term.c
        mandoc.h
        tree.c

Revision Data
-------------
Index: eqn.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -Leqn.c -Leqn.c -u -p -r1.31 -r1.32
--- eqn.c
+++ eqn.c
@@ -144,6 +144,7 @@ static	int		 eqn_do_set(struct eqn_node 
 static	int		 eqn_do_undef(struct eqn_node *);
 static	enum eqn_rest	 eqn_eqn(struct eqn_node *, struct eqn_box *);
 static	enum eqn_rest	 eqn_list(struct eqn_node *, struct eqn_box *);
+static	enum eqn_rest	 eqn_matrix(struct eqn_node *, struct eqn_box *);
 static	const char	*eqn_nexttok(struct eqn_node *, size_t *);
 static	const char	*eqn_nextrawtok(struct eqn_node *, size_t *);
 static	const char	*eqn_next(struct eqn_node *, 
@@ -191,6 +192,9 @@ static	const struct eqnstr eqnpiles[EQNP
 	{ "cpile", 5 }, /* EQNPILE_CPILE */
 	{ "rpile", 5 }, /* EQNPILE_RPILE */
 	{ "lpile", 5 }, /* EQNPILE_LPILE */
+	{ "ccol", 4 }, /* EQNPILE_CCOL */
+	{ "rcol", 4 }, /* EQNPILE_RCOL */
+	{ "lcol", 4 }, /* EQNPILE_LCOL */
 };
 
 static	const struct eqnsym eqnsyms[EQNSYM__MAX] = {
@@ -348,6 +352,55 @@ eqn_eqn(struct eqn_node *ep, struct eqn_
 }
 
 static enum eqn_rest
+eqn_matrix(struct eqn_node *ep, struct eqn_box *last)
+{
+	struct eqn_box	*bp;
+	const char	*start;
+	size_t		 sz;
+	enum eqn_rest	 c;
+
+	bp = eqn_box_alloc(ep, last);
+	bp->type = EQN_MATRIX;
+
+	if (NULL == (start = eqn_nexttok(ep, &sz))) {
+		EQN_MSG(MANDOCERR_EQNEOF, ep);
+		return(EQN_ERR);
+	}
+	if ( ! STRNEQ(start, sz, "{", 1)) {
+		EQN_MSG(MANDOCERR_EQNSYNT, ep);
+		return(EQN_ERR);
+	}
+
+	while (EQN_OK == (c = eqn_box(ep, bp)))
+		switch (bp->last->pile) {
+		case (EQNPILE_LCOL):
+			/* FALLTHROUGH */
+		case (EQNPILE_CCOL):
+			/* FALLTHROUGH */
+		case (EQNPILE_RCOL):
+			continue;
+		default:
+			EQN_MSG(MANDOCERR_EQNSYNT, ep);
+			return(EQN_ERR);
+		};
+
+	if (EQN_DESCOPE != c) {
+		if (EQN_EOF == c)
+			EQN_MSG(MANDOCERR_EQNEOF, ep);
+		return(EQN_ERR);
+	}
+
+	eqn_rewind(ep);
+	start = eqn_nexttok(ep, &sz);
+	assert(start);
+	if (STRNEQ(start, sz, "}", 1))
+		return(EQN_OK);
+
+	EQN_MSG(MANDOCERR_EQNBADSCOPE, ep);
+	return(EQN_ERR);
+}
+
+static enum eqn_rest
 eqn_list(struct eqn_node *ep, struct eqn_box *last)
 {
 	struct eqn_box	*bp;
@@ -373,7 +426,6 @@ eqn_list(struct eqn_node *ep, struct eqn
 		assert(start);
 		if ( ! STRNEQ(start, sz, "above", 5))
 			break;
-		bp->last->above = 1;
 	}
 
 	if (EQN_DESCOPE != c) {
@@ -441,6 +493,9 @@ eqn_box(struct eqn_node *ep, struct eqn_
 			last->last->pile = (enum eqn_pilet)i;
 		return(c);
 	}
+
+	if (STRNEQ(start, sz, "matrix", 6))
+		return(eqn_matrix(ep, last));
 
 	if (STRNEQ(start, sz, "left", 4)) {
 		if (NULL == (start = eqn_nexttok(ep, &sz))) {
Index: eqn_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn_term.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -Leqn_term.c -Leqn_term.c -u -p -r1.1 -r1.2
--- eqn_term.c
+++ eqn_term.c
@@ -61,8 +61,6 @@ static void
 eqn_box_pre(struct termp *p, const struct eqn_box *bp)
 {
 
-	if (EQN_LIST == bp->type)
-		term_word(p, "{");
 	if (bp->left)
 		term_word(p, bp->left);
 }
@@ -71,12 +69,8 @@ static void
 eqn_box_post(struct termp *p, const struct eqn_box *bp)
 {
 
-	if (EQN_LIST == bp->type)
-		term_word(p, "}");
 	if (bp->right)
 		term_word(p, bp->right);
-	if (bp->above)
-		term_word(p, "|");
 }
 
 static void
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.91
retrieving revision 1.92
diff -Lmandoc.h -Lmandoc.h -u -p -r1.91 -r1.92
--- mandoc.h
+++ mandoc.h
@@ -285,7 +285,8 @@ enum	eqn_boxt {
 	EQN_ROOT, /* root of parse tree */
 	EQN_TEXT, /* text (number, variable, whatever) */
 	EQN_SUBEXPR, /* nested `eqn' subexpression */
-	EQN_LIST /* list of subexpressions */
+	EQN_LIST, /* subexpressions list */
+	EQN_MATRIX /* matrix subexpression */
 };
 
 enum	eqn_markt {
@@ -324,6 +325,9 @@ enum	eqn_pilet {
 	EQNPILE_CPILE,
 	EQNPILE_RPILE,
 	EQNPILE_LPILE,
+	EQNPILE_CCOL,
+	EQNPILE_RCOL,
+	EQNPILE_LCOL,
 	EQNPILE__MAX
 };
 
@@ -346,7 +350,6 @@ struct	eqn_box {
 	enum eqn_markt	  mark; /* a mark about the box */
 	enum eqn_fontt	  font; /* font of box */
 	enum eqn_pilet	  pile; /* equation piling */
-	int		  above; /* next node is above */
 };
 
 /*
Index: eqn.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.7,v
retrieving revision 1.19
retrieving revision 1.20
diff -Leqn.7 -Leqn.7 -u -p -r1.19 -r1.20
--- eqn.7
+++ eqn.7
@@ -72,16 +72,18 @@ box     : text
         | \*qundef\*q text
         | box pos box
         | box mark
+        | \*qmatrix\*q \*q{\*q [col \*q{\*q list \*q}\*q ]*
         | pile \*q{\*q list \*q}\*q
         | font box
         | \*qsize\*q text box
         | \*qleft\*q text eqn [\*qright\*q text]
+col     : \*qlcol\*q | \*qrcol\*q | \*qccol\*q
 text    : [^space\e\*q]+ | \e\*q.*\e\*q
 pile    : \*qlpile\*q | \*qcpile\*q | \*qrpile\*q
 pos     : \*qover\*q | \*qsup\*q | \*qsub\*q | \*qto\*q | \*qfrom\*q
 mark	: \*qdot\*q | \*qdotdot\*q | \*qhat\*q | \*qtilde\*q | \*qvec\*q
         | \*qdyad\*q | \*qbar\*q | \*qunder\*q
-font    : \*qroman\*q | \*qitalic\*q | \*\*qbold\*q
+font    : \*qroman\*q | \*qitalic\*q | \*qbold\*q
 list    : eqn
         | list \*qabove\*q eqn
 space   : [\e^~ \et]
Index: tree.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/tree.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -Ltree.c -Ltree.c -u -p -r1.45 -r1.46
--- tree.c
+++ tree.c
@@ -263,46 +263,41 @@ static void
 print_box(const struct eqn_box *ep, int indent)
 {
 	int		 i;
+	const char	*t;
 
 	if (NULL == ep)
 		return;
 	for (i = 0; i < indent; i++)
 		putchar('\t');
 
+	t = NULL;
 	switch (ep->type) {
 	case (EQN_ROOT):
-		printf("eqn-root(%d, %d, %d, %d)\n", 
-			EQN_DEFSIZE == ep->size ? 0 : ep->size,
-			ep->pos, ep->font, ep->mark);
-		print_box(ep->first, indent + 1);
+		t = "eqn-root";
 		break;
 	case (EQN_LIST):
-		printf("eqn-list(%d, %d, %d, %d, %d, %d, \"%s\", \"%s\")\n", 
-			EQN_DEFSIZE == ep->size ? 0 : ep->size,
-			ep->pos, ep->font, ep->mark,
-			ep->pile, ep->above,
-			ep->left ? ep->left : "",
-			ep->right ? ep->right : "");
-		print_box(ep->first, indent + 1);
+		t = "eqn-list";
 		break;
 	case (EQN_SUBEXPR):
-		printf("eqn-subxpr(%d, %d, %d, %d, %d, %d, \"%s\", \"%s\")\n", 
-			EQN_DEFSIZE == ep->size ? 0 : ep->size,
-			ep->pos, ep->font, ep->mark,
-			ep->pile, ep->above,
-			ep->left ? ep->left : "",
-			ep->right ? ep->right : "");
-		print_box(ep->first, indent + 1);
+		t = "eqn-expr";
 		break;
 	case (EQN_TEXT):
-		printf("eqn-text(%d, %d, %d, %d): [%s]\n", 
-			EQN_DEFSIZE == ep->size ? 0 : ep->size,
-			ep->pos, ep->font, ep->mark, ep->text);
+		t = "eqn-text";
 		break;
-	default:
+	case (EQN_MATRIX):
+		t = "eqn-matrix";
 		break;
 	}
 
+	assert(t);
+	printf("%s(%d, %d, %d, %d, %d, \"%s\", \"%s\") %s\n", 
+		t, EQN_DEFSIZE == ep->size ? 0 : ep->size,
+		ep->pos, ep->font, ep->mark, ep->pile, 
+		ep->left ? ep->left : "",
+		ep->right ? ep->right : "",
+		ep->text ? ep->text : "");
+
+	print_box(ep->first, indent + 1);
 	print_box(ep->next, indent);
 }
 
--
 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:[~2011-07-23 12:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-23 12:01 mdocml: Add matrix support 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).