Tell the math parser that we are parsing a macro definition, so that
it doesn't try to return a verbatim copy in case of failure.
This commit is contained in:
Enrico Forestieri 2017-04-03 00:26:49 +02:00
parent e36c661c61
commit 66aa52ff20
5 changed files with 13 additions and 5 deletions

View File

@ -71,7 +71,7 @@ bool MacroData::expand(vector<MathData> const & args, MathData & to) const
InsetMathSqrt inset(const_cast<Buffer *>(buffer_));
docstring const & definition(display_.empty() ? definition_ : display_);
asArray(definition, inset.cell(0), Parse::QUIET);
asArray(definition, inset.cell(0), Parse::QUIET | Parse::MACRODEF);
//lyxerr << "MathData::expand: args: " << args << endl;
//LYXERR0("MathData::expand: ar: " << inset.cell(0));
for (DocIterator it = doc_iterator_begin(buffer_, &inset); it; it.forwardChar()) {

View File

@ -672,7 +672,7 @@ void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
// get definition for list edit mode
docstring const & display = d->macro_->display();
asArray(display.empty() ? d->macro_->definition() : display,
d->definition_, Parse::QUIET);
d->definition_, Parse::QUIET | Parse::MACRODEF);
}

View File

@ -1757,7 +1757,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
else {
success_ = false;
if (!(mode_ & Parse::QUIET)) {
if (!(mode_ & Parse::QUIET) &&
!(mode_ & Parse::TRACKMACRO)) {
dump();
lyxerr << "found unknown math environment '"
<< to_utf8(name) << "'" << endl;

View File

@ -28,7 +28,9 @@ enum flags {
/// Wrap unicode symbols in \text{}.
USETEXT = 0x08,
/// Track macro creation while loading a document
TRACKMACRO = 0x10
TRACKMACRO = 0x10,
/// Parse a macro definition
MACRODEF = 0x20
};

View File

@ -961,8 +961,13 @@ docstring asString(MathData const & ar)
void asArray(docstring const & str, MathData & ar, Parse::flags pf)
{
// If the QUIET flag is set, we are going to parse for either
// a paste operation or a macro definition. We try to do the
// right thing in all cases.
bool quiet = pf & Parse::QUIET;
if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet))
bool macro = pf & Parse::MACRODEF;
if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet && !macro))
mathed_parse_cell(ar, str, pf | Parse::VERBATIM);
}