This patch fixes bug 3034. It was introduced in denmark by the brute force conversion of mathed to docstring without understanding the details.
Please test with as obscure math contents as possible, since this changes a central part of the code in math parsing. This will go in on monday if nobody finds a problem. Log: Fix bug 3034 * src/mathed/InsetMathGrid.C: Don't declare mathed_parse_normal, include MathParser.h instead (InsetMathGrid::doDispatch): remove to_utf8, mathed_parse_normal takes now a docstring * src/mathed/MathMacroTemplate.C (MathMacroTemplate::read): restore the version of 1.4.x, since the new one did only work for macros without whitespace * src/mathed/MathParser.[Ch] (Parser): Add constructor from a docstring (mathed_parse_cell): Create the parser directly from the string, since the istream variant of tokenize() does only work if reading from the .lyx file (mathed_parse_normal): ditto (mathed_parse_normal): Delete the istream variant (unused)
Index: src/mathed/InsetMathGrid.C =================================================================== --- src/mathed/InsetMathGrid.C (Revision 16313) +++ src/mathed/InsetMathGrid.C (Arbeitskopie) @@ -12,6 +12,7 @@ #include "InsetMathGrid.h" #include "MathData.h" +#include "MathParser.h" #include "MathStream.h" #include "BufferView.h" @@ -75,8 +76,6 @@ protected: }; -void mathed_parse_normal(InsetMathGrid &, string const & argument); - namespace { docstring verboseHLine(int n) @@ -1215,9 +1214,7 @@ void InsetMathGrid::doDispatch(LCursor & int n = 0; is >> n; InsetMathGrid grid(1, 1); - // FIXME UNICODE - mathed_parse_normal(grid, - to_utf8(lyx::cap::getSelection(cur.buffer(), n))); + mathed_parse_normal(grid, cap::getSelection(cur.buffer(), n)); if (grid.nargs() == 1) { // single cell/part of cell recordUndo(cur); Index: src/mathed/MathMacroTemplate.C =================================================================== --- src/mathed/MathMacroTemplate.C (Revision 16313) +++ src/mathed/MathMacroTemplate.C (Arbeitskopie) @@ -105,9 +105,6 @@ docstring MathMacroTemplate::name() cons docstring MathMacroTemplate::prefix() const { - // FIXME UNICODE - // delete the conversion when bformat() will return a docstring. - // delete the conversion when bformat() takes a docstring arg. return bformat(_(" Macro: %1$s: "), name_); } @@ -176,12 +173,7 @@ void MathMacroTemplate::draw(PainterInfo void MathMacroTemplate::read(Buffer const &, LyXLex & lex) { MathArray ar; - lex.next(); // eat \begin_inset FormulaMacro line - docstring const str = lex.getDocString(); - lex.next(); // eat that macro definition - lex.next(); // eat the \\end_insrt line - //lyxerr << "Got to read from: " << to_utf8(str) << endl; - mathed_parse_cell(ar, str); + mathed_parse_cell(ar, lex.getStream()); if (ar.size() != 1 || !ar[0]->asMacroTemplate()) { lyxerr << "Cannot read macro from '" << ar << "'" << endl; lyxerr << "Read: " << to_utf8(asString(ar)) << endl; Index: src/mathed/MathParser.C =================================================================== --- src/mathed/MathParser.C (Revision 16313) +++ src/mathed/MathParser.C (Arbeitskopie) @@ -78,7 +78,6 @@ using std::fill; using std::string; using std::ios; using std::istream; -using std::istringstream; using std::ostream; using std::vector; @@ -302,8 +301,11 @@ public: /// Parser(LyXLex & lex); - /// + /// Only use this for reading from .lyx file format, for the reason + /// see Parser::tokenize(std::istream &). Parser(istream & is); + /// + Parser(docstring const & str); /// bool parse(MathAtom & at); @@ -331,7 +333,8 @@ private: void error(docstring const & msg) { error(to_utf8(msg)); } /// dump contents to screen void dump() const; - /// + /// Only use this for reading from .lyx file format (see + /// implementation for reason) void tokenize(istream & is); /// void tokenize(docstring const & s); @@ -384,6 +387,13 @@ Parser::Parser(istream & is) } +Parser::Parser(docstring const & str) + : lineno_(0), pos_(0) +{ + tokenize(str); +} + + void Parser::push_back(Token const & t) { tokens_.push_back(t); @@ -477,7 +487,7 @@ void Parser::tokenize(istream & is) { // eat everything up to the next \end_inset or end of stream // and store it in s for further tokenization - std::string s; + string s; char c; while (is.get(c)) { s += c; @@ -908,7 +918,7 @@ void Parser::parse1(InsetMathGrid & grid return; } - docstring const arg = getArg('[', ']'); + docstring const arg = getArg('[', ']'); if (!arg.empty()) nargs = convert<int>(arg); @@ -1423,8 +1433,7 @@ void Parser::parse1(InsetMathGrid & grid void mathed_parse_cell(MathArray & ar, docstring const & str) { - istringstream is(to_utf8(str)); - mathed_parse_cell(ar, is); + Parser(str).parse(ar, 0, InsetMath::MATH_MODE); } @@ -1434,16 +1443,9 @@ void mathed_parse_cell(MathArray & ar, i } -bool mathed_parse_normal(MathAtom & t, string const & str) -{ - istringstream is(str); - return Parser(is).parse(t); -} - - -bool mathed_parse_normal(MathAtom & t, istream & is) +bool mathed_parse_normal(MathAtom & t, docstring const & str) { - return Parser(is).parse(t); + return Parser(str).parse(t); } @@ -1453,10 +1455,9 @@ bool mathed_parse_normal(MathAtom & t, L } -void mathed_parse_normal(InsetMathGrid & grid, string const & str) +void mathed_parse_normal(InsetMathGrid & grid, docstring const & str) { - istringstream is(str); - Parser(is).parse1(grid, 0, InsetMath::MATH_MODE, false); + Parser(str).parse1(grid, 0, InsetMath::MATH_MODE, false); } Index: src/mathed/MathParser.h =================================================================== --- src/mathed/MathParser.h (Revision 16313) +++ src/mathed/MathParser.h (Arbeitskopie) @@ -63,16 +63,15 @@ latexkeys const * in_word_set(docstring /// parse formula from a string bool mathed_parse_normal(MathAtom &, docstring const &); -/// ... a stream -bool mathed_parse_normal(MathAtom &, std::istream &); /// ... the LyX lexxer bool mathed_parse_normal(MathAtom &, LyXLex &); -/// ... the LyX lexxer +/// parse formula from a string into a grid void mathed_parse_normal(InsetMathGrid &, docstring const &); /// parse a single cell from a string void mathed_parse_cell(MathArray & ar, docstring const &); -/// ... a stream +/// parse a single cell from a stream. Only use this for reading from .lyx +/// file format, for the reason see Parser::tokenize(std::istream &). void mathed_parse_cell(MathArray & ar, std::istream &); void initParser(); Index: Status.15x =================================================================== --- Status.15x (Revision 16313) +++ Status.15x (Arbeitskopie) @@ -36,13 +36,6 @@ ICONS: FILE -* Loading de_Userguide.lyx results in two parse errors: - Paragraph ended in line 21206 - Missing \end_layout. - Paragraph ended in line 21301 - Missing \end_layout. - I don't know if that is a lyx2lyx or LyX problem. LyX 1.4 can read the file. - * Change Tools->Preferences->User interface->User interface to something like "kornel.default.ui"; save prefs; exit LyX; restart LyX; => crash; in the preferences file, there is an entry \bind_file "/Something/kornel.default" @@ -600,3 +593,13 @@ CREDITS: * In the citation dialog, the shortcut for "&Find" does not work FIXED (JSpitzm 2006-12-17) +* Loading de_Userguide.lyx results in two parse errors: + Paragraph ended in line 21206 + Missing \end_layout. + Paragraph ended in line 21301 + Missing \end_layout. + I don't know if that is a lyx2lyx or LyX problem. LyX 1.4 can read the file. + FIXED (Georg 2006-12-17). It turned out that it was a math parser problem + (bug 3034). It was introduced by the conversion of mathed to unicode, + because two methods Parser::tokenize() with different semantics existed. +