summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eqn.711
-rw-r--r--eqn.c38
-rw-r--r--mandoc.h14
-rw-r--r--tree.c6
4 files changed, 60 insertions, 9 deletions
diff --git a/eqn.7 b/eqn.7
index c9c2e993..a8447f4a 100644
--- a/eqn.7
+++ b/eqn.7
@@ -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
diff --git a/eqn.c b/eqn.c
index 4a884406..7e2eff80 100644
--- a/eqn.c
+++ b/eqn.c
@@ -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))
diff --git a/mandoc.h b/mandoc.h
index eecaeefd..eabbf58b 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -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 {
diff --git a/tree.c b/tree.c
index e83a5bce..82bb0a06 100644
--- a/tree.c
+++ b/tree.c
@@ -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;