lexcode_enum lexcode[256];
-
char const * latex_special_chars = "#$%&_{}";
namespace {
-const char LM_TK_OPEN = '{';
-const char LM_TK_CLOSE = '}';
+const unsigned char LM_TK_OPEN = '{';
+const unsigned char LM_TK_CLOSE = '}';
enum {
FLAG_BRACE = 1 << 0, // A { needed //}
string yytext;
-
int yylineno;
istream * yyis;
-bool yy_mtextmode = false;
+MathTextCodes yyvarcode;
void LexInitCodes()
{
for (int i = 0; i <= 255; ++i) {
- if (isalpha(i))
- lexcode[i] = LexAlpha;
- else if (isdigit(i))
+ if (isdigit(i))
lexcode[i] = LexDigit;
else if (isspace(i))
lexcode[i] = LexSpace;
else
- lexcode[i] = LexNone;
+ lexcode[i] = LexAlpha;
}
lexcode['\t'] = lexcode['\f'] = lexcode[' '] = LexSpace;
}
-char LexGetArg(char lf, bool accept_spaces = false)
+unsigned char LexGetArg(unsigned char lf, bool accept_spaces = false)
{
while (yyis->good()) {
- char c;
+ unsigned char c;
yyis->get(c);
if (c > ' ') {
if (!lf)
break;
}
}
- char rg = 0;
+ unsigned char rg = 0;
if (lf == '{') rg = '}';
if (lf == '[') rg = ']';
if (lf == '(') rg = ')';
yytext.erase();
int bcnt = 1;
do {
- char c;
+ unsigned char c;
yyis->get(c);
if (c == lf) ++bcnt;
if (c == rg) --bcnt;
if (!init_done) LexInitCodes();
while (yyis->good()) {
- char c;
+ unsigned char c;
yyis->get(c);
+ lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
+ lyxerr << " code: " << lexcode['ΓΌ'] << endl;
- if (yy_mtextmode && c == ' ') {
- yylval.i= ' ';
+ if (yyvarcode == LM_TC_TEXTRM && c == ' ') {
+ yylval.i = ' ';
return LM_TK_ALPHA;
} else if (lexcode[c] == LexNewLine) {
++yylineno;
}
-MathInset * doAccent(byte c, MathTextCodes t)
+MathInset * doAccent(unsigned char c, MathTextCodes t)
{
MathInset * ac = 0;
dat.push_back(m);
}
-void do_insert(MathArray & dat, byte ch, MathTextCodes fcode)
+void do_insert(MathArray & dat, unsigned char ch, MathTextCodes fcode)
{
if (accent)
dat.push_back(doAccent(ch, fcode));
MathScriptInset * lastScriptInset(MathArray & array)
{
MathInset * p = array.back_inset();
- if (!p || p->GetType() != LM_OT_SCRIPT) {
+ if (!p || !p->isScriptInset()) {
p = new MathScriptInset;
array.push_back(p);
}
static bool curr_num;
static string curr_label;
-void mathed_parse_lines(MathInset * inset, int col)
+void mathed_parse_lines(MathInset * inset, int col, bool numbered, bool outmost)
{
+ // save global variables
+ bool saved_num = curr_num;
+ string saved_label = curr_label;
+
MathGridInset * p = static_cast<MathGridInset *>(inset);
- while (1) {
+ for (int row = 0; true; ++row) {
// reset global variables
- curr_num = true;
+ curr_num = numbered;
curr_label = string();
// reading a row
mathed_parse(p->cell(idx), FLAG_AMPERSAND);
mathed_parse(p->cell(idx), FLAG_NEWLINE | FLAG_END);
+ if (outmost) {
+ MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
+ m->numbered(row, curr_num);
+ m->label(row, curr_label);
+ }
+
// Hack!
// no newline
if (yylval.i != -1)
p->appendRow();
}
+
+ // restore global variables
+ curr_num = saved_num;
+ curr_label = saved_label;
}
string name = yytext.substr(1);
int na = 0;
- char const c = yyis->peek();
+ unsigned char const c = yyis->peek();
if (c == '[') {
LexGetArg('[');
na = atoi(yytext.c_str());
switch (typ) {
case LM_OT_SIMPLE: {
+ curr_num = latex_mathenv[i].numbered;
+ curr_label = string();
mathed_parse(p->cell(0), 0);
+ MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
+ m->numbered(0, curr_num);
+ m->label(0, curr_label);
break;
}
case LM_OT_EQUATION: {
+ curr_num = latex_mathenv[i].numbered;
+ curr_label = string();
mathed_parse(p->cell(0), FLAG_END);
+ MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
+ m->numbered(0, curr_num);
+ m->label(0, curr_label);
break;
}
case LM_OT_EQNARRAY: {
- mathed_parse_lines(p, 3);
+ mathed_parse_lines(p, 3, latex_mathenv[i].numbered, true);
break;
}
LexGetArg('{');
//int c = atoi(yytext.c_str());
lyxerr << "LM_OT_ALIGNAT: not implemented\n";
- mathed_parse_lines(p, 2);
+ mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true);
lyxerr << "LM_OT_ALIGNAT: par: " << *p << "\n";
break;
}
p->SetName(latex_mathenv[i].basename);
-/*
- curr_num = latex_mathenv[i].numbered;
- p->numbered(p->nrows()-1, curr_num);
-*/
break;
}
int tprev = 0;
bool panic = false;
static int plevel = -1;
- MathTextCodes varcode = LM_TC_VAR;
+ yyvarcode = LM_TC_VAR;
int brace = 0;
int acc_brace = 0;
switch (t) {
case LM_TK_ALPHA:
- do_insert(array, yylval.i, varcode);
+ do_insert(array, yylval.i, yyvarcode);
break;
case LM_TK_ARGUMENT:
break;
}
if (flags & FLAG_BRACE_FONT) {
- varcode = LM_TC_VAR;
- yy_mtextmode = false;
+ yyvarcode = LM_TC_VAR;
flags &= ~FLAG_BRACE_FONT;
break;
}
case '[':
if (flags & FLAG_BRACK_ARG) {
flags &= ~FLAG_BRACK_ARG;
- char const rg = LexGetArg('[');
+ unsigned char const rg = LexGetArg('[');
if (rg != ']') {
mathPrintError("Expected ']'");
panic = true;
{
MathScriptInset * p = lastScriptInset(array);
if (p)
- p->SetLimits(bool(yylval.l->id));
+ p->limits(yylval.l->id ? 1 : -1);
break;
}
case LM_TK_SQRT:
{
- char c;
+ unsigned char c;
yyis->get(c);
if (c == '[') {
MathRootInset * rt = new MathRootInset;
break;
case LM_TK_FONT:
- yy_mtextmode = (yylval.l->id == LM_TC_TEXTRM);
+ yyvarcode = static_cast<MathTextCodes>(yylval.l->id);
flags |= (FLAG_BRACE | FLAG_BRACE_FONT);
break;
lyxerr << "reading cell " << i << " '" << m->cell(i) << "'\n";
}
do_insert(array, m);
+ lyxerr << "macro: " << *m << "\n";
+ m->Metrics(LM_ST_TEXT);
} else
do_insert(array, new MathFuncInset(yytext, LM_OT_UNDEF));
break;
if (typ == LM_OT_MATRIX) {
string valign = "\0";
- char rg = LexGetArg(0);
+ unsigned char rg = LexGetArg(0);
if (rg == ']') {
valign = yytext;
rg = LexGetArg('{');
mm->valign(valign[0]);
mm->halign(halign);
- mathed_parse_lines(mm, halign.size());
+ mathed_parse_lines(mm, halign.size(), latex_mathenv[i].numbered, false);
do_insert(array, mm);
//lyxerr << "read matrix " << *mm << "\n";
break;
case LM_TK_LABEL:
{
- char const rg = LexGetArg('\0', true);
+ unsigned char const rg = LexGetArg('\0', true);
if (rg != '}') {
mathPrintError("Expected '{'");
// debug info