diff options
-rw-r--r-- | eqn.7 | 4 | ||||
-rw-r--r-- | eqn.c | 57 | ||||
-rw-r--r-- | eqn_term.c | 6 | ||||
-rw-r--r-- | mandoc.h | 7 | ||||
-rw-r--r-- | tree.c | 39 |
5 files changed, 81 insertions, 32 deletions
@@ -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] @@ -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[EQNPILE__MAX] = { { "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_box *last) } 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_box *last) assert(start); if ( ! STRNEQ(start, sz, "above", 5)) break; - bp->last->above = 1; } if (EQN_DESCOPE != c) { @@ -442,6 +494,9 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last) 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))) { EQN_MSG(MANDOCERR_EQNEOF, ep); @@ -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 @@ -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 */ }; /* @@ -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); } |