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"
|
|
|
|
#include "math_rowst.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_iter.h"
|
|
|
|
#include "math_inset.h"
|
|
|
|
#include "math_macro.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
#include "math_macrotable.h"
|
|
|
|
#include "math_macrotemplate.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_root.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_matrixinset.h"
|
|
|
|
#include "math_accentinset.h"
|
|
|
|
#include "math_bigopinset.h"
|
|
|
|
#include "math_funcinset.h"
|
|
|
|
#include "math_spaceinset.h"
|
|
|
|
#include "math_dotsinset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_decorationinset.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2000-09-26 13:54:57 +00:00
|
|
|
#include "support/lyxlib.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "mathed/support.h"
|
2001-02-16 09:25:43 +00:00
|
|
|
#include "boost/array.hpp"
|
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-02-03 21:02:22 +00:00
|
|
|
extern MathMatrixInset * create_multiline(short int type, int cols);
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
enum {
|
|
|
|
FLAG_BRACE = 1, // A { needed
|
|
|
|
FLAG_BRACE_ARG = 2, // Next { is argument
|
|
|
|
FLAG_BRACE_OPT = 4, // Optional {
|
|
|
|
FLAG_BRACE_LAST = 8, // Last } ends the parsing process
|
|
|
|
FLAG_BRACK_ARG = 16, // Optional [
|
|
|
|
FLAG_RIGHT = 32, // Next right ends the parsing process
|
|
|
|
FLAG_END = 64, // Next end ends the parsing process
|
|
|
|
FLAG_BRACE_FONT = 128, // Next } closes a font
|
|
|
|
FLAG_BRACK_END = 256 // Next ] ends the parsing process
|
|
|
|
};
|
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
union YYSTYPE {
|
|
|
|
///
|
|
|
|
unsigned char c;
|
|
|
|
///
|
|
|
|
char const * s;
|
|
|
|
///
|
|
|
|
int i;
|
|
|
|
///
|
|
|
|
latexkeys const * l;
|
|
|
|
};
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
1999-09-27 18:44:28 +00:00
|
|
|
YYSTYPE yylval;
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
2001-02-03 21:02:22 +00:00
|
|
|
MathedInsetTypes mathed_env = LM_OT_MIN;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
|
|
string mathed_label;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-02-11 09:58:20 +00:00
|
|
|
int const latex_mathenv_num = 12;
|
2001-02-03 21:02:22 +00:00
|
|
|
char const * latex_mathenv[latex_mathenv_num] = {
|
1999-09-27 18:44:28 +00:00
|
|
|
"math",
|
|
|
|
"displaymath",
|
|
|
|
"equation",
|
|
|
|
"eqnarray*",
|
|
|
|
"eqnarray",
|
2001-02-11 09:58:20 +00:00
|
|
|
"align*",
|
|
|
|
"align",
|
2001-02-03 21:02:22 +00:00
|
|
|
"alignat*",
|
|
|
|
"alignat",
|
|
|
|
"multline*",
|
|
|
|
"multline",
|
1999-09-27 18:44:28 +00:00
|
|
|
"array"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
char const * latex_special_chars = "#$%&_{}";
|
1999-09-27 18:44:28 +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
|
|
|
|
};
|
|
|
|
|
|
|
|
static lexcode_enum lexcode[256];
|
2001-01-26 22:24:20 +00:00
|
|
|
#warning Replace with string
|
2001-02-16 09:25:43 +00:00
|
|
|
//static char yytext[256];
|
|
|
|
static array<char, 256> yytext;
|
1999-09-27 18:44:28 +00:00
|
|
|
static int yylineno;
|
2000-01-06 02:44:26 +00:00
|
|
|
static istream * yyis;
|
1999-11-15 11:06:41 +00:00
|
|
|
static bool yy_mtextmode= false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
static
|
2000-09-14 17:53:12 +00:00
|
|
|
void mathPrintError(string const & msg)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Line ~" << yylineno << ": Math parse error: "
|
|
|
|
<< msg << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
static
|
|
|
|
void LexInitCodes()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
for (int i = 0; i <= 255; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (isalpha(i)) lexcode[i] = LexAlpha;
|
|
|
|
else if (isdigit(i)) lexcode[i] = LexDigit;
|
|
|
|
else if (isspace(i)) lexcode[i] = LexSpace;
|
|
|
|
else lexcode[i] = LexNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
lexcode['\t'] = lexcode['\f'] = lexcode[' '] = LexSpace;
|
|
|
|
lexcode['\n'] = LexNewLine;
|
|
|
|
lexcode['%'] = LexComment;
|
|
|
|
lexcode['#'] = LexArgument;
|
|
|
|
lexcode['+'] = lexcode['-'] = lexcode['*'] = lexcode['/'] =
|
1999-11-15 14:45:17 +00:00
|
|
|
lexcode['<'] = lexcode['>'] = lexcode['='] = LexBOP;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
lexcode['!'] = lexcode[','] = lexcode[':'] = lexcode[';'] = LexMathSpace;
|
2000-10-04 14:24:42 +00:00
|
|
|
|
|
|
|
lexcode['('] = lexcode[')'] = lexcode['|'] = lexcode['.'] =
|
|
|
|
lexcode['?'] = LexOther;
|
|
|
|
|
|
|
|
lexcode['\''] = lexcode['@'] = LexAlpha;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
lexcode['['] = lexcode[']'] = lexcode['^'] = lexcode['_'] =
|
|
|
|
lexcode['&'] = LexSelf;
|
|
|
|
|
|
|
|
lexcode['\\'] = LexESC;
|
|
|
|
lexcode['{'] = LexOpen;
|
|
|
|
lexcode['}'] = LexClose;
|
|
|
|
}
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
static
|
|
|
|
char LexGetArg(char lf, bool accept_spaces= false)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-01-06 02:44:26 +00:00
|
|
|
unsigned char c;
|
2000-01-07 03:42:16 +00:00
|
|
|
char cc;
|
2000-01-06 02:44:26 +00:00
|
|
|
while (yyis->good()) {
|
2000-01-07 03:42:16 +00:00
|
|
|
yyis->get(cc);
|
|
|
|
c = cc;
|
2000-01-06 02:44:26 +00:00
|
|
|
if (c > ' ') {
|
2001-01-26 22:24:20 +00:00
|
|
|
if (!lf)
|
|
|
|
lf = c;
|
|
|
|
else if (c != lf) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Math parse error: unexpected '"
|
|
|
|
<< c << "'" << endl;
|
2001-01-26 22:24:20 +00:00
|
|
|
return '\0';
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-09-26 13:54:57 +00:00
|
|
|
char const rg =
|
|
|
|
(lf == '{') ? '}' : ((lf == '[') ? ']' : ((lf == '(') ? ')' : 0));
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!rg) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Math parse error: unknown bracket '"
|
|
|
|
<< lf << "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return '\0';
|
2000-09-26 13:54:57 +00:00
|
|
|
}
|
|
|
|
char * p = &yytext[0];
|
|
|
|
int bcnt = 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
do {
|
2000-01-07 03:42:16 +00:00
|
|
|
yyis->get(cc);
|
|
|
|
c = cc;
|
2000-01-06 02:44:26 +00:00
|
|
|
if (c == lf) ++bcnt;
|
|
|
|
if (c == rg) --bcnt;
|
2000-09-26 13:54:57 +00:00
|
|
|
if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0) *(p++) = c;
|
2001-02-16 09:25:43 +00:00
|
|
|
} while (bcnt > 0 && yyis->good() && p - yytext.data() < 255);
|
1999-09-27 18:44:28 +00:00
|
|
|
*p = '\0';
|
|
|
|
return rg;
|
|
|
|
}
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
static
|
|
|
|
int yylex(void)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
static int init_done = 0;
|
|
|
|
|
|
|
|
if (!init_done) LexInitCodes();
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
unsigned char c;
|
|
|
|
char cc;
|
2000-01-07 03:42:16 +00:00
|
|
|
while (yyis->good()) {
|
|
|
|
yyis->get(cc);
|
|
|
|
c = cc;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
if (yy_mtextmode && c == ' ') {
|
|
|
|
yylval.i= ' ';
|
1999-09-27 18:44:28 +00:00
|
|
|
return LM_TK_ALPHA;
|
2000-09-26 13:54:57 +00:00
|
|
|
} else
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
if (lexcode[c] == LexNewLine) {
|
2000-01-06 02:44:26 +00:00
|
|
|
++yylineno;
|
1999-09-27 18:44:28 +00:00
|
|
|
continue;
|
2000-09-26 13:54:57 +00:00
|
|
|
} else
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
if (lexcode[c] == LexComment) {
|
|
|
|
do {
|
|
|
|
yyis->get(cc);
|
|
|
|
c = cc;
|
|
|
|
} while (c != '\n' % yyis->good()); // eat comments
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (lexcode[c] == LexDigit
|
|
|
|
|| lexcode[c] == LexOther
|
|
|
|
|| lexcode[c] == LexMathSpace) {
|
|
|
|
yylval.i = c;
|
|
|
|
return LM_TK_STR;
|
|
|
|
} else
|
|
|
|
if (lexcode[c] == LexAlpha) {
|
|
|
|
yylval.i= c;
|
|
|
|
return LM_TK_ALPHA;
|
|
|
|
} else
|
|
|
|
if (lexcode[c] == LexBOP) {
|
|
|
|
yylval.i= c;
|
|
|
|
return LM_TK_BOP;
|
|
|
|
} else
|
|
|
|
if (lexcode[c] == LexSelf) {
|
|
|
|
return c;
|
|
|
|
} else
|
2000-01-07 03:42:16 +00:00
|
|
|
if (lexcode[c] == LexArgument) {
|
|
|
|
yyis->get(cc);
|
|
|
|
c = cc;
|
1999-09-27 18:44:28 +00:00
|
|
|
yylval.i = c - '0';
|
|
|
|
return LM_TK_ARGUMENT;
|
2000-09-26 13:54:57 +00:00
|
|
|
} else
|
|
|
|
if (lexcode[c] == LexOpen) {
|
|
|
|
return LM_TK_OPEN;
|
|
|
|
} else
|
|
|
|
if (lexcode[c] == LexClose) {
|
|
|
|
return LM_TK_CLOSE;
|
|
|
|
} else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (lexcode[c] == LexESC) {
|
2000-01-07 03:42:16 +00:00
|
|
|
yyis->get(cc);
|
|
|
|
c = cc;
|
2000-09-26 13:54:57 +00:00
|
|
|
if (c == '\\') {
|
|
|
|
return LM_TK_NEWLINE;
|
|
|
|
}
|
|
|
|
if (c == '(') {
|
2001-02-03 21:02:22 +00:00
|
|
|
yylval.i = LM_OT_MIN;
|
2000-09-26 13:54:57 +00:00
|
|
|
return LM_TK_BEGIN;
|
|
|
|
}
|
|
|
|
if (c == ')') {
|
2001-02-03 21:02:22 +00:00
|
|
|
yylval.i = LM_OT_MIN;
|
2000-09-26 13:54:57 +00:00
|
|
|
return LM_TK_END;
|
|
|
|
}
|
|
|
|
if (c == '[') {
|
2001-02-03 21:02:22 +00:00
|
|
|
yylval.i = LM_OT_PAR;
|
2000-09-26 13:54:57 +00:00
|
|
|
return LM_TK_BEGIN;
|
|
|
|
}
|
|
|
|
if (c == ']') {
|
2001-02-03 21:02:22 +00:00
|
|
|
yylval.i = LM_OT_PAR;
|
2000-09-26 13:54:57 +00:00
|
|
|
return LM_TK_END;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
if (strchr(latex_special_chars, c)) {
|
|
|
|
yylval.i = c;
|
|
|
|
return LM_TK_SPECIAL;
|
2000-09-26 13:54:57 +00:00
|
|
|
}
|
1999-11-15 11:06:41 +00:00
|
|
|
if (lexcode[c] == LexMathSpace) {
|
1999-09-27 18:44:28 +00:00
|
|
|
int i;
|
2000-01-07 03:42:16 +00:00
|
|
|
for (i = 0; i < 4 && static_cast<int>(c) != latex_mathspace[i][0]; ++i);
|
2000-09-26 13:54:57 +00:00
|
|
|
yylval.i = (i < 4) ? i : 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
return LM_TK_SPACE;
|
|
|
|
}
|
1999-11-15 11:06:41 +00:00
|
|
|
if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
|
2000-01-06 02:44:26 +00:00
|
|
|
char * p = &yytext[0];
|
2001-01-26 22:24:20 +00:00
|
|
|
while ((lexcode[c] == LexAlpha || lexcode[c] == LexDigit)
|
2001-02-16 09:25:43 +00:00
|
|
|
&& p - yytext.data() < 255) {
|
1999-09-27 18:44:28 +00:00
|
|
|
*p = c;
|
2000-01-07 03:42:16 +00:00
|
|
|
yyis->get(cc);
|
|
|
|
c = cc;
|
2000-01-24 18:34:46 +00:00
|
|
|
++p;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
*p = '\0';
|
2000-01-06 02:44:26 +00:00
|
|
|
if (yyis->good()) yyis->putback(c);
|
2001-02-16 09:25:43 +00:00
|
|
|
latexkeys const * l = in_word_set (yytext.data(), strlen(yytext.data()));
|
1999-09-27 18:44:28 +00:00
|
|
|
if (l) {
|
1999-11-15 11:06:41 +00:00
|
|
|
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
|
1999-09-27 18:44:28 +00:00
|
|
|
int i;
|
|
|
|
LexGetArg('{');
|
2001-02-16 09:25:43 +00:00
|
|
|
// for (i = 0; i < 5 && compare(yytext, latex_mathenv[i],
|
2000-01-24 18:34:46 +00:00
|
|
|
// strlen(latex_mathenv[i])); ++i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-03 21:02:22 +00:00
|
|
|
for (i = 0; i < latex_mathenv_num
|
2001-02-16 09:25:43 +00:00
|
|
|
&& compare(yytext.data(), latex_mathenv[i]); ++i);
|
1999-09-27 18:44:28 +00:00
|
|
|
yylval.i = i;
|
|
|
|
} else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (l->token == LM_TK_SPACE)
|
1999-09-27 18:44:28 +00:00
|
|
|
yylval.i = l->id;
|
|
|
|
else
|
|
|
|
yylval.l = l;
|
|
|
|
return l->token;
|
|
|
|
} else {
|
2001-02-16 09:25:43 +00:00
|
|
|
yylval.s = yytext.data();
|
1999-09-27 18:44:28 +00:00
|
|
|
return LM_TK_UNDEF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
1999-11-15 11:06:41 +00:00
|
|
|
int parse_align(char * hor, char *)
|
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
int nc = 0;
|
2000-01-06 02:44:26 +00:00
|
|
|
for (char * c = hor; c && *c > ' '; ++c) ++nc;
|
1999-09-27 18:44:28 +00:00
|
|
|
return nc;
|
|
|
|
}
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Accent hacks only for 0.12. Stolen from Cursor.
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
1999-09-27 18:44:28 +00:00
|
|
|
int accent = 0;
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
1999-09-27 18:44:28 +00:00
|
|
|
int nestaccent[8];
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
1999-09-27 18:44:28 +00:00
|
|
|
void setAccent(int ac)
|
|
|
|
{
|
|
|
|
if (ac > 0 && accent < 8) {
|
|
|
|
nestaccent[accent++] = ac;
|
|
|
|
} else
|
|
|
|
accent = 0; // consumed!
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
1999-11-15 11:06:41 +00:00
|
|
|
MathedInset * doAccent(byte c, MathedTextCodes t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathedInset * ac = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
for (int i = accent - 1; i >= 0; --i) {
|
|
|
|
if (i == accent - 1)
|
1999-09-27 18:44:28 +00:00
|
|
|
ac = new MathAccentInset(c, t, nestaccent[i]);
|
|
|
|
else
|
|
|
|
ac = new MathAccentInset(ac, nestaccent[i]);
|
|
|
|
}
|
|
|
|
accent = 0; // consumed!
|
|
|
|
|
|
|
|
return ac;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
static
|
1999-11-15 11:06:41 +00:00
|
|
|
MathedInset * doAccent(MathedInset * p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathedInset * ac = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
for (int i = accent - 1; i >= 0; --i) {
|
|
|
|
if (i == accent - 1)
|
1999-09-27 18:44:28 +00:00
|
|
|
ac = new MathAccentInset(p, nestaccent[i]);
|
|
|
|
else
|
|
|
|
ac = new MathAccentInset(ac, nestaccent[i]);
|
|
|
|
}
|
|
|
|
accent = 0; // consumed!
|
|
|
|
|
|
|
|
return ac;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
|
|
|
|
MathParInset ** mtx = 0)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
int t = yylex();
|
|
|
|
int tprev = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
bool panic = false;
|
|
|
|
static int plevel = -1;
|
|
|
|
static int size = LM_ST_TEXT;
|
|
|
|
MathedTextCodes varcode = LM_TC_VAR;
|
2000-01-06 02:44:26 +00:00
|
|
|
MathedInset * binset = 0;
|
2000-09-26 13:54:57 +00:00
|
|
|
static MathMacroTemplate * macro = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
int brace = 0;
|
|
|
|
int acc_brace = 0;
|
|
|
|
int acc_braces[8];
|
2000-02-29 02:19:17 +00:00
|
|
|
MathParInset * mt = (mtx) ? *mtx : 0;//(MathParInset*)0;
|
2000-01-06 02:44:26 +00:00
|
|
|
MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
++plevel;
|
2001-02-12 08:55:14 +00:00
|
|
|
if (!array) array = new MathedArray;
|
1999-09-27 18:44:28 +00:00
|
|
|
MathedIter data(array);
|
|
|
|
while (t) {
|
|
|
|
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
|
1999-11-15 11:06:41 +00:00
|
|
|
if ((flags & FLAG_BRACK_ARG) && t == '[') {
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mathPrintError("Expected {. Maybe you forgot to enclose an argument in {}");
|
|
|
|
panic = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MathedInsetTypes fractype = LM_OT_FRAC;
|
|
|
|
switch (t) {
|
|
|
|
case LM_TK_ALPHA:
|
|
|
|
{
|
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(yylval.i, varcode), LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert(yylval.i, varcode); //LM_TC_VAR);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_ARGUMENT:
|
|
|
|
{
|
|
|
|
if (macro) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(macro->getMacroPar(yylval.i-1), LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_NEWCOMMAND:
|
|
|
|
{
|
|
|
|
int na = 0;
|
|
|
|
|
|
|
|
LexGetArg('{');
|
2000-09-26 13:54:57 +00:00
|
|
|
string const name(&yytext[1]);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// ugly trick to be removed soon (lyx3)
|
2000-09-26 13:54:57 +00:00
|
|
|
char const c = yyis->peek();
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == '[') {
|
1999-09-27 18:44:28 +00:00
|
|
|
LexGetArg('[');
|
2001-02-16 09:25:43 +00:00
|
|
|
na = lyx::atoi(yytext.data());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
macro = new MathMacroTemplate(name, na);
|
|
|
|
flags = FLAG_BRACE|FLAG_BRACE_LAST;
|
|
|
|
*mtx = macro;
|
2001-02-20 16:00:22 +00:00
|
|
|
macro->setData(*array);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_SPECIAL:
|
|
|
|
{
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert(yylval.i, LM_TC_SPECIAL);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_STR:
|
|
|
|
{
|
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(yylval.i, LM_TC_CONST), LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert(yylval.i, LM_TC_CONST);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_OPEN:
|
|
|
|
{
|
2000-01-24 18:34:46 +00:00
|
|
|
++brace;
|
1999-11-15 11:06:41 +00:00
|
|
|
if (accent && tprev == LM_TK_ACCENT) {
|
1999-09-27 18:44:28 +00:00
|
|
|
acc_braces[acc_brace++] = brace;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flags & FLAG_BRACE_OPT) {
|
|
|
|
flags &= ~FLAG_BRACE_OPT;
|
|
|
|
flags |= FLAG_BRACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FLAG_BRACE)
|
|
|
|
flags &= ~FLAG_BRACE;
|
|
|
|
else {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert('{', LM_TC_TEX);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_CLOSE:
|
|
|
|
{
|
2000-01-24 18:34:46 +00:00
|
|
|
--brace;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (brace < 0) {
|
|
|
|
mathPrintError("Unmatching braces");
|
|
|
|
panic = true;
|
|
|
|
break;
|
|
|
|
}
|
1999-11-15 11:06:41 +00:00
|
|
|
if (acc_brace && brace == acc_braces[acc_brace-1]-1) {
|
2000-01-24 18:34:46 +00:00
|
|
|
--acc_brace;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flags & FLAG_BRACE_FONT) {
|
|
|
|
varcode = LM_TC_VAR;
|
|
|
|
yy_mtextmode = false;
|
|
|
|
flags &= ~FLAG_BRACE_FONT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (brace == 0 && (flags & FLAG_BRACE_LAST)) {
|
2000-01-24 18:34:46 +00:00
|
|
|
--plevel;
|
1999-09-27 18:44:28 +00:00
|
|
|
return array;
|
|
|
|
} else {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert('}', LM_TC_TEX);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
{
|
|
|
|
if (flags & FLAG_BRACK_ARG) {
|
|
|
|
flags &= ~FLAG_BRACK_ARG;
|
2000-09-26 13:54:57 +00:00
|
|
|
char const rg = LexGetArg('[');
|
|
|
|
if (rg != ']') {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathPrintError("Expected ']'");
|
|
|
|
panic = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// if (arg) strcpy(arg, yytext);
|
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert('[', LM_TC_CONST);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ']':
|
|
|
|
{
|
|
|
|
if (flags & FLAG_BRACK_END) {
|
2000-01-24 18:34:46 +00:00
|
|
|
--plevel;
|
1999-09-27 18:44:28 +00:00
|
|
|
return array;
|
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert(']', LM_TC_CONST);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '^':
|
|
|
|
{
|
2000-01-06 02:44:26 +00:00
|
|
|
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
|
2001-02-20 16:00:22 +00:00
|
|
|
p->setData(*ar);
|
1999-10-07 18:44:17 +00:00
|
|
|
// lyxerr << "UP[" << p->GetStyle() << "]" << endl;
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(p, LM_TC_UP);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '_':
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
|
2001-02-20 16:00:22 +00:00
|
|
|
p->setData(*ar);
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(p, LM_TC_DOWN);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_LIMIT:
|
|
|
|
{
|
|
|
|
if (binset) {
|
1999-12-13 00:05:34 +00:00
|
|
|
binset->SetLimits(bool(yylval.l->id));
|
1999-10-02 16:21:10 +00:00
|
|
|
binset = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '&': // Tab
|
|
|
|
{
|
2000-09-29 18:44:07 +00:00
|
|
|
if ((flags & FLAG_END) && mt && data.getCol()<mt->GetColumns() - 1) {
|
1999-09-27 18:44:28 +00:00
|
|
|
data.setNumCols(mt->GetColumns());
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert('T', LM_TC_TAB);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
mathPrintError("Unexpected tab");
|
|
|
|
// debug info. [made that conditional -JMarc]
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::MATHED))
|
|
|
|
lyxerr << data.getCol() << " " << mt->GetColumns() << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_NEWLINE:
|
|
|
|
{
|
|
|
|
if (mt && (flags & FLAG_END)) {
|
|
|
|
if (mt->Permit(LMPF_ALLOW_CR)) {
|
|
|
|
if (crow) {
|
2000-09-29 18:44:07 +00:00
|
|
|
crow->setNext(new MathedRowSt(mt->GetColumns() + 1)); // this leaks
|
1999-09-27 18:44:28 +00:00
|
|
|
crow = crow->getNext();
|
|
|
|
}
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert('K', LM_TC_CR);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
mathPrintError("Unexpected newline");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_BIGSYM:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
binset = new MathBigopInset(yylval.l->name, yylval.l->id);
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(binset, LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_SYM:
|
|
|
|
{
|
|
|
|
if (yylval.l->id < 256) {
|
|
|
|
MathedTextCodes tc = MathIsBOPS(yylval.l->id) ? LM_TC_BOPS: LM_TC_SYMB;
|
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(yylval.l->id, tc), LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert(yylval.l->id, tc);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2000-01-06 02:44:26 +00:00
|
|
|
MathFuncInset * bg = new MathFuncInset(yylval.l->name);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(bg), LM_TC_INSET);
|
|
|
|
} else {
|
|
|
|
#warning This is suspisious! (Lgb)
|
|
|
|
// it should not take a bool as second arg (Lgb)
|
|
|
|
data.insertInset(bg, true);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_BOP:
|
|
|
|
{
|
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(yylval.i, LM_TC_BOP), LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert(yylval.i, LM_TC_BOP);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_STY:
|
|
|
|
{
|
|
|
|
if (mt) {
|
|
|
|
mt->UserSetSize(yylval.l->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_SPACE:
|
|
|
|
{
|
2000-01-06 02:44:26 +00:00
|
|
|
if (yylval.i >= 0) {
|
1999-11-15 11:06:41 +00:00
|
|
|
MathSpaceInset * sp = new MathSpaceInset(yylval.i);
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(sp, LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_DOTS:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathDotsInset * p = new MathDotsInset(yylval.l->name, yylval.l->id);
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(p, LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
2000-01-06 02:44:26 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
case LM_TK_STACK:
|
|
|
|
fractype = LM_OT_STACKREL;
|
|
|
|
case LM_TK_FRAC:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathFracInset * fc = new MathFracInset(fractype);
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * num = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
|
|
|
|
MathedArray * den = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
|
2001-02-20 16:00:22 +00:00
|
|
|
fc->SetData(*num, *den);
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(fc, LM_TC_ACTIVE_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_SQRT:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathParInset * rt;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
char c; yyis->get(c);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == '[') {
|
1999-09-27 18:44:28 +00:00
|
|
|
rt = new MathRootInset(size);
|
|
|
|
rt->setArgumentIdx(0);
|
2001-02-20 16:00:22 +00:00
|
|
|
rt->setData(*mathed_parse(FLAG_BRACK_END, 0, &rt));
|
1999-09-27 18:44:28 +00:00
|
|
|
rt->setArgumentIdx(1);
|
|
|
|
} else {
|
2000-01-06 02:44:26 +00:00
|
|
|
yyis->putback(c);
|
1999-09-27 18:44:28 +00:00
|
|
|
rt = new MathSqrtInset(size);
|
|
|
|
}
|
2001-02-20 16:00:22 +00:00
|
|
|
rt->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST, 0, &rt));
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(rt, LM_TC_ACTIVE_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_LEFT:
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
int lfd = yylex();
|
1999-11-15 11:06:41 +00:00
|
|
|
if (lfd == LM_TK_SYM || lfd == LM_TK_STR || lfd == LM_TK_BOP|| lfd == LM_TK_SPECIAL)
|
|
|
|
lfd = (lfd == LM_TK_SYM) ? yylval.l->id: yylval.i;
|
1999-10-07 18:44:17 +00:00
|
|
|
// lyxerr << "L[" << lfd << " " << lfd << "]";
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * a = mathed_parse(FLAG_RIGHT);
|
2000-09-26 13:54:57 +00:00
|
|
|
int rgd = yylex();
|
1999-10-07 18:44:17 +00:00
|
|
|
// lyxerr << "R[" << rgd << "]";
|
1999-11-15 11:06:41 +00:00
|
|
|
if (rgd == LM_TK_SYM || rgd == LM_TK_STR || rgd == LM_TK_BOP || rgd == LM_TK_SPECIAL)
|
|
|
|
rgd = (rgd == LM_TK_SYM) ? yylval.l->id: yylval.i;
|
|
|
|
MathDelimInset * dl = new MathDelimInset(lfd, rgd);
|
2001-02-20 16:00:22 +00:00
|
|
|
dl->setData(*a);
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(dl, LM_TC_ACTIVE_INSET);
|
1999-10-07 18:44:17 +00:00
|
|
|
// lyxerr << "RL[" << lfd << " " << rgd << "]";
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_RIGHT:
|
|
|
|
{
|
|
|
|
if (flags & FLAG_RIGHT) {
|
2000-01-24 18:34:46 +00:00
|
|
|
--plevel;
|
1999-09-27 18:44:28 +00:00
|
|
|
return array;
|
|
|
|
} else {
|
|
|
|
mathPrintError("Unmatched right delimiter");
|
|
|
|
// panic = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_FONT:
|
|
|
|
{
|
1999-12-13 00:05:34 +00:00
|
|
|
varcode = static_cast<MathedTextCodes>(yylval.l->id);
|
1999-11-15 11:06:41 +00:00
|
|
|
yy_mtextmode = bool(varcode == LM_TC_TEXTRM);
|
1999-09-27 18:44:28 +00:00
|
|
|
flags |= (FLAG_BRACE|FLAG_BRACE_FONT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_WIDE:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathDecorationInset * sq = new MathDecorationInset(yylval.l->id,
|
|
|
|
size);
|
2001-02-20 16:00:22 +00:00
|
|
|
sq->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(sq, LM_TC_ACTIVE_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
case LM_TK_ACCENT:
|
|
|
|
setAccent(yylval.l->id);
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
case LM_TK_NONUM:
|
|
|
|
{
|
|
|
|
if (crow)
|
|
|
|
crow->setNumbered(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_PMOD:
|
|
|
|
case LM_TK_FUNC:
|
|
|
|
{
|
2001-02-17 18:52:53 +00:00
|
|
|
#warning This must leak. (Lgb)
|
|
|
|
// if (accent) this must leak... (Lgb)
|
1999-11-15 11:06:41 +00:00
|
|
|
MathedInset * bg = new MathFuncInset(yylval.l->name);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insert(t, LM_TC_CONST);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(bg, LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_FUNCLIM:
|
|
|
|
{
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM),
|
|
|
|
LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_UNDEF:
|
|
|
|
{
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
MathMacro * p =
|
1999-09-27 18:44:28 +00:00
|
|
|
MathMacroTable::mathMTable.getMacro(yylval.s);
|
|
|
|
if (p) {
|
|
|
|
if (accent)
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(p), p->getTCode());
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(p, p->getTCode());
|
2000-01-24 18:34:46 +00:00
|
|
|
for (int i = 0; p->setArgumentIdx(i); ++i)
|
2001-02-20 16:00:22 +00:00
|
|
|
p->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-11-15 11:06:41 +00:00
|
|
|
MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(q), LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(q, LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LM_TK_END:
|
|
|
|
{
|
2001-02-03 21:02:22 +00:00
|
|
|
if (mathed_env != yylval.i && yylval.i != LM_OT_MATRIX)
|
1999-09-27 18:44:28 +00:00
|
|
|
mathPrintError("Unmatched environment");
|
|
|
|
// debug info [made that conditional -JMarc]
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::MATHED))
|
|
|
|
lyxerr << "[" << yylval.i << "]" << endl;
|
2000-01-24 18:34:46 +00:00
|
|
|
--plevel;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (mt) { // && (flags & FLAG_END)) {
|
2001-02-20 16:00:22 +00:00
|
|
|
mt->setData(*array);
|
1999-10-02 16:21:10 +00:00
|
|
|
array = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
case LM_TK_BEGIN:
|
|
|
|
{
|
2001-02-03 21:02:22 +00:00
|
|
|
if (yylval.i == LM_OT_MATRIX) {
|
1999-09-27 18:44:28 +00:00
|
|
|
char ar[120], ar2[8];
|
|
|
|
ar[0] = ar2[0] = '\0';
|
2000-01-06 02:44:26 +00:00
|
|
|
char rg = LexGetArg(0);
|
1999-11-15 11:06:41 +00:00
|
|
|
if (rg == ']') {
|
2001-02-16 09:25:43 +00:00
|
|
|
strcpy(ar2, yytext.data());
|
1999-09-27 18:44:28 +00:00
|
|
|
rg = LexGetArg('{');
|
|
|
|
}
|
2001-02-16 09:25:43 +00:00
|
|
|
strcpy(ar, yytext.data());
|
2000-09-26 13:54:57 +00:00
|
|
|
int const nc = parse_align(ar, ar2);
|
1999-11-15 11:06:41 +00:00
|
|
|
MathParInset * mm = new MathMatrixInset(nc, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
mm->SetAlign(ar2[0], ar);
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(mm, LM_TC_ACTIVE_INSET);
|
2001-02-20 16:00:22 +00:00
|
|
|
mathed_parse(FLAG_END, &mm->GetData(), &mm);
|
2001-02-03 21:02:22 +00:00
|
|
|
} else if (is_eqn_type(yylval.i)) {
|
1999-11-15 11:06:41 +00:00
|
|
|
if (plevel!= 0) {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathPrintError("Misplaced environment");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!mt) {
|
1999-10-02 16:21:10 +00:00
|
|
|
mathPrintError("0 paragraph.");
|
1999-09-27 18:44:28 +00:00
|
|
|
panic = true;
|
|
|
|
}
|
|
|
|
|
2001-02-04 07:01:49 +00:00
|
|
|
mathed_env = static_cast<MathedInsetTypes>(yylval.i);
|
2001-02-03 21:02:22 +00:00
|
|
|
if (mathed_env != LM_OT_MIN) {
|
1999-09-27 18:44:28 +00:00
|
|
|
size = LM_ST_DISPLAY;
|
2001-02-03 21:02:22 +00:00
|
|
|
if (is_multiline(mathed_env)) {
|
|
|
|
int cols = 1;
|
|
|
|
if (is_multicolumn(mathed_env)) {
|
2001-02-11 09:58:20 +00:00
|
|
|
if (mathed_env != LM_OT_ALIGNAT &&
|
|
|
|
mathed_env != LM_OT_ALIGNATN &&
|
|
|
|
yyis->good()) {
|
|
|
|
char c;
|
|
|
|
yyis->get(c);
|
|
|
|
if (c != '%')
|
|
|
|
lyxerr << "Math parse error: unexpected '"
|
|
|
|
<< c << "'" << endl;
|
|
|
|
}
|
2001-02-03 21:02:22 +00:00
|
|
|
LexGetArg('{');
|
2001-02-16 09:25:43 +00:00
|
|
|
cols = strToInt(string(yytext.data()));
|
2001-02-03 21:02:22 +00:00
|
|
|
}
|
|
|
|
mt = create_multiline(mathed_env, cols);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (mtx) *mtx = mt;
|
|
|
|
flags |= FLAG_END;
|
|
|
|
// data.Insert(' ', LM_TC_TAB);
|
|
|
|
// data.Insert(' ', LM_TC_TAB);
|
|
|
|
// data.Reset();
|
|
|
|
}
|
|
|
|
mt->SetStyle(size);
|
|
|
|
mt->SetType(mathed_env);
|
|
|
|
crow = mt->getRowSt();
|
|
|
|
}
|
2001-02-03 21:02:22 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#ifdef DEBUG
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "MATH BEGIN[" << mathed_env << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
1999-10-07 18:44:17 +00:00
|
|
|
// lyxerr << "MATHCRO[" << yytext << "]";
|
1999-11-15 11:06:41 +00:00
|
|
|
MathMacro * p =
|
2001-02-16 09:25:43 +00:00
|
|
|
MathMacroTable::mathMTable.getMacro(yytext.data());
|
1999-09-27 18:44:28 +00:00
|
|
|
if (p) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(p, p->getTCode());
|
1999-09-27 18:44:28 +00:00
|
|
|
p->setArgumentIdx(0);
|
2001-02-20 16:00:22 +00:00
|
|
|
mathed_parse(FLAG_END, &p->GetData(), reinterpret_cast<MathParInset**>(&p));
|
2000-01-24 18:34:46 +00:00
|
|
|
// for (int i = 0; p->setArgumentIdx(i); ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
// p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
|
|
|
|
} else
|
|
|
|
mathPrintError("Unrecognized environment");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_MACRO:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
MathedInset * p =
|
1999-09-27 18:44:28 +00:00
|
|
|
MathMacroTable::mathMTable.getMacro(yylval.l->name);
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
if (accent) {
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(doAccent(p), LM_TC_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
2001-02-17 18:52:53 +00:00
|
|
|
data.insertInset(p, static_cast<MathMacro*>(p)->getTCode());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_TK_LABEL:
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
char const rg = LexGetArg('\0', true);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (rg != '}') {
|
|
|
|
mathPrintError("Expected '{'");
|
|
|
|
// debug info
|
2001-02-16 09:25:43 +00:00
|
|
|
lyxerr << "[" << yytext.data() << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
panic = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (crow) {
|
2001-02-16 09:25:43 +00:00
|
|
|
crow->setLabel(yytext.data());
|
2000-09-26 13:54:57 +00:00
|
|
|
} else {
|
2001-02-16 09:25:43 +00:00
|
|
|
mathed_label = yytext.data();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Label[" << mathed_label << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
mathPrintError("Unrecognized token");
|
|
|
|
// debug info
|
2001-02-16 09:25:43 +00:00
|
|
|
lyxerr << "[" << t << " " << yytext.data() << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
tprev = t;
|
|
|
|
if (panic) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << " Math Panic, expect problems!" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// Search for the end command.
|
2000-09-26 13:54:57 +00:00
|
|
|
do {
|
|
|
|
t = yylex ();
|
|
|
|
} while (t != LM_TK_END && t);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
t = yylex ();
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
if ((flags & FLAG_BRACE_OPT)/* && t!= '^' && t!= '_'*/) {
|
1999-09-27 18:44:28 +00:00
|
|
|
flags &= ~FLAG_BRACE_OPT;
|
|
|
|
//data.Insert (LM_TC_CLOSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-01-24 18:34:46 +00:00
|
|
|
--plevel;
|
1999-09-27 18:44:28 +00:00
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
void mathed_parser_file(istream & is, int lineno)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-01-06 02:44:26 +00:00
|
|
|
yyis = &is;
|
1999-09-27 18:44:28 +00:00
|
|
|
yylineno = lineno;
|
|
|
|
if (!MathMacroTable::built)
|
|
|
|
MathMacroTable::mathMTable.builtinMacros();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int mathed_parser_lineno()
|
|
|
|
{
|
|
|
|
return yylineno;
|
|
|
|
}
|
|
|
|
|