]> git.lyx.org Git - features.git/commitdiff
Fix bug 3034
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 19 Dec 2006 14:24:25 +0000 (14:24 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 19 Dec 2006 14:24:25 +0000 (14:24 +0000)
* 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

Status.15x
src/mathed/InsetMathGrid.C
src/mathed/MathMacroTemplate.C
src/mathed/MathParser.C
src/mathed/MathParser.h

index 7252506df34836345a6e3c33516d758b9bef8ac1..1aaa177ae6a107eed758a333ebc3c4ed535142db 100644 (file)
@@ -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;\"></p></body></html>"
   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.
+
index 46eed9db8e225e3dfa09d79ffc640a14b168eaf2..bf987daf33057274c12d595401355d6715fd7cc2 100644 (file)
@@ -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);
index aedca146127426e2ea754d7925adf659ed24a4e4..a78756f3371b9e74ec9abbcae94d6900d7758484 100644 (file)
@@ -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;
index abbe9e90c4c9174924bb5251959994a539ae0910..9bab600667831c08ce0ce4deb08b133be8e61abf 100644 (file)
@@ -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<int>(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);
 }
 
 
index a64b85d66e3f9f74046e739f70ac2b3220fd8a1e..2fb712fa1124aecc43231c9c96b6ac56db70132e 100644 (file)
@@ -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();