mathed34.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1578 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-20 17:45:56 +00:00
parent 04a2d2ddb0
commit fbb9a99704
5 changed files with 46 additions and 31 deletions

View File

@ -9,6 +9,8 @@
* math_cursor.C: make selarray a proper MathArray * math_cursor.C: make selarray a proper MathArray
* several files: Change "MathedArray *" to "MathedArray &"
2001-02-19 Dekel Tsur <dekelts@tau.ac.il> 2001-02-19 Dekel Tsur <dekelts@tau.ac.il>

View File

@ -305,7 +305,8 @@ void InsetFormula::Read(Buffer const *, LyXLex & lex)
// Silly hack to read labels. // Silly hack to read labels.
mathed_label.erase(); mathed_label.erase();
mathed_parse(0, 0, &par); MathedArray ar;
mathed_parse(ar, 0, &par);
par->Metrics(); par->Metrics();
disp_flag = (par->GetType() > 0); disp_flag = (par->GetType() > 0);

View File

@ -101,7 +101,8 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
{ {
istream & is = lex.getStream(); istream & is = lex.getStream();
mathed_parser_file(is, lex.GetLineNo()); mathed_parser_file(is, lex.GetLineNo());
mathed_parse(0, 0, reinterpret_cast<MathParInset **>(&tmacro)); MathedArray ar;
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro));
// Update line number // Update line number
lex.setLineNo(mathed_parser_lineno()); lex.setLineNo(mathed_parser_lineno());

View File

