#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 {
* 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()) {
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;
}
++cellcol;
if (cellcol == grid.ncols()) {
//lyxerr << "adding column " << cellcol << endl;
- grid.addCol(cellcol - 1);
+ grid.addCol(cellcol);
if (cellcol == grid.ncols()) {
// We can't add a column to this grid, so let's
// append the content of this cell to the previous
///
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);
char_type Parser::getChar()
{
- if (!good())
+ if (!good()) {
error("The input stream is not well...");
+ putback();
+ return 0;
+ }
return tokens_[pos_++].character();
}
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;
- if (t.cs() == "def") {
+ int optionals = 0;
+ vector<MathData> optionalValues;
+ if (type == MacroTypeDef) {
// get name
name = getToken().cs();
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;
if (!arg.empty())
nargs = convert<int>(arg);
+ // optional argument given?
+ skipSpaces();
+ while (nextToken().character() == '[') {
+ getToken();
+ optionalValues.push_back(MathData());
+ parse(optionalValues[optionals], FLAG_BRACK_LAST, mode);
+ ++optionals;
+ }
}
- MathData ar1;
- parse(ar1, FLAG_ITEM, InsetMath::UNDECIDED_MODE);
-
- // we cannot handle recursive stuff at all
- //MathData test;
- //test.push_back(createInsetMath(name));
- //if (ar1.contains(test)) {
- // error("we cannot handle recursive macros at all.");
- // return;
- //}
+ MathData def;
+ parse(def, FLAG_ITEM, InsetMath::UNDECIDED_MODE);
// is a version for display attached?
skipSpaces();
- MathData ar2;
+ MathData display;
if (nextToken().cat() == catBegin)
- parse(ar2, FLAG_ITEM, InsetMath::MATH_MODE);
+ parse(display, FLAG_ITEM, InsetMath::MATH_MODE);
- cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, type,
- ar1, ar2)));
+ cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, optionals, type,
+ optionalValues, def, display)));
}
else if (t.cs() == "(") {
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())