From e5e39c1884914867257d409732922be2c194d409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 7 Feb 2002 09:47:21 +0000 Subject: [PATCH] bugfix: in some cases the parser created unecessary extra braces git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3499 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_braceinset.h | 2 ++ src/mathed/math_inset.h | 2 ++ src/mathed/math_parser.C | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mathed/math_braceinset.h b/src/mathed/math_braceinset.h index 6a9c086575..88031d383f 100644 --- a/src/mathed/math_braceinset.h +++ b/src/mathed/math_braceinset.h @@ -20,6 +20,8 @@ public: /// MathInset * clone() const; /// + MathBraceInset * asBraceInset() { return this; } + /// void draw(Painter &, int x, int y) const; /// void write(WriteStream & os) const; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 015d15df79..42957a9b6e 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -47,6 +47,7 @@ inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset. class MathArrayInset; +class MathBraceInset; class MathBoxInset; class MathCharInset; class MathDelimInset; @@ -176,6 +177,7 @@ public: /// identifies certain types of insets virtual MathArrayInset * asArrayInset() { return 0; } + virtual MathBraceInset * asBraceInset() { return 0; } virtual MathBoxInset * asBoxInset() { return 0; } virtual MathBoxInset const * asBoxInset() const { return 0; } virtual MathCharInset const * asCharInset() const { return 0; } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 4a94e204fa..313d235444 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -256,6 +256,8 @@ public: void putback(); private: + /// + void parse_into1(MathArray & array, unsigned flags, MathTextCodes); /// string getArg(char lf, char rf); /// @@ -521,6 +523,7 @@ void Parser::error(string const & msg) } + bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost) { MathGridInset * p = t->asGridInset(); @@ -545,7 +548,11 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost) for (MathInset::col_type col = 0; col < p->ncols(); ++col) { //lyxerr << "reading cell " << row << " " << col << "\n"; - parse_into(p->cell(col + row * p->ncols()), FLAG_BLOCK); + MathArray & ar = p->cell(col + row * p->ncols()); + parse_into(ar, FLAG_BLOCK); + // remove 'unnecessary' braces: + if (ar.size() == 1 && ar.back()->asBraceInset()) + ar = ar.back()->asBraceInset()->cell(0); // break if cell is not followed by an ampersand if (nextToken().cat() != catAlign) { @@ -824,6 +831,15 @@ bool Parser::parse_normal(MathAtom & matrix) void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) +{ + parse_into1(array, flags, code); + // remove 'unnecessary' braces: + if (array.size() == 1 && array.back()->asBraceInset()) + array = array.back()->asBraceInset()->cell(0); +} + + +void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) { bool panic = false; int limits = 0;