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.

Thanks to Enrico, who noticed that the previous fix did not take into account
the case of nonempty length argument + the next line beginning with [.
Now the parsing is exactly the inverse of InsetMathGrid::eolString().
This commit is contained in:
Georg Baum 2015-02-12 21:36:01 +01:00
parent 15d1349847
commit edc1ce4068
2 changed files with 57 additions and 5 deletions

View File

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

View File

@ -73,6 +73,9 @@ What's new
- Work around limitations of external image viewers on windows (bug 8892).
- Do not display unwanted curly brackets in multi-line formulas (happened if
the first character in a row was a '[') (bug 8679).
* INTERNALS