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.
|
|
|
|
*/
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
// {[(
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#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"
|
|
|
|
#include "math_bigopinset.h"
|
|
|
|
#include "math_dotsinset.h"
|
|
|
|
#include "math_decorationinset.h"
|
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_funcinset.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-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"
|
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"
|
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-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
// These are lexical codes, not semantic
|
|
|
|
enum lexcode_enum {
|
|
|
|
LexNone,
|
|
|
|
LexESC,
|
|
|
|
LexAlpha,
|
|
|
|
LexDigit,
|
|
|
|
LexBOP, // Binary operators or relations
|
|
|
|
LexMathSpace,
|
|
|
|
LexOpen,
|
|
|
|
LexClose,
|
|
|
|
LexComment,
|
|
|
|
LexArgument,
|
|
|
|
LexSpace,
|
|
|
|
LexNewLine,
|
|
|
|
LexOther,
|
|
|
|
LexSelf
|
|
|
|
};
|
|
|
|
|
|
|
|
lexcode_enum lexcode[256];
|
|
|
|
|
|
|
|
|
|
|
|
char const * latex_special_chars = "#$%&_{}";
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
2001-02-03 21:02:22 +00:00
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
void mathed_parse(MathArray & array, unsigned flags);
|
|
|
|
|
2001-07-05 14:45:04 +00:00
|
|
|
unsigned char getuchar(std::istream * is)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
is->get(c);
|
|
|
|
return static_cast<unsigned char>(c);
|
|
|
|
}
|
|
|
|
|
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-02-16 09:25:43 +00:00
|
|
|
///
|
2001-06-25 00:06:33 +00:00
|
|
|
union {
|
2001-02-26 12:53:35 +00:00
|
|
|
///
|
|
|
|
int i;
|
|
|
|
///
|
|
|
|
latexkeys const * l;
|
2001-06-25 00:06:33 +00:00
|
|
|
} yylval;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
string yytext;
|
|
|
|
int yylineno;
|
|
|
|
istream * yyis;
|
2001-07-03 07:56:55 +00:00
|
|
|
MathTextCodes yyvarcode;
|
2001-02-26 12:53:35 +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
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
void mathPrintError(string const & msg)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-13 07:55:55 +00:00
|
|
|
//lyxerr[Debug::MATHED] << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
|
|
|
|
lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
|
1999-09-27 18:44:28 +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-02-26 12:53:35 +00:00
|
|
|
lexcode[i] = LexDigit;
|
|
|
|
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;
|
|
|
|
lexcode['+'] = lexcode['-'] = lexcode['*'] = lexcode['/']
|
|
|
|
= lexcode['<'] = lexcode['>'] = lexcode['='] = LexBOP;
|
|
|
|
|
|
|
|
lexcode['!'] = lexcode[','] = lexcode[':']
|
|
|
|
= lexcode[';'] = LexMathSpace;
|
|
|
|
|
|
|
|
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-07-13 07:55:55 +00:00
|
|
|
string 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-02-26 12:53:35 +00:00
|
|
|
while (yyis->good()) {
|
2001-07-13 07:55:55 +00:00
|
|
|
c = getuchar(yyis);
|
|
|
|
if (!isspace(c))
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
if (c != lf) {
|
|
|
|
yyis->putback(c);
|
|
|
|
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-07-05 14:45:04 +00:00
|
|
|
unsigned char c = getuchar(yyis);
|
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;
|
|
|
|
} while (depth > 0 && yyis->good());
|
|
|
|
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int 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
|
|
|
|
|
|
|
while (yyis->good()) {
|
2001-07-05 14:45:04 +00:00
|
|
|
unsigned char c = getuchar(yyis);
|
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-07-03 07:56:55 +00:00
|
|
|
if (yyvarcode == LM_TC_TEXTRM && c == ' ') {
|
|
|
|
yylval.i = ' ';
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_ALPHA;
|
|
|
|
} else if (lexcode[c] == LexNewLine) {
|
|
|
|
++yylineno;
|
|
|
|
continue;
|
|
|
|
} else if (lexcode[c] == LexComment) {
|
|
|
|
do {
|
2001-07-05 14:45:04 +00:00
|
|
|
c = getuchar(yyis);
|
2001-06-25 00:06:33 +00:00
|
|
|
} while (c != '\n' && yyis->good()); // eat comments
|
2001-02-26 12:53:35 +00:00
|
|
|
} else if (lexcode[c] == LexDigit
|
|
|
|
|| lexcode[c] == LexOther
|
|
|
|
|| lexcode[c] == LexMathSpace) {
|
|
|
|
yylval.i = c;
|
|
|
|
return LM_TK_STR;
|
|
|
|
} else if (lexcode[c] == LexAlpha) {
|
2001-06-25 00:06:33 +00:00
|
|
|
yylval.i = c;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_ALPHA;
|
|
|
|
} else if (lexcode[c] == LexBOP) {
|
2001-06-25 00:06:33 +00:00
|
|
|
yylval.i = c;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_BOP;
|
|
|
|
} else if (lexcode[c] == LexSelf) {
|
|
|
|
return c;
|
|
|
|
} else if (lexcode[c] == LexArgument) {
|
2001-07-05 14:45:04 +00:00
|
|
|
c = getuchar(yyis);
|
2001-02-26 12:53:35 +00:00
|
|
|
yylval.i = c - '0';
|
|
|
|
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-07-05 14:45:04 +00:00
|
|
|
c = getuchar(yyis);
|
2001-02-26 12:53:35 +00:00
|
|
|
if (c == '\\') {
|
2001-06-25 00:06:33 +00:00
|
|
|
yylval.i = -1;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_NEWLINE;
|
|
|
|
}
|
|
|
|
if (c == '(') {
|
2001-06-25 00:06:33 +00:00
|
|
|
yylval.i = LM_OT_SIMPLE;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_BEGIN;
|
|
|
|
}
|
|
|
|
if (c == ')') {
|
2001-06-25 00:06:33 +00:00
|
|
|
yylval.i = LM_OT_SIMPLE;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_END;
|
|
|
|
}
|
|
|
|
if (c == '[') {
|
2001-06-25 00:06:33 +00:00
|
|
|
yylval.i = LM_OT_EQUATION;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_BEGIN;
|
|
|
|
}
|
|
|
|
if (c == ']') {
|
2001-06-25 00:06:33 +00:00
|
|
|
yylval.i = LM_OT_EQUATION;
|
2001-02-26 12:53:35 +00:00
|
|
|
return LM_TK_END;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
if (contains(latex_special_chars, c)) {
|
2001-02-26 12:53:35 +00:00
|
|
|
yylval.i = c;
|
|
|
|
return LM_TK_SPECIAL;
|
|
|
|
}
|
|
|
|
if (lexcode[c] == LexMathSpace) {
|
|
|
|
int i;
|
2001-06-25 00:06:33 +00:00
|
|
|
for (i = 0; i < 4 && static_cast<int>(c) != latex_mathspace[i][0]; ++i)
|
|
|
|
;
|
2001-02-26 12:53:35 +00:00
|
|
|
yylval.i = (i < 4) ? i : 0;
|
|
|
|
return LM_TK_SPACE;
|
|
|
|
}
|
2001-07-12 07:18:29 +00:00
|
|
|
if (lexcode[c] == LexAlpha) {
|
2001-06-25 00:06:33 +00:00
|
|
|
yytext.erase();
|
2001-07-26 16:14:23 +00:00
|
|
|
while (lexcode[c] == LexAlpha && yyis->good()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
yytext += c;
|
2001-07-05 14:45:04 +00:00
|
|
|
c = getuchar(yyis);
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
if (yyis->good())
|
|
|
|
yyis->putback(c);
|
2001-07-13 07:55:55 +00:00
|
|
|
//lyxerr[Debug::MATHED] << "reading: text '" << yytext << "'\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
latexkeys const * l = in_word_set(yytext);
|
|
|
|
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;
|
|
|
|
yylval.i = i;
|
|
|
|
} else if (l->token == LM_TK_SPACE)
|
|
|
|
yylval.i = l->id;
|
|
|
|
else
|
|
|
|
yylval.l = l;
|
|
|
|
return l->token;
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
|
|
|
|
MathScriptInset * prevScriptInset(MathArray const & array)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
MathInset * p = array.back_inset();
|
2001-07-26 06:46:50 +00:00
|
|
|
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_inset();
|
|
|
|
if (b && b->isScriptable()) {
|
|
|
|
p = new MathScriptInset(up, down, b->clone());
|
|
|
|
array.pop_back();
|
|
|
|
} else {
|
|
|
|
p = new MathScriptInset(up, down);
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
array.push_back(p);
|
|
|
|
}
|
2001-07-12 07:18:29 +00:00
|
|
|
if (up)
|
2001-07-26 06:46:50 +00:00
|
|
|
p->up(true);
|
2001-07-12 07:18:29 +00:00
|
|
|
if (down)
|
2001-07-26 06:46:50 +00:00
|
|
|
p->down(down);
|
|
|
|
if (limits)
|
|
|
|
p->limits(limits);
|
2001-07-12 07:18:29 +00:00
|
|
|
return p;
|
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-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
static bool curr_num;
|
|
|
|
static string curr_label;
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
void mathed_parse_lines(MathInset * inset, 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
|
|
|
|
bool saved_num = curr_num;
|
|
|
|
string saved_label = curr_label;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset * p = static_cast<MathGridInset *>(inset);
|
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-06-27 14:10:35 +00:00
|
|
|
curr_num = numbered;
|
2001-06-25 00:06:33 +00:00
|
|
|
curr_label = string();
|
|
|
|
|
|
|
|
// reading a row
|
|
|
|
int idx = p->nargs() - p->ncols();
|
|
|
|
for (int i = 0; i < col - 1; ++i, ++idx)
|
|
|
|
mathed_parse(p->cell(idx), FLAG_AMPERSAND);
|
|
|
|
mathed_parse(p->cell(idx), FLAG_NEWLINE | FLAG_END);
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
if (outmost) {
|
|
|
|
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
|
|
|
|
m->numbered(row, curr_num);
|
|
|
|
m->label(row, curr_label);
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
// Hack!
|
|
|
|
// no newline
|
|
|
|
if (yylval.i != -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
p->appendRow();
|
|
|
|
}
|
2001-07-03 07:56:55 +00:00
|
|
|
|
|
|
|
// restore global variables
|
|
|
|
curr_num = saved_num;
|
|
|
|
curr_label = saved_label;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * mathed_parse()
|
|
|
|
{
|
|
|
|
MathInset * p = 0;
|
2001-02-26 12:53:35 +00:00
|
|
|
int t = yylex();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
switch (t) {
|
|
|
|
case LM_TK_NEWCOMMAND: {
|
2001-07-13 07:55:55 +00:00
|
|
|
string name = lexArg('{').substr(1);
|
|
|
|
string arg = lexArg('[');
|
|
|
|
int narg = arg.empty() ? 0 : atoi(arg.c_str());
|
|
|
|
p = new MathMacroTemplate(name, narg);
|
2001-06-25 00:06:33 +00:00
|
|
|
mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
|
2001-07-13 07:55:55 +00:00
|
|
|
//lyxerr[Debug::MATHED] << "LM_TK_NEWCOMMAND: name: "
|
|
|
|
// << name << " nargs: " << narg << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_BEGIN: {
|
|
|
|
int i = yylval.i;
|
2001-07-13 07:55:55 +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-07-13 07:55:55 +00:00
|
|
|
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
|
2001-06-25 00:06:33 +00:00
|
|
|
switch (typ) {
|
|
|
|
|
|
|
|
case LM_OT_SIMPLE: {
|
2001-06-27 14:10:35 +00:00
|
|
|
curr_num = latex_mathenv[i].numbered;
|
|
|
|
curr_label = string();
|
2001-07-13 07:55:55 +00:00
|
|
|
mathed_parse(m->cell(0), 0);
|
2001-06-27 14:10:35 +00:00
|
|
|
m->numbered(0, curr_num);
|
|
|
|
m->label(0, curr_label);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_EQUATION: {
|
2001-06-27 14:10:35 +00:00
|
|
|
curr_num = latex_mathenv[i].numbered;
|
|
|
|
curr_label = string();
|
2001-07-13 07:55:55 +00:00
|
|
|
mathed_parse(m->cell(0), FLAG_END);
|
2001-06-27 14:10:35 +00:00
|
|
|
m->numbered(0, curr_num);
|
|
|
|
m->label(0, curr_label);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY: {
|
2001-07-13 07:55:55 +00:00
|
|
|
mathed_parse_lines(m, 3, latex_mathenv[i].numbered, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_ALIGN: {
|
|
|
|
m->halign(lexArg('{'));
|
|
|
|
mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_ALIGNAT: {
|
2001-07-13 07:55:55 +00:00
|
|
|
m->halign(lexArg('{'));
|
|
|
|
mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2001-07-08 12:52:16 +00:00
|
|
|
lyxerr[Debug::MATHED] << "1: unknown math environment: " << typ << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
p->setName(latex_mathenv[i].basename);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2001-07-08 12:52:16 +00:00
|
|
|
lyxerr[Debug::MATHED] << "2 unknown math environment: " << t << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
void handle_frac(MathArray & array, string const & name)
|
|
|
|
{
|
|
|
|
MathFracInset * p = new MathFracInset(name);
|
|
|
|
mathed_parse(p->cell(0), FLAG_ITEM);
|
|
|
|
mathed_parse(p->cell(1), FLAG_ITEM);
|
|
|
|
array.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void mathed_parse(MathArray & array, unsigned flags)
|
|
|
|
{
|
2001-07-13 07:55:55 +00:00
|
|
|
int t = yylex();
|
2001-02-26 12:53:35 +00:00
|
|
|
bool panic = false;
|
|
|
|
static int plevel = -1;
|
2001-07-03 07:56:55 +00:00
|
|
|
yyvarcode = LM_TC_VAR;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
int brace = 0;
|
|
|
|
int limits = 0;
|
2001-03-09 23:55:50 +00:00
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
++plevel;
|
|
|
|
while (t) {
|
2001-07-26 16:14:23 +00:00
|
|
|
//lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i << "\n";
|
2001-07-13 07:55:55 +00:00
|
|
|
// << " plevel: " << plevel << " ";
|
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) {
|
|
|
|
mathPrintError(
|
|
|
|
"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-07-10 13:17:43 +00:00
|
|
|
array.push_back(yylval.i, yyvarcode);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_ARGUMENT:
|
2001-06-25 00:06:33 +00:00
|
|
|
array.push_back(new MathMacroArgument(yylval.i));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SPECIAL:
|
2001-06-25 00:06:33 +00:00
|
|
|
array.push_back(yylval.i, LM_TC_SPECIAL);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_STR:
|
2001-07-10 13:17:43 +00:00
|
|
|
array.push_back(yylval.i, 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
|
|
|
|
array.push_back('{', LM_TC_TEX);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_CLOSE:
|
|
|
|
--brace;
|
|
|
|
if (brace < 0) {
|
|
|
|
mathPrintError("Unmatching braces");
|
|
|
|
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
|
|
|
|
array.push_back('}', LM_TC_TEX);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
2001-07-13 07:55:55 +00:00
|
|
|
array.push_back('[', 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
|
|
|
|
array.push_back(']', LM_TC_CONST);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '^':
|
2001-07-26 06:46:50 +00:00
|
|
|
mathed_parse(
|
|
|
|
lastScriptInset(array, true, false, limits)->cell(0), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '_':
|
2001-07-26 06:46:50 +00:00
|
|
|
mathed_parse(
|
|
|
|
lastScriptInset(array, false, true, limits)->cell(1), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_LIMIT:
|
2001-07-26 06:46:50 +00:00
|
|
|
limits = yylval.l->id;
|
|
|
|
//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-02-26 12:53:35 +00:00
|
|
|
case LM_TK_BIGSYM:
|
2001-07-26 15:28:45 +00:00
|
|
|
case LM_TK_SYM:
|
2001-07-26 13:52:47 +00:00
|
|
|
case LM_TK_FUNCLIM:
|
2001-07-26 06:46:50 +00:00
|
|
|
limits = 0;
|
2001-07-26 14:37:09 +00:00
|
|
|
array.push_back(new MathBigopInset(yylval.l));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_BOP:
|
2001-07-10 13:17:43 +00:00
|
|
|
array.push_back(yylval.i, LM_TC_BOP);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SPACE:
|
2001-06-25 00:06:33 +00:00
|
|
|
if (yylval.i >= 0)
|
|
|
|
array.push_back(new MathSpaceInset(yylval.i));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_DOTS:
|
2001-07-26 16:14:23 +00:00
|
|
|
array.push_back(new MathDotsInset(yylval.l));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
case LM_TK_CHOOSE:
|
2001-07-09 10:19:50 +00:00
|
|
|
handle_frac(array, "atop");
|
2001-04-27 12:35:55 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
case LM_TK_STACK:
|
2001-07-09 10:19:50 +00:00
|
|
|
handle_frac(array, "stackrel");
|
2001-04-27 12:35:55 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
case LM_TK_FRAC:
|
2001-07-09 10:19:50 +00:00
|
|
|
handle_frac(array, "frac");
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
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-07-05 14:45:04 +00:00
|
|
|
unsigned char c = getuchar(yyis);
|
2001-02-26 12:53:35 +00:00
|
|
|
if (c == '[') {
|
2001-07-12 07:18:29 +00:00
|
|
|
array.push_back(new MathRootInset);
|
|
|
|
mathed_parse(array.back_inset()->cell(0), FLAG_BRACK_END);
|
|
|
|
mathed_parse(array.back_inset()->cell(1), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
} else {
|
|
|
|
yyis->putback(c);
|
2001-07-12 07:18:29 +00:00
|
|
|
array.push_back(new MathSqrtInset);
|
|
|
|
mathed_parse(array.back_inset()->cell(0), FLAG_ITEM);
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_LEFT:
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
int ld = yylex();
|
|
|
|
if (ld == LM_TK_SYM)
|
|
|
|
ld = yylval.l->id;
|
|
|
|
else if (ld == LM_TK_STR || ld == LM_TK_BOP || ld == LM_TK_SPECIAL)
|
|
|
|
ld = yylval.i;
|
|
|
|
|
|
|
|
MathArray ar;
|
|
|
|
mathed_parse(ar, FLAG_RIGHT);
|
|
|
|
|
|
|
|
int rd = yylex();
|
|
|
|
if (rd == LM_TK_SYM)
|
|
|
|
rd = yylval.l->id;
|
|
|
|
else if (rd == LM_TK_STR || rd == LM_TK_BOP || rd == LM_TK_SPECIAL)
|
|
|
|
rd = yylval.i;
|
|
|
|
|
|
|
|
MathDelimInset * dl = new MathDelimInset(ld, rd);
|
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-04-24 16:13:38 +00:00
|
|
|
mathPrintError("Unmatched right delimiter");
|
|
|
|
// panic = true;
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_FONT:
|
2001-07-03 07:56:55 +00:00
|
|
|
yyvarcode = static_cast<MathTextCodes>(yylval.l->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;
|
|
|
|
//MathSizeInset * p = new MathSizeInset(MathStyles(yylval.l->id));
|
|
|
|
//array.push_back(p);
|
|
|
|
//mathed_parse(p->cell(0), FLAG_BRACE_FONT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
case LM_TK_DECORATION:
|
2001-02-26 12:53:35 +00:00
|
|
|
{
|
2001-07-26 16:14:23 +00:00
|
|
|
MathDecorationInset * p = new MathDecorationInset(yylval.l);
|
2001-07-13 07:55:55 +00:00
|
|
|
mathed_parse(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-06-25 00:06:33 +00:00
|
|
|
curr_num = false;
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_FUNC:
|
2001-07-13 07:55:55 +00:00
|
|
|
array.push_back(new MathFuncInset(yylval.l->name));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_TK_UNDEF:
|
|
|
|
if (MathMacroTable::hasTemplate(yytext)) {
|
|
|
|
MathMacro * m = MathMacroTable::cloneTemplate(yytext);
|
2001-07-06 12:09:32 +00:00
|
|
|
for (int i = 0; i < m->nargs(); ++i)
|
2001-07-12 07:18:29 +00:00
|
|
|
mathed_parse(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-07-26 13:52:47 +00:00
|
|
|
array.push_back(new MathFuncInset(yytext));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int i = yylval.i;
|
|
|
|
MathInsetTypes typ = latex_mathenv[i].typ;
|
|
|
|
|
|
|
|
if (typ == LM_OT_MATRIX) {
|
2001-07-13 07:55:55 +00:00
|
|
|
string valign = lexArg('[') + 'c';
|
|
|
|
string halign = lexArg('{');
|
|
|
|
//lyxerr << "valign: '" << valign << "'\n";
|
|
|
|
//lyxerr << "halign: '" << halign << "'\n";
|
|
|
|
MathArrayInset * m = new MathArrayInset(halign.size(), 1);
|
|
|
|
m->valign(valign[0]);
|
|
|
|
m->halign(halign);
|
|
|
|
|
|
|
|
mathed_parse_lines(m, halign.size(), latex_mathenv[i].numbered, false);
|
|
|
|
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-07-10 13:17:43 +00:00
|
|
|
array.push_back(MathMacroTable::cloneTemplate(yylval.l->name));
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_LABEL:
|
2001-07-13 07:55:55 +00:00
|
|
|
curr_label = lexArg('{', true);
|
2001-02-26 12:53:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
mathPrintError("Unrecognized token");
|
2001-07-08 12:52:16 +00:00
|
|
|
lyxerr[Debug::MATHED] << "[" << t << " " << yytext << "]" << 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-07-26 16:14:23 +00:00
|
|
|
} while (yyis->good() && t != LM_TK_END && t);
|
2001-02-26 12:53:35 +00:00
|
|
|
} else
|
2001-06-25 00:06:33 +00:00
|
|
|
t = yylex();
|
2001-07-13 07:55:55 +00:00
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
}
|
|
|
|
--plevel;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
yyis = &is;
|
|
|
|
yylineno = 0;
|
|
|
|
MathArray ar;
|
|
|
|
mathed_parse(ar, 0);
|
|
|
|
return ar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-20 10:57:22 +00:00
|
|
|
MathInset * mathed_parse(string const & str)
|
|
|
|
{
|
|
|
|
istringstream is(str.c_str());
|
|
|
|
return mathed_parse(is);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * mathed_parse(istream & is)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
yyis = &is;
|
|
|
|
yylineno = 0;
|
|
|
|
return mathed_parse();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * mathed_parse(LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
yyis = &lex.getStream();
|
|
|
|
yylineno = lex.GetLineNo();
|
|
|
|
|
|
|
|
MathInset * p = mathed_parse();
|
|
|
|
|
|
|
|
// Update line number
|
|
|
|
lex.setLineNo(yylineno);
|
|
|
|
|
|
|
|
// reading of end_inset
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
lex.nextToken();
|
|
|
|
if (lex.GetString() == "\\end_inset")
|
|
|
|
break;
|
2001-07-08 12:52:16 +00:00
|
|
|
lyxerr[Debug::MATHED] << "InsetFormula::Read: Garbage before \\end_inset,"
|
2001-06-25 00:06:33 +00:00
|
|
|
" or missing \\end_inset!" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-07-12 07:18:29 +00:00
|
|
|
|
|
|
|
//]})
|