1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* File: math_parser.C
|
|
|
|
* Purpose: Parser for mathed
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description: Parse LaTeX2e math mode code.
|
|
|
|
*
|
|
|
|
* Dependencies: Xlib, XForms
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* Version: 0.8beta.
|
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2000-09-26 13:54:57 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
#include <cctype>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
2001-02-13 13:28:32 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_parser.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "array.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_inset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_arrayinset.h"
|
2001-08-06 17:20:26 +00:00
|
|
|
#include "math_bigopinset.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
#include "math_charinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_dotsinset.h"
|
|
|
|
#include "math_decorationinset.h"
|
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_funcinset.h"
|
2001-08-06 17:20:26 +00:00
|
|
|
#include "math_funcliminset.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_macro.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
#include "math_macrotable.h"
|
|
|
|
#include "math_macrotemplate.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_matrixinset.h"
|
2001-08-09 15:19:31 +00:00
|
|
|
#include "math_noglyphinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_rootinset.h"
|
2001-07-12 07:18:29 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_sizeinset.h"
|
|
|
|
#include "math_spaceinset.h"
|
|
|
|
#include "math_sqrtinset.h"
|
2001-08-08 17:26:30 +00:00
|
|
|
#include "math_stackrelinset.h"
|
2001-08-06 17:20:26 +00:00
|
|
|
#include "math_symbolinset.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "mathed/support.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "lyxlex.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::istream;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2000-11-02 04:48:34 +00:00
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
namespace {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
MathScriptInset * prevScriptInset(MathArray const & array)
|
|
|
|
{
|
|
|
|
MathInset * p = array.back();
|
|
|
|
return (p && p->isScriptInset()) ? static_cast<MathScriptInset *>(p) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * lastScriptInset(MathArray & array, bool up, bool down, int limits)
|
|
|
|
{
|
|
|
|
MathScriptInset * p = prevScriptInset(array);
|
|
|
|
if (!p) {
|
|
|
|
MathInset * b = array.back();
|
|
|
|
if (b && b->isScriptable()) {
|
|
|
|
p = new MathScriptInset(up, down, b->clone());
|
|
|
|
array.pop_back();
|
|
|
|
} else {
|
|
|
|
p = new MathScriptInset(up, down);
|
|
|
|
}
|
|
|
|
array.push_back(p);
|
|
|
|
}
|
|
|
|
if (up)
|
|
|
|
p->up(true);
|
|
|
|
if (down)
|
|
|
|
p->down(down);
|
|
|
|
if (limits)
|
|
|
|
p->limits(limits);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
// These are lexical codes, not semantic
|
|
|
|
enum lexcode_enum {
|
|
|
|
LexNone,
|
|
|
|
LexESC,
|
|
|
|
LexAlpha,
|
|
|
|
LexBOP, // Binary operators or relations
|
|
|
|
LexOpen,
|
|
|
|
LexClose,
|
|
|
|
LexComment,
|
|
|
|
LexArgument,
|
|
|
|
LexSpace,
|
|
|
|
LexNewLine,
|
|
|
|
LexOther,
|
2001-07-26 16:56:23 +00:00
|
|
|
LexMath,
|
2001-06-25 00:06:33 +00:00
|
|
|
LexSelf
|
|
|
|
};
|
|
|
|
|
|
|
|
lexcode_enum lexcode[256];
|
|
|
|
|
|
|
|
|
2001-07-04 17:15:08 +00:00
|
|
|
const unsigned char LM_TK_OPEN = '{';
|
|
|
|
const unsigned char LM_TK_CLOSE = '}';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
enum {
|
2001-06-25 00:06:33 +00:00
|
|
|
FLAG_BRACE = 1 << 0, // A { needed //}
|
2001-07-13 09:10:59 +00:00
|
|
|
FLAG_BRACE_LAST = 1 << 1, // // { Last } ends the parsing process
|
|
|
|
FLAG_RIGHT = 1 << 2, // Next right ends the parsing process
|
|
|
|
FLAG_END = 1 << 3, // Next end ends the parsing process
|
|
|
|
FLAG_BRACE_FONT = 1 << 4, // // { Next } closes a font
|
|
|
|
FLAG_BRACK_END = 1 << 5, // // [ Next ] ends the parsing process
|
|
|
|
FLAG_AMPERSAND = 1 << 6, // Next & ends the parsing process
|
|
|
|
FLAG_NEWLINE = 1 << 7, // Next \\ ends the parsing process
|
|
|
|
FLAG_ITEM = 1 << 8, // read a (possibly braced token)
|
|
|
|
FLAG_LEAVE = 1 << 9, // marker for leaving the
|
|
|
|
FLAG_OPTARG = 1 << 10 // reads an argument in []
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
struct latex_mathenv_type {
|
|
|
|
char const * name;
|
|
|
|
char const * basename;
|
|
|
|
MathInsetTypes typ;
|
|
|
|
bool numbered;
|
|
|
|
bool ams;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
latex_mathenv_type latex_mathenv[] = {
|
|
|
|
{"math", "math", LM_OT_SIMPLE, 0, 0},
|
|
|
|
{"equation*", "equation", LM_OT_EQUATION, 0, 0},
|
|
|
|
{"equation", "equation", LM_OT_EQUATION, 1, 0},
|
|
|
|
{"eqnarray*", "eqnarray", LM_OT_EQNARRAY, 0, 0},
|
|
|
|
{"eqnarray", "eqnarray", LM_OT_EQNARRAY, 1, 0},
|
|
|
|
{"align*", "align", LM_OT_ALIGN, 0, 1},
|
|
|
|
{"align", "align", LM_OT_ALIGN, 1, 1},
|
|
|
|
{"alignat*", "alignat", LM_OT_ALIGNAT, 0, 1},
|
|
|
|
{"alignat", "alignat", LM_OT_ALIGNAT, 1, 1},
|
|
|
|
{"multline*", "multline", LM_OT_MULTLINE, 0, 1},
|
|
|
|
{"multline", "multline", LM_OT_MULTLINE, 1, 1},
|
|
|
|
{"array", "array", LM_OT_MATRIX, 0, 1}
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int const latex_mathenv_num = sizeof(latex_mathenv)/sizeof(latex_mathenv[0]);
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
void lexInit()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
for (int i = 0; i <= 255; ++i) {
|
2001-07-04 17:15:08 +00:00
|
|
|
if (isdigit(i))
|
2001-08-10 07:52:04 +00:00
|
|
|
lexcode[i] = LexOther;
|
2001-02-26 12:53:35 +00:00
|
|
|
else if (isspace(i))
|
|
|
|
lexcode[i] = LexSpace;
|
|
|
|
else
|
2001-07-04 17:15:08 +00:00
|
|
|
lexcode[i] = LexAlpha;
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lexcode['\t'] = lexcode['\f'] = lexcode[' '] = LexSpace;
|
|
|
|
lexcode['\n'] = LexNewLine;
|
|
|
|
lexcode['%'] = LexComment;
|
|
|
|
lexcode['#'] = LexArgument;
|
2001-07-26 16:56:23 +00:00
|
|
|
lexcode['$'] = LexMath;
|
2001-02-26 12:53:35 +00:00
|
|
|
lexcode['+'] = lexcode['-'] = lexcode['*'] = lexcode['/']
|
|
|
|
= lexcode['<'] = lexcode['>'] = lexcode['='] = LexBOP;
|
|
|
|
|
|
|
|
lexcode['('] = lexcode[')'] = lexcode['|'] = lexcode['.'] =
|
|
|
|
lexcode['?'] = LexOther;
|
|
|
|
|
|
|
|
lexcode['\''] = lexcode['@'] = LexAlpha;
|
|
|
|
|
|
|
|
lexcode['['] = lexcode[']'] = lexcode['^'] = lexcode['_'] =
|
|
|
|
lexcode['&'] = LexSelf;
|
|
|
|
|
|
|
|
lexcode['\\'] = LexESC;
|
|
|
|
lexcode['{'] = LexOpen;
|
|
|
|
lexcode['}'] = LexClose;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Helper class for parsing
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
class Parser {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
Parser(LyXLex & lex) : is_(lex.getStream()), lineno_(lex.getLineNo()) {}
|
|
|
|
///
|
|
|
|
Parser(istream & is) : is_(is), lineno_(0) {}
|
|
|
|
|
|
|
|
///
|
|
|
|
MathMacroTemplate * parse_macro();
|
|
|
|
///
|
|
|
|
MathMatrixInset * parse_normal();
|
|
|
|
///
|
|
|
|
void parse_into(MathArray & array, unsigned flags);
|
|
|
|
///
|
|
|
|
int lineno() const { return lineno_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
int yylex();
|
|
|
|
///
|
|
|
|
string lexArg(unsigned char lf, bool accept_spaces = false);
|
|
|
|
///
|
|
|
|
unsigned char getuchar();
|
|
|
|
///
|
|
|
|
void error(string const & msg);
|
|
|
|
///
|
|
|
|
void parse_lines(MathGridInset * p, int col, bool numbered, bool outmost);
|
|
|
|
///
|
|
|
|
latexkeys const * read_delim();
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
istream & is_;
|
|
|
|
///
|
|
|
|
int lineno_;
|
|
|
|
|
|
|
|
///
|
|
|
|
int ival_;
|
|
|
|
///
|
|
|
|
latexkeys const * lval_;
|
|
|
|
///
|
|
|
|
string sval_;
|
|
|
|
|
|
|
|
///
|
|
|
|
bool curr_num_;
|
|
|
|
//
|
|
|
|
string curr_label_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char Parser::getuchar()
|
|
|
|
{
|
|
|
|
char c = 0;
|
|
|
|
is_.get(c);
|
|
|
|
if (!is_.good())
|
|
|
|
lyxerr << "The input stream is not well..." << endl;
|
|
|
|
return static_cast<unsigned char>(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string Parser::lexArg(unsigned char lf, bool accept_spaces = false)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-13 07:55:55 +00:00
|
|
|
string result;
|
|
|
|
unsigned char c = 0;
|
2001-08-10 09:30:02 +00:00
|
|
|
while (is_.good()) {
|
|
|
|
c = getuchar();
|
2001-07-13 07:55:55 +00:00
|
|
|
if (!isspace(c))
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
if (c != lf) {
|
2001-08-10 09:30:02 +00:00
|
|
|
is_.putback(c);
|
2001-07-13 07:55:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-07-04 17:15:08 +00:00
|
|
|
unsigned char rg = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
if (lf == '{') rg = '}';
|
|
|
|
if (lf == '[') rg = ']';
|
|
|
|
if (lf == '(') rg = ')';
|
2001-02-26 12:53:35 +00:00
|
|
|
if (!rg) {
|
2001-07-13 07:55:55 +00:00
|
|
|
lyxerr[Debug::MATHED] << "Math parse error: unknown bracket '"
|
|
|
|
<< lf << "'" << endl;
|
|
|
|
return result;
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
int depth = 1;
|
2001-02-26 12:53:35 +00:00
|
|
|
do {
|
2001-08-10 09:30:02 +00:00
|
|
|
unsigned char c = getuchar();
|
2001-07-13 07:55:55 +00:00
|
|
|
if (c == lf)
|
|
|
|
++depth;
|
|
|
|
if (c == rg)
|
|
|
|
--depth;
|
|
|
|
if ((!isspace(c) || (c == ' ' && accept_spaces)) && depth > 0)
|
|
|
|
result += c;
|
2001-08-10 09:30:02 +00:00
|
|
|
} while (depth > 0 && is_.good());
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
int Parser::yylex()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-10 13:17:43 +00:00
|
|
|
static bool init_done = false;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
2001-07-10 13:17:43 +00:00
|
|
|
if (!init_done) {
|
2001-07-13 07:55:55 +00:00
|
|
|
lexInit();
|
2001-07-10 13:17:43 +00:00
|
|
|
init_done = true;
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
while (is_.good()) {
|
|
|
|
unsigned char c = getuchar();
|
2001-07-06 12:09:32 +00:00
|
|
|
//lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
if (lexcode[c] == LexNewLine) {
|
2001-08-10 09:30:02 +00:00
|
|
|
++lineno_;
|
2001-02-26 12:53:35 +00:00
|
|
|
continue;
|
|
|
|
} else if (lexcode[c] == LexComment) {
|
|
|
|
do {
|
2001-08-10 09:30:02 +00:00
|
|
|
c = getuchar();
|
|
|
|
} while (c != '\n' && is_.good()); // eat comments
|
2001-08-10 07:52:04 +00:00
|
|
|
} else if (lexcode[c] == LexOther) {
|
2001-08-10 09:30:02 +00:00
|
|
|
ival_ = c;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_STR;
|
2001-08-03 09:54:48 +00:00
|
|
|
} else if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) {
|
2001-08-10 09:30:02 +00:00
|
|
|
ival_ = c;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_ALPHA;
|
|
|
|
} else if (lexcode[c] == LexBOP) {
|
2001-08-10 09:30:02 +00:00
|
|
|
ival_ = c;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_BOP;
|
2001-07-26 16:56:23 +00:00
|
|
|
} else if (lexcode[c] == LexMath) {
|
2001-08-10 09:30:02 +00:00
|
|
|
ival_ = 0;
|
2001-07-26 16:56:23 +00:00
|
|
|
return LM_TK_MATH;
|
2001-02-26 12:53:35 +00:00
|
|
|
} else if (lexcode[c] == LexSelf) {
|
|
|
|
return c;
|
|
|
|
} else if (lexcode[c] == LexArgument) {
|
2001-08-10 09:30:02 +00:00
|
|
|
c = getuchar();
|
|
|
|
ival_ = c - '0';
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_ARGUMENT;
|
|
|
|
} else if (lexcode[c] == LexOpen) {
|
|
|
|
return LM_TK_OPEN;
|
|
|
|
} else if (lexcode[c] == LexClose) {
|
|
|
|
return LM_TK_CLOSE;
|
|
|
|
} else if (lexcode[c] == LexESC) {
|
2001-08-10 09:30:02 +00:00
|
|
|
c = getuchar();
|
2001-08-09 15:19:31 +00:00
|
|
|
//lyxerr << "reading second byte: '" << c << "' code: " << lexcode[c] << endl;
|
2001-08-09 10:34:43 +00:00
|
|
|
string s;
|
|
|
|
s += c;
|
|
|
|
latexkeys const * l = in_word_set(s);
|
|
|
|
if (l) {
|
2001-08-09 15:19:31 +00:00
|
|
|
//lyxerr << "found key: " << l << endl;
|
|
|
|
//lyxerr << "found key name: " << l->name << endl;
|
|
|
|
//lyxerr << "found key token: " << l->token << endl;
|
2001-08-10 09:30:02 +00:00
|
|
|
lval_ = l;
|
|
|
|
ival_ = l->id;
|
2001-08-09 10:34:43 +00:00
|
|
|
return l->token;
|
2001-07-27 14:50:33 +00:00
|
|
|
}
|
2001-07-12 07:18:29 +00:00
|
|
|
if (lexcode[c] == LexAlpha) {
|
2001-08-10 09:30:02 +00:00
|
|
|
sval_.erase();
|
|
|
|
while (lexcode[c] == LexAlpha && is_.good()) {
|
|
|
|
sval_ += c;
|
|
|
|
c = getuchar();
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
2001-08-10 09:30:02 +00:00
|
|
|
while (lexcode[c] == LexSpace && is_.good())
|
|
|
|
c = getuchar();
|
2001-08-03 17:10:22 +00:00
|
|
|
if (lexcode[c] != LexSpace)
|
2001-08-10 09:30:02 +00:00
|
|
|
is_.putback(c);
|
2001-08-03 09:54:48 +00:00
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
//lyxerr[Debug::MATHED] << "reading: text '" << sval_ << "'\n";
|
|
|
|
//lyxerr << "reading: text '" << sval_ << "'\n";
|
|
|
|
latexkeys const * l = in_word_set(sval_);
|
2001-07-27 12:32:29 +00:00
|
|
|
if (!l)
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_UNDEF;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
|
2001-07-13 07:55:55 +00:00
|
|
|
string name = lexArg('{');
|
2001-06-25 00:06:33 +00:00
|
|
|
int i = 0;
|
2001-07-13 07:55:55 +00:00
|
|
|
while (i < latex_mathenv_num && name != latex_mathenv[i].name)
|
2001-06-25 00:06:33 +00:00
|
|
|
++i;
|
2001-08-10 09:30:02 +00:00
|
|
|
ival_ = i;
|
2001-06-25 00:06:33 +00:00
|
|
|
} else if (l->token == LM_TK_SPACE)
|
2001-08-10 09:30:02 +00:00
|
|
|
ival_ = l->id;
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
2001-08-10 09:30:02 +00:00
|
|
|
lval_ = l;
|
2001-06-25 00:06:33 +00:00
|
|
|
return l->token;
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
void Parser::error(string const & msg)
|
2001-07-26 06:46:50 +00:00
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
void Parser::parse_lines(MathGridInset * p, int col, bool numbered, bool outmost)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-03 07:56:55 +00:00
|
|
|
// save global variables
|
2001-08-10 09:30:02 +00:00
|
|
|
bool const saved_num = curr_num_;
|
|
|
|
string const saved_label = curr_label_;
|
2001-07-03 07:56:55 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
for (int row = 0; true; ++row) {
|
2001-06-25 00:06:33 +00:00
|
|
|
// reset global variables
|
2001-08-10 09:30:02 +00:00
|
|
|
curr_num_ = numbered;
|
|
|
|
curr_label_.erase();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
// reading a row
|
|
|
|
int idx = p->nargs() - p->ncols();
|
|
|
|
for (int i = 0; i < col - 1; ++i, ++idx)
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(p->cell(idx), FLAG_AMPERSAND);
|
|
|
|
parse_into(p->cell(idx), FLAG_NEWLINE | FLAG_END);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
if (outmost) {
|
|
|
|
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
|
2001-08-10 09:30:02 +00:00
|
|
|
m->numbered(row, curr_num_);
|
|
|
|
m->label(row, curr_label_);
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-08-09 10:34:43 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning Hack!
|
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
// no newline
|
2001-08-10 09:30:02 +00:00
|
|
|
if (ival_ != -1)
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
p->appendRow();
|
|
|
|
}
|
2001-07-03 07:56:55 +00:00
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
// restore "global" variables
|
|
|
|
curr_num_ = saved_num;
|
|
|
|
curr_label_ = saved_label;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
MathMacroTemplate * Parser::parse_macro()
|
2001-08-03 09:54:48 +00:00
|
|
|
{
|
|
|
|
if (yylex() != LM_TK_NEWCOMMAND) {
|
|
|
|
lyxerr << "\\newcommand expected\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
string name = lexArg('{').substr(1);
|
|
|
|
string arg = lexArg('[');
|
|
|
|
int narg = arg.empty() ? 0 : atoi(arg.c_str());
|
|
|
|
MathMacroTemplate * p = new MathMacroTemplate(name, narg);
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
|
2001-08-03 09:54:48 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
MathMatrixInset * Parser::parse_normal()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-08-03 09:54:48 +00:00
|
|
|
MathMatrixInset * p = 0;
|
2001-02-26 12:53:35 +00:00
|
|
|
int t = yylex();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
switch (t) {
|
2001-07-26 16:56:23 +00:00
|
|
|
case LM_TK_MATH:
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_TK_BEGIN: {
|
2001-08-10 09:30:02 +00:00
|
|
|
int i = ival_;
|
2001-07-26 16:56:23 +00:00
|
|
|
lyxerr[Debug::MATHED]
|
|
|
|
<< "reading math environment " << i << " "
|
|
|
|
<< latex_mathenv[i].name << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
MathInsetTypes typ = latex_mathenv[i].typ;
|
|
|
|
p = new MathMatrixInset(typ);
|
2001-08-08 17:26:30 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
switch (typ) {
|
|
|
|
|
|
|
|
case LM_OT_SIMPLE: {
|
2001-08-10 09:30:02 +00:00
|
|
|
curr_num_ = latex_mathenv[i].numbered;
|
|
|
|
curr_label_.erase();
|
|
|
|
parse_into(p->cell(0), 0);
|
|
|
|
p->numbered(0, curr_num_);
|
|
|
|
p->label(0, curr_label_);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_EQUATION: {
|
2001-08-10 09:30:02 +00:00
|
|
|
curr_num_ = latex_mathenv[i].numbered;
|
|
|
|
curr_label_.erase();
|
|
|
|
parse_into(p->cell(0), FLAG_END);
|
|
|
|
p->numbered(0, curr_num_);
|
|
|
|
p->label(0, curr_label_);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY: {
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_lines(p, 3, latex_mathenv[i].numbered, true);
|
2001-07-13 07:55:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_ALIGN: {
|
2001-08-08 17:26:30 +00:00
|
|
|
p->halign(lexArg('{'));
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_lines(p, 2, latex_mathenv[i].numbered, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_ALIGNAT: {
|
2001-08-08 17:26:30 +00:00
|
|
|
p->halign(lexArg('{'));
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_lines(p, 2, latex_mathenv[i].numbered, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2001-07-26 16:56:23 +00:00
|
|
|
lyxerr[Debug::MATHED]
|
|
|
|
<< "1: unknown math environment: " << typ << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2001-07-26 16:56:23 +00:00
|
|
|
lyxerr[Debug::MATHED]
|
|
|
|
<< "2 unknown math environment: " << t << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
latexkeys const * Parser::read_delim()
|
2001-08-09 15:19:31 +00:00
|
|
|
{
|
|
|
|
int ld = yylex();
|
2001-08-10 07:52:04 +00:00
|
|
|
//lyxerr << "found symbol: " << ld << "\n";
|
2001-08-09 15:19:31 +00:00
|
|
|
latexkeys const * l = in_word_set(".");
|
|
|
|
switch (ld) {
|
|
|
|
case LM_TK_SYM:
|
|
|
|
case LM_TK_NOGLYPH:
|
|
|
|
case LM_TK_SPECIAL:
|
2001-08-10 09:35:19 +00:00
|
|
|
case LM_TK_BEGIN: {
|
2001-08-10 09:30:02 +00:00
|
|
|
l = lval_;
|
2001-08-10 07:52:04 +00:00
|
|
|
//lyxerr << "found key 1: '" << l << "'\n";
|
|
|
|
//lyxerr << "found key 1: '" << l->name << "'\n";
|
2001-08-09 15:19:31 +00:00
|
|
|
break;
|
2001-08-10 09:35:19 +00:00
|
|
|
}
|
|
|
|
case ']':
|
|
|
|
case '[': {
|
|
|
|
string s;
|
|
|
|
s += ld;
|
|
|
|
l = in_word_set(s);
|
|
|
|
//lyxerr << "found key 2: '" << l->name << "'\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_STR: {
|
2001-08-09 15:19:31 +00:00
|
|
|
string s;
|
2001-08-10 09:30:02 +00:00
|
|
|
s += ival_;
|
2001-08-09 15:19:31 +00:00
|
|
|
l = in_word_set(s);
|
2001-08-10 07:52:04 +00:00
|
|
|
//lyxerr << "found key 2: '" << l->name << "'\n";
|
2001-08-10 09:35:19 +00:00
|
|
|
}
|
2001-08-09 15:19:31 +00:00
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
void Parser::parse_into(MathArray & array, unsigned flags)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-02-26 12:53:35 +00:00
|
|
|
static int plevel = -1;
|
2001-03-09 23:55:50 +00:00
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
++plevel;
|
2001-08-03 09:54:48 +00:00
|
|
|
MathTextCodes yyvarcode = LM_TC_VAR;
|
2001-07-27 12:32:29 +00:00
|
|
|
|
|
|
|
int t = yylex();
|
|
|
|
bool panic = false;
|
|
|
|
int brace = 0;
|
|
|
|
int limits = 0;
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
while (t) {
|
2001-08-10 09:30:02 +00:00
|
|
|
//lyxerr << "t: " << t << " flags: " << flags << " i: " << ival_
|
|
|
|
// << " '" << sval_ << "'\n";
|
2001-04-24 16:13:38 +00:00
|
|
|
//array.dump(lyxerr);
|
|
|
|
//lyxerr << "\n";
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
if (flags & FLAG_ITEM) {
|
|
|
|
flags &= ~FLAG_ITEM;
|
|
|
|
if (t == LM_TK_OPEN) {
|
|
|
|
// skip the brace and regard everything to the next matching
|
|
|
|
// closing brace
|
|
|
|
t = yylex();
|
|
|
|
++brace;
|
|
|
|
flags |= FLAG_BRACE_LAST;
|
|
|
|
} else {
|
|
|
|
// regard only this single token
|
|
|
|
flags |= FLAG_LEAVE;
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
|
2001-08-10 09:30:02 +00:00
|
|
|
error(
|
2001-07-13 07:55:55 +00:00
|
|
|
"Expected {. Maybe you forgot to enclose an argument in {}");
|
|
|
|
panic = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
switch (t) {
|
|
|
|
|
|
|
|
case LM_TK_ALPHA:
|
2001-08-10 09:30:02 +00:00
|
|
|
if (!isspace(ival_) || yyvarcode == LM_TC_TEXTRM)
|
|
|
|
array.push_back(new MathCharInset(ival_, yyvarcode));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
case LM_TK_ARGUMENT: {
|
2001-08-10 09:30:02 +00:00
|
|
|
MathMacroArgument * p = new MathMacroArgument(ival_);
|
2001-08-03 09:54:48 +00:00
|
|
|
p->code(yyvarcode);
|
|
|
|
array.push_back(p);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
2001-08-03 09:54:48 +00:00
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
|
|
case LM_TK_SPECIAL:
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathCharInset(ival_, LM_TC_SPECIAL));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_STR:
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathCharInset(ival_, LM_TC_CONST));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_OPEN:
|
|
|
|
++brace;
|
|
|
|
if (flags & FLAG_BRACE)
|
|
|
|
flags &= ~FLAG_BRACE;
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
2001-08-09 09:19:18 +00:00
|
|
|
array.push_back(new MathCharInset('{', LM_TC_TEX));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_CLOSE:
|
2001-08-02 18:46:53 +00:00
|
|
|
--brace;
|
2001-02-26 12:53:35 +00:00
|
|
|
if (brace < 0) {
|
2001-08-10 09:30:02 +00:00
|
|
|
error("Unmatching braces");
|
2001-02-26 12:53:35 +00:00
|
|
|
panic = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flags & FLAG_BRACE_FONT) {
|
2001-07-03 07:56:55 +00:00
|
|
|
yyvarcode = LM_TC_VAR;
|
2001-02-26 12:53:35 +00:00
|
|
|
flags &= ~FLAG_BRACE_FONT;
|
|
|
|
break;
|
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
if (brace == 0 && (flags & FLAG_BRACE_LAST))
|
|
|
|
flags |= FLAG_LEAVE;
|
|
|
|
else
|
2001-08-09 09:19:18 +00:00
|
|
|
array.push_back(new MathCharInset('}', LM_TC_TEX));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
2001-08-09 09:19:18 +00:00
|
|
|
array.push_back(new MathCharInset('[', LM_TC_CONST));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ']':
|
2001-07-13 07:55:55 +00:00
|
|
|
if (flags & FLAG_BRACK_END)
|
|
|
|
flags |= FLAG_LEAVE;
|
|
|
|
else
|
2001-08-09 09:19:18 +00:00
|
|
|
array.push_back(new MathCharInset(']', LM_TC_CONST));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '^':
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(
|
2001-07-26 06:46:50 +00:00
|
|
|
lastScriptInset(array, true, false, limits)->cell(0), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '_':
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(
|
2001-07-26 06:46:50 +00:00
|
|
|
lastScriptInset(array, false, true, limits)->cell(1), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_LIMIT:
|
2001-08-10 09:30:02 +00:00
|
|
|
limits = lval_->id;
|
2001-07-26 06:46:50 +00:00
|
|
|
//lyxerr << "setting limit to " << limits << "\n";
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case '&':
|
|
|
|
if (flags & FLAG_AMPERSAND) {
|
|
|
|
flags &= ~FLAG_AMPERSAND;
|
|
|
|
--plevel;
|
|
|
|
return;
|
|
|
|
}
|
2001-07-26 06:46:50 +00:00
|
|
|
lyxerr[Debug::MATHED]
|
|
|
|
<< "found tab unexpectedly, array: '" << array << "'\n";
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_NEWLINE:
|
2001-06-25 00:06:33 +00:00
|
|
|
if (flags & FLAG_NEWLINE) {
|
|
|
|
flags &= ~FLAG_NEWLINE;
|
|
|
|
--plevel;
|
|
|
|
return;
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
2001-07-26 06:46:50 +00:00
|
|
|
lyxerr[Debug::MATHED]
|
|
|
|
<< "found newline unexpectedly, array: '" << array << "'\n";
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-26 16:56:23 +00:00
|
|
|
case LM_TK_PROTECT:
|
|
|
|
break;
|
|
|
|
|
2001-08-09 15:19:31 +00:00
|
|
|
case LM_TK_NOGLYPH:
|
|
|
|
case LM_TK_NOGLYPHB:
|
|
|
|
limits = 0;
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathNoglyphInset(lval_));
|
2001-08-09 15:19:31 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
case LM_TK_BIGSYM:
|
2001-08-06 17:20:26 +00:00
|
|
|
limits = 0;
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathBigopInset(lval_));
|
2001-08-06 17:20:26 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-26 13:52:47 +00:00
|
|
|
case LM_TK_FUNCLIM:
|
2001-08-06 17:20:26 +00:00
|
|
|
limits = 0;
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathFuncLimInset(lval_));
|
2001-08-06 17:20:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SYM:
|
2001-07-26 06:46:50 +00:00
|
|
|
limits = 0;
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathSymbolInset(lval_));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_BOP:
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathCharInset(ival_, LM_TC_BOP));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SPACE:
|
2001-08-10 09:30:02 +00:00
|
|
|
if (ival_ >= 0)
|
|
|
|
array.push_back(new MathSpaceInset(ival_));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_DOTS:
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathDotsInset(lval_));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_STACK:
|
2001-08-08 17:26:30 +00:00
|
|
|
{
|
|
|
|
MathStackrelInset * p = new MathStackrelInset;
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(p->cell(0), FLAG_ITEM);
|
|
|
|
parse_into(p->cell(1), FLAG_ITEM);
|
2001-08-08 17:26:30 +00:00
|
|
|
array.push_back(p);
|
2001-04-27 12:35:55 +00:00
|
|
|
break;
|
2001-08-08 17:26:30 +00:00
|
|
|
}
|
2001-04-27 12:35:55 +00:00
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
case LM_TK_FRAC:
|
2001-08-08 17:26:30 +00:00
|
|
|
{
|
|
|
|
MathFracInset * p = new MathFracInset;
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(p->cell(0), FLAG_ITEM);
|
|
|
|
parse_into(p->cell(1), FLAG_ITEM);
|
2001-08-08 17:26:30 +00:00
|
|
|
array.push_back(p);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
2001-08-08 17:26:30 +00:00
|
|
|
}
|
2001-04-27 12:35:55 +00:00
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
case LM_TK_SQRT:
|
2001-07-13 07:55:55 +00:00
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
unsigned char c = getuchar();
|
2001-02-26 12:53:35 +00:00
|
|
|
if (c == '[') {
|
2001-07-12 07:18:29 +00:00
|
|
|
array.push_back(new MathRootInset);
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(array.back()->cell(0), FLAG_BRACK_END);
|
|
|
|
parse_into(array.back()->cell(1), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
} else {
|
2001-08-10 09:30:02 +00:00
|
|
|
is_.putback(c);
|
2001-07-12 07:18:29 +00:00
|
|
|
array.push_back(new MathSqrtInset);
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(array.back()->cell(0), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_LEFT:
|
|
|
|
{
|
2001-08-09 15:19:31 +00:00
|
|
|
latexkeys const * l = read_delim();
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray ar;
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(ar, FLAG_RIGHT);
|
2001-08-09 15:19:31 +00:00
|
|
|
latexkeys const * r = read_delim();
|
|
|
|
MathDelimInset * dl = new MathDelimInset(l, r);
|
2001-07-12 07:18:29 +00:00
|
|
|
dl->cell(0) = ar;
|
2001-06-25 00:06:33 +00:00
|
|
|
array.push_back(dl);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_RIGHT:
|
|
|
|
if (flags & FLAG_RIGHT) {
|
|
|
|
--plevel;
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
2001-08-10 09:30:02 +00:00
|
|
|
error("Unmatched right delimiter");
|
2001-04-24 16:13:38 +00:00
|
|
|
// panic = true;
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_FONT:
|
2001-08-10 09:30:02 +00:00
|
|
|
yyvarcode = static_cast<MathTextCodes>(lval_->id);
|
2001-06-25 00:06:33 +00:00
|
|
|
flags |= (FLAG_BRACE | FLAG_BRACE_FONT);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_TK_STY:
|
|
|
|
{
|
2001-07-08 12:52:16 +00:00
|
|
|
lyxerr[Debug::MATHED] << "LM_TK_STY not implemented\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
//MathArray tmp = array;
|
2001-08-10 09:30:02 +00:00
|
|
|
//MathSizeInset * p = new MathSizeInset(MathStyles(lval_->id));
|
2001-06-25 00:06:33 +00:00
|
|
|
//array.push_back(p);
|
2001-08-10 09:30:02 +00:00
|
|
|
//parse_into(p->cell(0), FLAG_BRACE_FONT);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
case LM_TK_DECORATION:
|
2001-02-26 12:53:35 +00:00
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
MathDecorationInset * p = new MathDecorationInset(lval_);
|
|
|
|
parse_into(p->cell(0), FLAG_ITEM);
|
2001-07-10 13:17:43 +00:00
|
|
|
array.push_back(p);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
|
|
case LM_TK_NONUM:
|
2001-08-10 09:30:02 +00:00
|
|
|
curr_num_ = false;
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_FUNC:
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathSymbolInset(lval_));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_TK_UNDEF:
|
2001-08-10 09:30:02 +00:00
|
|
|
if (MathMacroTable::hasTemplate(sval_)) {
|
|
|
|
MathMacro * m = MathMacroTable::cloneTemplate(sval_);
|
2001-07-06 12:09:32 +00:00
|
|
|
for (int i = 0; i < m->nargs(); ++i)
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_into(m->cell(i), FLAG_ITEM);
|
2001-07-10 13:17:43 +00:00
|
|
|
array.push_back(m);
|
2001-07-26 06:56:43 +00:00
|
|
|
m->metrics(LM_ST_TEXT);
|
2001-06-25 00:06:33 +00:00
|
|
|
} else
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(new MathFuncInset(sval_));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-26 16:56:23 +00:00
|
|
|
case LM_TK_MATH:
|
2001-02-26 12:53:35 +00:00
|
|
|
case LM_TK_END:
|
|
|
|
--plevel;
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
|
|
case LM_TK_BEGIN:
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
int i = ival_;
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInsetTypes typ = latex_mathenv[i].typ;
|
|
|
|
|
|
|
|
if (typ == LM_OT_MATRIX) {
|
2001-08-02 18:46:53 +00:00
|
|
|
string const valign = lexArg('[') + 'c';
|
|
|
|
string const halign = lexArg('{');
|
2001-07-13 07:55:55 +00:00
|
|
|
//lyxerr << "valign: '" << valign << "'\n";
|
|
|
|
//lyxerr << "halign: '" << halign << "'\n";
|
|
|
|
MathArrayInset * m = new MathArrayInset(halign.size(), 1);
|
|
|
|
m->valign(valign[0]);
|
|
|
|
m->halign(halign);
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
parse_lines(m, halign.size(), latex_mathenv[i].numbered, false);
|
2001-07-13 07:55:55 +00:00
|
|
|
array.push_back(m);
|
|
|
|
//lyxerr << "read matrix " << *m << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
} else
|
2001-07-08 12:52:16 +00:00
|
|
|
lyxerr[Debug::MATHED] << "unknow math inset " << typ << "\n";
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
case LM_TK_MACRO:
|
2001-08-10 09:30:02 +00:00
|
|
|
array.push_back(MathMacroTable::cloneTemplate(lval_->name));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_LABEL:
|
2001-08-10 09:30:02 +00:00
|
|
|
curr_label_ = lexArg('{', true);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-08-10 09:30:02 +00:00
|
|
|
error("Unrecognized token");
|
|
|
|
lyxerr[Debug::MATHED] << "[" << t << " " << sval_ << "]" << endl;
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
} // end of big switch
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
if (flags & FLAG_LEAVE) {
|
|
|
|
flags &= ~FLAG_LEAVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
if (panic) {
|
|
|
|
lyxerr << " Math Panic, expect problems!" << endl;
|
|
|
|
// Search for the end command.
|
|
|
|
do {
|
2001-06-25 00:06:33 +00:00
|
|
|
t = yylex();
|
2001-08-10 09:30:02 +00:00
|
|
|
} while (is_.good() && t != LM_TK_END && t);
|
2001-08-02 18:46:53 +00:00
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
t = yylex();
|
2001-08-02 18:46:53 +00:00
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
--plevel;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
void parse_end(LyXLex & lex, int lineno)
|
2001-08-10 07:52:04 +00:00
|
|
|
{
|
|
|
|
// Update line number
|
2001-08-10 09:30:02 +00:00
|
|
|
lex.setLineNo(lineno);
|
2001-08-10 07:52:04 +00:00
|
|
|
|
|
|
|
// reading of end_inset
|
|
|
|
while (lex.isOK()) {
|
|
|
|
lex.nextToken();
|
|
|
|
if (lex.getString() == "\\end_inset")
|
|
|
|
break;
|
|
|
|
lyxerr[Debug::MATHED] << "InsetFormula::Read: Garbage before \\end_inset,"
|
|
|
|
" or missing \\end_inset!" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
2001-07-26 16:14:23 +00:00
|
|
|
|
|
|
|
MathArray mathed_parse_cell(string const & str)
|
|
|
|
{
|
|
|
|
istringstream is(str.c_str());
|
2001-08-10 09:30:02 +00:00
|
|
|
Parser parser(is);
|
2001-07-26 16:14:23 +00:00
|
|
|
MathArray ar;
|
2001-08-10 09:30:02 +00:00
|
|
|
parser.parse_into(ar, 0);
|
2001-07-26 16:14:23 +00:00
|
|
|
return ar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
MathMacroTemplate * mathed_parse_macro(string const & str)
|
|
|
|
{
|
|
|
|
istringstream is(str.c_str());
|
2001-08-10 09:30:02 +00:00
|
|
|
Parser parser(is);
|
|
|
|
return parser.parse_macro();
|
2001-08-03 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
MathMacroTemplate * mathed_parse_macro(istream & is)
|
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
Parser parser(is);
|
|
|
|
return parser.parse_macro();
|
2001-08-10 07:52:04 +00:00
|
|
|
}
|
2001-08-03 09:54:48 +00:00
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
MathMacroTemplate * mathed_parse_macro(LyXLex & lex)
|
2001-07-20 10:57:22 +00:00
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
Parser parser(lex);
|
|
|
|
MathMacroTemplate * p = parser.parse_macro();
|
|
|
|
parse_end(lex, parser.lineno());
|
2001-08-10 07:52:04 +00:00
|
|
|
return p;
|
2001-07-20 10:57:22 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
MathMatrixInset * mathed_parse_normal(string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-10 07:52:04 +00:00
|
|
|
istringstream is(str.c_str());
|
2001-08-10 09:30:02 +00:00
|
|
|
Parser parser(is);
|
|
|
|
return parser.parse_normal();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
MathMatrixInset * mathed_parse_normal(istream & is)
|
2001-08-03 09:54:48 +00:00
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
Parser parser(is);
|
|
|
|
return parser.parse_normal();
|
2001-08-03 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MathMatrixInset * mathed_parse_normal(LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
Parser parser(lex);
|
|
|
|
MathMatrixInset * p = parser.parse_normal();
|
|
|
|
parse_end(lex, parser.lineno());
|
2001-06-25 00:06:33 +00:00
|
|
|
return p;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-07-12 07:18:29 +00:00
|
|
|
|