@ -405,7 +405,7 @@ MathedInset * doAccent(MathedInset * p)
} }
MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, void mathed_parse(MathedArray & array, unsigned flags = 0,
MathParInset ** mtx = 0) MathParInset ** mtx = 0)
{ {
int t = yylex(); int t = yylex();
@ -424,8 +424,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
MathedRowSt * crow = (mt) ? mt->getRowSt() : 0; MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
++plevel; ++plevel;
if (!array) array = new MathedArray; MathedIter data(&array);
MathedIter data(array);
while (t) { while (t) {
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) { if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
if ((flags & FLAG_BRACK_ARG) && t == '[') { if ((flags & FLAG_BRACK_ARG) && t == '[') {
@ -469,7 +468,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
macro = new MathMacroTemplate(name, na); macro = new MathMacroTemplate(name, na);
flags = FLAG_BRACE|FLAG_BRACE_LAST; flags = FLAG_BRACE|FLAG_BRACE_LAST;
*mtx = macro; *mtx = macro;
macro->setData(*array); macro->setData(array);
break; break;
} }
case LM_TK_SPECIAL: case LM_TK_SPECIAL:
@ -524,7 +523,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
} }
if (brace == 0 && (flags & FLAG_BRACE_LAST)) { if (brace == 0 && (flags & FLAG_BRACE_LAST)) {
--plevel; --plevel;
return array; return;
} else { } else {
data.insert('}', LM_TC_TEX); data.insert('}', LM_TC_TEX);
} }
@ -550,7 +549,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
{ {
if (flags & FLAG_BRACK_END) { if (flags & FLAG_BRACK_END) {
--plevel; --plevel;
return array; return;
} else } else
data.insert(']', LM_TC_CONST); data.insert(']', LM_TC_CONST);
break; break;
@ -559,8 +558,9 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
case '^': case '^':
{ {
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT); MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0); MathedArray ar;
p->setData(*ar); mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar);
// lyxerr << "UP[" << p->GetStyle() << "]" << endl; // lyxerr << "UP[" << p->GetStyle() << "]" << endl;
data.insertInset(p, LM_TC_UP); data.insertInset(p, LM_TC_UP);
break; break;
@ -568,8 +568,9 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
case '_': case '_':
{ {
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT); MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0); MathedArray ar;
p->setData(*ar); mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar);
data.insertInset(p, LM_TC_DOWN); data.insertInset(p, LM_TC_DOWN);
break; break;
} }
@ -670,9 +671,11 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
case LM_TK_FRAC: case LM_TK_FRAC:
{ {
MathFracInset * fc = new MathFracInset(fractype); MathFracInset * fc = new MathFracInset(fractype);
MathedArray * num = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST); MathedArray num;
MathedArray * den = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST); mathed_parse(num, FLAG_BRACE|FLAG_BRACE_LAST);
fc->SetData(*num, *den); MathedArray den;
mathed_parse(den, FLAG_BRACE|FLAG_BRACE_LAST);
fc->SetData(num, den);
data.insertInset(fc, LM_TC_ACTIVE_INSET); data.insertInset(fc, LM_TC_ACTIVE_INSET);
break; break;
} }
@ -685,13 +688,17 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
if (c == '[') { if (c == '[') {
rt = new MathRootInset(size); rt = new MathRootInset(size);
rt->setArgumentIdx(0); rt->setArgumentIdx(0);
rt->setData(*mathed_parse(FLAG_BRACK_END, 0, &rt)); MathedArray ar;
mathed_parse(ar, FLAG_BRACK_END, &rt);
rt->setData(ar);
rt->setArgumentIdx(1); rt->setArgumentIdx(1);
} else { } else {
yyis->putback(c); yyis->putback(c);
rt = new MathSqrtInset(size); rt = new MathSqrtInset(size);
} }
rt->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST, 0, &rt)); MathedArray ar;
mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST, &rt);
rt->setData(ar);
data.insertInset(rt, LM_TC_ACTIVE_INSET); data.insertInset(rt, LM_TC_ACTIVE_INSET);
break; break;
} }
@ -702,13 +709,14 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
if (lfd == LM_TK_SYM || lfd == LM_TK_STR || lfd == LM_TK_BOP|| lfd == LM_TK_SPECIAL) 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; lfd = (lfd == LM_TK_SYM) ? yylval.l->id: yylval.i;
// lyxerr << "L[" << lfd << " " << lfd << "]"; // lyxerr << "L[" << lfd << " " << lfd << "]";
MathedArray * a = mathed_parse(FLAG_RIGHT); MathedArray ar;
mathed_parse(ar, FLAG_RIGHT);
int rgd = yylex(); int rgd = yylex();
// lyxerr << "R[" << rgd << "]"; // lyxerr << "R[" << rgd << "]";
if (rgd == LM_TK_SYM || rgd == LM_TK_STR || rgd == LM_TK_BOP || rgd == LM_TK_SPECIAL) 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; rgd = (rgd == LM_TK_SYM) ? yylval.l->id: yylval.i;
MathDelimInset * dl = new MathDelimInset(lfd, rgd); MathDelimInset * dl = new MathDelimInset(lfd, rgd);
dl->setData(*a); dl->setData(ar);
data.insertInset(dl, LM_TC_ACTIVE_INSET); data.insertInset(dl, LM_TC_ACTIVE_INSET);
// lyxerr << "RL[" << lfd << " " << rgd << "]"; // lyxerr << "RL[" << lfd << " " << rgd << "]";
break; break;
@ -717,7 +725,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
{ {
if (flags & FLAG_RIGHT) { if (flags & FLAG_RIGHT) {
--plevel; --plevel;
return array; return;
} else { } else {
mathPrintError("Unmatched right delimiter"); mathPrintError("Unmatched right delimiter");
// panic = true; // panic = true;
@ -736,7 +744,9 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
{ {
MathDecorationInset * sq = new MathDecorationInset(yylval.l->id, MathDecorationInset * sq = new MathDecorationInset(yylval.l->id,
size); size);
sq->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST)); MathedArray ar;
mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST);
sq->setData(ar);
data.insertInset(sq, LM_TC_ACTIVE_INSET); data.insertInset(sq, LM_TC_ACTIVE_INSET);
break; break;
} }
@ -780,8 +790,11 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
data.insertInset(doAccent(p), p->getTCode()); data.insertInset(doAccent(p), p->getTCode());
else else
data.insertInset(p, p->getTCode()); data.insertInset(p, p->getTCode());
for (int i = 0; p->setArgumentIdx(i); ++i) for (int i = 0; p->setArgumentIdx(i); ++i) {
p->setData(*mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST)); MathedArray ar;
mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST);
p->setData(ar);
}
} }
else { else {
MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF); MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF);
@ -802,10 +815,10 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
lyxerr << "[" << yylval.i << "]" << endl; lyxerr << "[" << yylval.i << "]" << endl;
--plevel; --plevel;
if (mt) { // && (flags & FLAG_END)) { if (mt) { // && (flags & FLAG_END)) {
mt->setData(*array); mt->setData(array);
array = 0; array.clear();
} }
return array; return;
} }
case LM_TK_BEGIN: case LM_TK_BEGIN:
{ {
@ -822,7 +835,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
MathParInset * mm = new MathMatrixInset(nc, 0); MathParInset * mm = new MathMatrixInset(nc, 0);
mm->SetAlign(ar2[0], ar); mm->SetAlign(ar2[0], ar);
data.insertInset(mm, LM_TC_ACTIVE_INSET); data.insertInset(mm, LM_TC_ACTIVE_INSET);
mathed_parse(FLAG_END, &mm->GetData(), &mm); mathed_parse(mm->GetData(), FLAG_END, &mm);
} else if (is_eqn_type(yylval.i)) { } else if (is_eqn_type(yylval.i)) {
if (plevel!= 0) { if (plevel!= 0) {
mathPrintError("Misplaced environment"); mathPrintError("Misplaced environment");
@ -873,7 +886,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
if (p) { if (p) {
data.insertInset(p, p->getTCode()); data.insertInset(p, p->getTCode());
p->setArgumentIdx(0); p->setArgumentIdx(0);
mathed_parse(FLAG_END, &p->GetData(), reinterpret_cast<MathParInset**>(&p)); mathed_parse(p->GetData(), FLAG_END, reinterpret_cast<MathParInset**>(&p));
// for (int i = 0; p->setArgumentIdx(i); ++i) // for (int i = 0; p->setArgumentIdx(i); ++i)
// p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST)); // p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
} else } else
@ -939,7 +952,6 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
} }
} }
--plevel; --plevel;
return array;
} }

View File

@ -36,8 +36,7 @@ extern math_deco_struct const * search_deco(int code);
/// math_parser.C /// math_parser.C
extern extern
MathedArray * mathed_parse(unsigned flags, MathedArray * data, void mathed_parse(MathedArray & data, unsigned flags, MathParInset ** mt);
MathParInset ** mt);
/// math_parser.C /// math_parser.C
extern extern