From: Georg Baum Date: Tue, 19 Dec 2006 14:24:25 +0000 (+0000) Subject: Fix bug 3034 X-Git-Tag: 1.6.10~11502 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1ca55d1c8f1bc16d80db26d287ecf6f1a8e51aee;p=features.git 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) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16334 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/Status.15x b/Status.15x index 7252506df3..1aaa177ae6 100644 --- a/Status.15x +++ b/Status.15x @@ -42,13 +42,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" @@ -607,3 +600,14 @@ CREDITS: "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">

" msgstr "" FIXED (JSpitzm 2006-12-19) + +* 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. + diff --git a/src/mathed/InsetMathGrid.C b/src/mathed/InsetMathGrid.C index 46eed9db8e..bf987daf33 100644 --- a/src/mathed/InsetMathGrid.C +++ b/src/mathed/InsetMathGrid.C @@ -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 & cur, FuncRequest & cmd) 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); diff --git a/src/mathed/MathMacroTemplate.C b/src/mathed/MathMacroTemplate.C index aedca14612..a78756f337 100644 --- a/src/mathed/MathMacroTemplate.C +++ b/src/mathed/MathMacroTemplate.C @@ -105,9 +105,6 @@ docstring MathMacroTemplate::name() const 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 & p, int x, int y) const 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; diff --git a/src/mathed/MathParser.C b/src/mathed/MathParser.C index abbe9e90c4..9bab600667 100644 --- a/src/mathed/MathParser.C +++ b/src/mathed/MathParser.C @@ -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, unsigned flags, return; } - docstring const arg = getArg('[', ']'); + docstring const arg = getArg('[', ']'); if (!arg.empty()) nargs = convert(arg); @@ -1423,8 +1433,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, 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, istream & is) } -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, LyXLex & lex) } -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); } diff --git a/src/mathed/MathParser.h b/src/mathed/MathParser.h index a64b85d66e..2fb712fa11 100644 --- a/src/mathed/MathParser.h +++ b/src/mathed/MathParser.h @@ -63,16 +63,15 @@ latexkeys const * in_word_set(docstring const & str); /// 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();