=================================================================== RCS file: /cvs/mandoc/mandoc.h,v retrieving revision 1.77 retrieving revision 1.87 diff -u -p -r1.77 -r1.87 --- mandoc/mandoc.h 2011/05/24 21:31:23 1.77 +++ mandoc/mandoc.h 2011/07/21 14:13:00 1.87 @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.77 2011/05/24 21:31:23 kristaps Exp $ */ +/* $Id: mandoc.h,v 1.87 2011/07/21 14:13:00 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * @@ -104,8 +104,17 @@ enum mandocerr { MANDOCERR_BADESCAPE, /* unknown escape sequence */ MANDOCERR_BADQUOTE, /* unterminated quoted string */ + /* related to equations */ + MANDOCERR_EQNQUOTE, /* unexpected literal in equation */ + MANDOCERR_ERROR, /* ===== start of errors ===== */ + /* related to equations */ + MANDOCERR_EQNARGS, /* bad equation macro arguments */ + MANDOCERR_EQNNEST, /* too many nested equation defines */ + MANDOCERR_EQNNSCOPE, /* unexpected equation scope closure*/ + MANDOCERR_EQNSCOPE, /* equation scope open on exit */ + /* related to tables */ MANDOCERR_TBL, /* bad table syntax */ MANDOCERR_TBLOPT, /* bad table option */ @@ -270,10 +279,65 @@ struct tbl_span { struct tbl_span *next; }; +enum eqn_boxt { + EQN_ROOT, /* root of parse tree */ + EQN_TEXT, /* text (number, variable, whatever) */ + 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 +}; + +enum eqn_fontt { + EQNFONT_NONE = 0, + EQNFONT_ROMAN, + EQNFONT_BOLD, + EQNFONT_ITALIC, + EQNFONT__MAX +}; + +enum eqn_post { + EQNPOS_NONE = 0, + EQNPOS_OVER, + EQNPOS_SUP, + EQNPOS_SUB, + EQNPOS_TO, + EQNPOS_FROM, + EQNPOS_ABOVE, + EQNPOS__MAX +}; + + /* + * A "box" is a parsed mathematical expression as defined by the eqn.7 + * grammar. + */ +struct eqn_box { + enum eqn_boxt type; /* type of node */ + struct eqn_box *child; /* child node */ + struct eqn_box *next; /* next in tree */ + enum eqn_post pos; /* position of next box */ + char *text; /* text (or NULL) */ + enum eqn_markt mark; /* a mark about the box */ + enum eqn_fontt font; /* font of box */ +}; + +/* + * An equation consists of a tree of expressions starting at a given + * line and position. + */ struct eqn { - size_t sz; - char *data; - int line; /* invocation line */ + struct eqn_box *root; /* root mathematical expression */ + int ln; /* invocation line */ int pos; /* invocation position */ }; @@ -324,6 +388,7 @@ const char *mparse_strlevel(enum mandoclevel); void *mandoc_calloc(size_t, size_t); void *mandoc_malloc(size_t); void *mandoc_realloc(void *, size_t); +char *mandoc_strdup(const char *); enum mandoc_esc mandoc_escape(const char **, const char **, int *);