Fix unwanted curly braces in formula (bug #8679)

There was an unsymmetry between reading and writing: InsetMathGrid::eolString()
adds curly braces if the first cell of the next line starts with [ to prevent
misparsing as optional argument of \\. These braces were not removed on reading.
This commit is contained in:
Georg Baum 2014-11-20 22:05:05 +01:00
parent 0e0746c703
commit 0385ef0e19

View File

@ -400,6 +400,12 @@ public:
int lineno() const { return lineno_; } int lineno() const { return lineno_; }
/// ///
void putback(); void putback();
/// store current position
void pushPosition();
/// restore previous position
void popPosition();
/// forget last saved position
void dropPosition();
private: private:
/// ///
@ -447,6 +453,8 @@ private:
vector<Token> tokens_; vector<Token> tokens_;
/// ///
unsigned pos_; unsigned pos_;
///
std::vector<unsigned> positions_;
/// Stack of active environments /// Stack of active environments
vector<docstring> environments_; vector<docstring> environments_;
/// ///
@ -528,6 +536,25 @@ void Parser::putback()
} }
void Parser::pushPosition()
{
positions_.push_back(pos_);
}
void Parser::popPosition()
{
pos_ = positions_.back();
positions_.pop_back();
}
void Parser::dropPosition()
{
positions_.pop_back();
}
bool Parser::good() const bool Parser::good() const
{ {
return pos_ < tokens_.size(); return pos_ < tokens_.size();
@ -1311,10 +1338,35 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
if (nextToken().asInput() == "*") { if (nextToken().asInput() == "*") {
getToken(); getToken();
added = addRow(grid, cellrow, docstring(), false); added = addRow(grid, cellrow, docstring(), false);
} else if (good()) } else {
added = addRow(grid, cellrow, getArg('[', ']')); // skip "{}" added in front of "[" (the
else // counterpart is in InsetMathGrid::eolString())
error("missing token after \\\\"); // skip spaces because formula could come from tex2lyx
bool skipBraces = false;
pushPosition();
skipSpaces();
if (nextToken().cat() == catBegin) {
getToken();
skipSpaces();
if (nextToken().cat() == catEnd) {
getToken();
skipSpaces();
if (nextToken().asInput() == "[")
skipBraces = true;
}
}
if (skipBraces)
dropPosition();
else
popPosition();
if (good()) {
docstring arg;
if (!skipBraces)
arg = getArg('[', ']');
added = addRow(grid, cellrow, arg);
} else
error("missing token after \\\\");
}
if (added) { if (added) {
cellcol = 0; cellcol = 0;
if (grid.asHullInset()) if (grid.asHullInset())