diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-07-21 13:18:24 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-07-21 13:18:24 +0000 |
commit | d98b3838b2d49efc6220b1dc7bdb995e37cd4d10 (patch) | |
tree | 78b6d8a9ac3e4bf00688322b73cc0728f1ee1fa1 | |
parent | 5bbaf34f67268b1270c7dd46448c7cf7556805f8 (diff) | |
download | mandoc-d98b3838b2d49efc6220b1dc7bdb995e37cd4d10.tar.gz |
Add support for markers. These decorate the last box: see eqn.7.
-rw-r--r-- | eqn.7 | 11 | ||||
-rw-r--r-- | eqn.c | 38 | ||||
-rw-r--r-- | mandoc.h | 14 | ||||
-rw-r--r-- | tree.c | 6 |
4 files changed, 60 insertions, 9 deletions
@@ -63,11 +63,20 @@ The equation grammar is as follows: .Bd -literal -offset indent eqn : box | eqn box box : text - | { eqn } + | { eqn } | DEFINE text text | SET text text | UNDEF text + | box mark text : TEXT +mark : DOT + | DOTDOT + | HAT + | TILDE + | VEC + | DYAD + | BAR + | UNDER .Ed .Pp Data in TEXT form is a non-empty sequence of non-space characters or a @@ -37,6 +37,11 @@ struct eqnpart { int (*fp)(struct eqn_node *); }; +struct eqnmark { + const char *name; + size_t sz; +}; + enum eqnpartt { EQN_DEFINE = 0, EQN_SET, @@ -63,6 +68,18 @@ static const struct eqnpart eqnparts[EQN__MAX] = { { "undef", 5, eqn_do_undef }, /* EQN_UNDEF */ }; +static const struct eqnmark eqnmarks[EQNMARK__MAX] = { + { "", 0 }, /* EQNMARK_NONE */ + { "dot", 3 }, /* EQNMARK_DOT */ + { "dotdot", 6 }, /* EQNMARK_DOTDOT */ + { "hat", 3 }, /* EQNMARK_HAT */ + { "tilde", 5 }, /* EQNMARK_TILDE */ + { "vec", 3 }, /* EQNMARK_VEC */ + { "dyad", 4 }, /* EQNMARK_DYAD */ + { "bar", 3 }, /* EQNMARK_BAR */ + { "under", 5 }, /* EQNMARK_UNDER */ +}; + /* ARGSUSED */ enum rofferr eqn_read(struct eqn_node **epp, int ln, @@ -139,13 +156,15 @@ eqn_end(struct eqn_node *ep) * Otherwise, return the equation. */ - if ((c = eqn_box(ep, root, &last)) > 0) { + if (0 == (c = eqn_box(ep, root, &last))) { + if (last != root) { + EQN_MSG(MANDOCERR_EQNSCOPE, ep); + c = 0; + } + } else if (c > 0) EQN_MSG(MANDOCERR_EQNNSCOPE, ep); - c = 0; - } else if (0 == c && last != root) - EQN_MSG(MANDOCERR_EQNSCOPE, ep); - return(1 == c ? ROFF_EQN : ROFF_IGN); + return(0 == c ? ROFF_EQN : ROFF_IGN); } static int @@ -179,6 +198,15 @@ again: goto again; } + for (i = 0; i < (int)EQNMARK__MAX; i++) { + if (eqnmarks[i].sz != sz) + continue; + if (strncmp(eqnmarks[i].name, start, sz)) + continue; + last->mark = (enum eqn_markt)i; + goto again; + } + /* Exit this [hopefully] subexpression. */ if (sz == 1 && 0 == strncmp("}", start, 1)) @@ -285,6 +285,19 @@ enum eqn_boxt { EQN_SUBEXPR /* nested subexpression */ }; +enum eqn_markt { + EQNMARK_NONE = 0, + EQNMARK_DOT, + EQNMARK_DOTDOT, + EQNMARK_HAT, + EQNMARK_TILDE, + EQNMARK_VEC, + EQNMARK_DYAD, + EQNMARK_BAR, + EQNMARK_UNDER, + EQNMARK__MAX +}; + /* * A "box" is a parsed mathematical expression as defined by the eqn.7 * grammar. @@ -294,6 +307,7 @@ struct eqn_box { struct eqn_box *child; /* child node */ struct eqn_box *next; /* next in tree */ char *text; /* text (or NULL) */ + enum eqn_markt mark; /* whether 'marked' */ }; struct eqn { @@ -270,15 +270,15 @@ print_box(const struct eqn_box *ep, int indent) switch (ep->type) { case (EQN_ROOT): - puts("eqn-root"); + printf("eqn-root(%d)\n", ep->mark); print_box(ep->child, indent + 1); break; case (EQN_SUBEXPR): - puts("eqn-subxpr"); + printf("eqn-subxpr(%d)\n", ep->mark); print_box(ep->child, indent + 1); break; case (EQN_TEXT): - printf("eqn-text: [%s]\n", ep->text); + printf("eqn-text(%d): [%s]\n", ep->mark, ep->text); break; default: break; |