]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathParser.cpp
Change the interface to a paragraph's layout. We still store a LayoutPtr, but now...
[lyx.git] / src / mathed / MathParser.cpp
index 26cf14f4979616a684817309aa9acc9a389a20df..e14c925d6ef9e26867ddf932b4e6b6b182dcfbce 100644 (file)
@@ -63,27 +63,18 @@ following hack as starting point to write some macros:
 #include "MathSupport.h"
 
 #include "Lexer.h"
-#include "debug.h"
 
+#include "support/debug.h"
 #include "support/convert.h"
+#include "support/docstream.h"
 
 #include <sstream>
 
-
-namespace lyx {
-
-using std::endl;
-using std::fill;
-
-using std::string;
-using std::ios;
-using std::istream;
-using std::ostream;
-using std::vector;
-
-
 //#define FILEDEBUG
 
+using namespace std;
+
+namespace lyx {
 
 namespace {
 
@@ -111,7 +102,7 @@ bool stared(docstring const & s)
  * environments like "equation" that have a fixed number of rows.
  */
 bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow,
-           docstring const & vskip, bool allow_pagebreak = true)
+           docstring const & vskip, bool allow_newpage_ = true)
 {
        ++cellrow;
        if (cellrow == grid.nrows()) {
@@ -128,14 +119,14 @@ bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow,
                        lyxerr << "ignoring extra row";
                        if (!vskip.empty())
                                lyxerr << " with extra space " << to_utf8(vskip);
-                       if (!allow_pagebreak)
+                       if (!allow_newpage_)
                                lyxerr << " with no page break allowed";
                        lyxerr << '.' << endl;
                        return false;
                }
        }
        grid.vcrskip(Length(to_utf8(vskip)), cellrow - 1);
-       grid.rowinfo(cellrow - 1).allow_pagebreak_ = allow_pagebreak;
+       grid.rowinfo(cellrow - 1).allow_newpage_ = allow_newpage_;
        return true;
 }
 
@@ -316,7 +307,7 @@ public:
        ///
        Parser(Lexer & lex);
        /// Only use this for reading from .lyx file format, for the reason
-       /// see Parser::tokenize(std::istream &).
+       /// see Parser::tokenize(istream &).
        Parser(istream & is);
        ///
        Parser(docstring const & str);
@@ -463,8 +454,11 @@ bool Parser::good() const
 
 char_type Parser::getChar()
 {
-       if (!good())
+       if (!good()) {
                error("The input stream is not well...");
+               putback();
+               return 0;
+       }
        return tokens_[pos_++].character();
 }
 
@@ -900,14 +894,17 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                else if (t.cs() == "def" ||
                        t.cs() == "newcommand" ||
-                       t.cs() == "renewcommand")
+                       t.cs() == "renewcommand" ||
+                       t.cs() == "newlyxcommand")
                {
-                       docstring const type = t.cs();
+                       MacroType type = MacroTypeNewcommand;
+                       if (t.cs() == "def")
+                               type = MacroTypeDef;
                        docstring name;
                        int nargs = 0;
                        int optionals = 0;
-                       std::vector<MathData> optionalValues;
-                       if (t.cs() == "def") {
+                       vector<MathData> optionalValues;
+                       if (type == MacroTypeDef) {
                                // get name
                                name = getToken().cs();
 
@@ -920,7 +917,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                nargs /= 2;
                                //lyxerr << "read \\def parameter list '" << pars << "'" << endl;
 
-                       } else { // t.cs() == "newcommand" || t.cs() == "renewcommand"
+                       } else {
                                if (getToken().cat() != catBegin) {
                                        error("'{' in \\newcommand expected (1) ");
                                        return;
@@ -1018,12 +1015,14 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
                else if (t.cs() == "\\") {
                        if (flags & FLAG_ALIGN)
                                return;
-                       bool added;
+                       bool added = false;
                        if (nextToken().asInput() == "*") {
                                getToken();
                                added = addRow(grid, cellrow, docstring(), false);
-                       } else
+                       } else if (good())
                                added = addRow(grid, cellrow, getArg('[', ']'));
+                       else
+                               error("missing token after \\\\");
                        if (added) {
                                cellcol = 0;
                                if (grid.asHullInset())
@@ -1267,7 +1266,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                               << to_utf8(l->inset) << "'." << endl;
                                        // create generic environment inset
                                        cell->push_back(MathAtom(new InsetMathEnv(name)));
-                                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
+                                       parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
                                }
                        }
 
@@ -1277,7 +1276,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                        << "'" << endl;
                                // create generic environment inset
                                cell->push_back(MathAtom(new InsetMathEnv(name)));
-                               parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
+                               parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
                        }
                }