mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 11:16:55 +00:00
Fix bug #5530: LyX expansion in math-macro overwritten by default one.
This patch initializes the buffer_ member of a MathHull inset in most (but not all) cases. The problems with buffer_ should be greatly allievated now, but there still can be some corner case. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31873 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b67cd61d3c
commit
a1a34443ef
@ -1440,7 +1440,8 @@ bool Cursor::macroModeClose()
|
|||||||
InsetMathNest * const in = inset().asInsetMath()->asNestInset();
|
InsetMathNest * const in = inset().asInsetMath()->asNestInset();
|
||||||
if (in && in->interpretString(*this, s))
|
if (in && in->interpretString(*this, s))
|
||||||
return true;
|
return true;
|
||||||
MathAtom atom = createInsetMath(name);
|
MathAtom atom = buffer()->getMacro(name, *this, false) ?
|
||||||
|
MathAtom(new MathMacro(name)) : createInsetMath(name);
|
||||||
|
|
||||||
// try to put argument into macro, if we just inserted a macro
|
// try to put argument into macro, if we just inserted a macro
|
||||||
bool macroArg = false;
|
bool macroArg = false;
|
||||||
|
@ -141,7 +141,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
|
|||||||
#ifdef ENABLE_ASSERTIONS
|
#ifdef ENABLE_ASSERTIONS
|
||||||
const int old_pos = cur.pos();
|
const int old_pos = cur.pos();
|
||||||
#endif
|
#endif
|
||||||
cur.insert(new InsetMathHull(hullSimple));
|
cur.insert(new InsetMathHull(hullSimple, cur.buffer()));
|
||||||
#ifdef ENABLE_ASSERTIONS
|
#ifdef ENABLE_ASSERTIONS
|
||||||
LASSERT(old_pos == cur.pos(), /**/);
|
LASSERT(old_pos == cur.pos(), /**/);
|
||||||
#endif
|
#endif
|
||||||
@ -165,7 +165,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
|
|||||||
&& sel.find(from_ascii("\\newlyxcommand")) == string::npos
|
&& sel.find(from_ascii("\\newlyxcommand")) == string::npos
|
||||||
&& sel.find(from_ascii("\\def")) == string::npos)
|
&& sel.find(from_ascii("\\def")) == string::npos)
|
||||||
{
|
{
|
||||||
InsetMathHull * formula = new InsetMathHull;
|
InsetMathHull * formula = new InsetMathHull(cur.buffer());
|
||||||
string const selstr = to_utf8(sel);
|
string const selstr = to_utf8(sel);
|
||||||
istringstream is(selstr);
|
istringstream is(selstr);
|
||||||
Lexer lex;
|
Lexer lex;
|
||||||
@ -184,7 +184,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
|
|||||||
} else
|
} else
|
||||||
cur.insert(formula);
|
cur.insert(formula);
|
||||||
} else {
|
} else {
|
||||||
cur.insert(new MathMacroTemplate(sel));
|
cur.insert(new MathMacroTemplate(sel, cur.buffer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (valid)
|
if (valid)
|
||||||
@ -207,7 +207,7 @@ void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
|
|||||||
// It may happen that sel is empty but there is a selection
|
// It may happen that sel is empty but there is a selection
|
||||||
replaceSelection(cur);
|
replaceSelection(cur);
|
||||||
|
|
||||||
cur.insert(new InsetMathHull(hullRegexp));
|
cur.insert(new InsetMathHull(hullRegexp, cur.buffer()));
|
||||||
cur.nextInset()->edit(cur, true);
|
cur.nextInset()->edit(cur, true);
|
||||||
cur.niceInsert(sel);
|
cur.niceInsert(sel);
|
||||||
|
|
||||||
@ -1753,7 +1753,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
MacroType type = MacroTypeNewcommand;
|
MacroType type = MacroTypeNewcommand;
|
||||||
if (s2 == "def")
|
if (s2 == "def")
|
||||||
type = MacroTypeDef;
|
type = MacroTypeDef;
|
||||||
MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type);
|
MathMacroTemplate * inset = new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, false, type, cur.buffer());
|
||||||
inset->setBuffer(bv->buffer());
|
inset->setBuffer(bv->buffer());
|
||||||
insertInset(cur, inset);
|
insertInset(cur, inset);
|
||||||
|
|
||||||
@ -1781,7 +1781,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
case LFUN_MATH_BIGDELIM: {
|
case LFUN_MATH_BIGDELIM: {
|
||||||
cur.recordUndo();
|
cur.recordUndo();
|
||||||
cap::replaceSelection(cur);
|
cap::replaceSelection(cur);
|
||||||
cur.insert(new InsetMathHull(hullSimple));
|
cur.insert(new InsetMathHull(hullSimple, cur.buffer()));
|
||||||
checkAndActivateInset(cur, true);
|
checkAndActivateInset(cur, true);
|
||||||
LASSERT(cur.inMathed(), /**/);
|
LASSERT(cur.inMathed(), /**/);
|
||||||
cur.dispatch(cmd);
|
cur.dispatch(cmd);
|
||||||
|
@ -531,9 +531,9 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
|||||||
} else if (tmptok == "External") {
|
} else if (tmptok == "External") {
|
||||||
inset.reset(new InsetExternal(const_cast<Buffer &>(buf)));
|
inset.reset(new InsetExternal(const_cast<Buffer &>(buf)));
|
||||||
} else if (tmptok == "FormulaMacro") {
|
} else if (tmptok == "FormulaMacro") {
|
||||||
inset.reset(new MathMacroTemplate);
|
inset.reset(new MathMacroTemplate(&const_cast<Buffer &>(buf)));
|
||||||
} else if (tmptok == "Formula") {
|
} else if (tmptok == "Formula") {
|
||||||
inset.reset(new InsetMathHull);
|
inset.reset(new InsetMathHull(&const_cast<Buffer &>(buf)));
|
||||||
} else if (tmptok == "Graphics") {
|
} else if (tmptok == "Graphics") {
|
||||||
inset.reset(new InsetGraphics(const_cast<Buffer &>(buf)));
|
inset.reset(new InsetGraphics(const_cast<Buffer &>(buf)));
|
||||||
} else if (tmptok == "Note") {
|
} else if (tmptok == "Note") {
|
||||||
|
@ -59,7 +59,9 @@ InsetMathArray::InsetMathArray(docstring const & name, docstring const & str)
|
|||||||
addCol(0);
|
addCol(0);
|
||||||
for (row_type row = 0; row < dat.size(); ++row)
|
for (row_type row = 0; row < dat.size(); ++row)
|
||||||
for (col_type col = 0; col < dat[0].size(); ++col)
|
for (col_type col = 0; col < dat[0].size(); ++col)
|
||||||
mathed_parse_cell(cell(index(row, col)), from_utf8(dat[row][col]));
|
mathed_parse_cell(cell(index(row, col)),
|
||||||
|
from_utf8(dat[row][col]),
|
||||||
|
Parse::NORMAL, &buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1276,10 +1276,12 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
InsetMathGrid grid(1, 1);
|
InsetMathGrid grid(1, 1);
|
||||||
if (!topaste.empty())
|
if (!topaste.empty())
|
||||||
if ((topaste.size() == 1 && topaste.at(0) < 0x80)
|
if ((topaste.size() == 1 && topaste.at(0) < 0x80)
|
||||||
|| !mathed_parse_normal(grid, topaste, parseflg)) {
|
|| !mathed_parse_normal(grid, topaste, parseflg,
|
||||||
|
cur.buffer())) {
|
||||||
resetGrid(grid);
|
resetGrid(grid);
|
||||||
mathed_parse_normal(grid, topaste,
|
mathed_parse_normal(grid, topaste,
|
||||||
parseflg | Parse::VERBATIM);
|
parseflg | Parse::VERBATIM,
|
||||||
|
cur.buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grid.nargs() == 1) {
|
if (grid.nargs() == 1) {
|
||||||
|
@ -149,7 +149,7 @@ docstring hullName(HullType type)
|
|||||||
|
|
||||||
static InsetLabel * dummy_pointer = 0;
|
static InsetLabel * dummy_pointer = 0;
|
||||||
|
|
||||||
InsetMathHull::InsetMathHull()
|
InsetMathHull::InsetMathHull(Buffer * buf)
|
||||||
: InsetMathGrid(1, 1), type_(hullNone), nonum_(1, false),
|
: InsetMathGrid(1, 1), type_(hullNone), nonum_(1, false),
|
||||||
label_(1, dummy_pointer), preview_(new RenderPreview(this))
|
label_(1, dummy_pointer), preview_(new RenderPreview(this))
|
||||||
{
|
{
|
||||||
@ -157,15 +157,17 @@ InsetMathHull::InsetMathHull()
|
|||||||
//lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
|
//lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
|
||||||
//lyxerr << "sizeof InsetMathChar: " << sizeof(InsetMathChar) << endl;
|
//lyxerr << "sizeof InsetMathChar: " << sizeof(InsetMathChar) << endl;
|
||||||
//lyxerr << "sizeof FontInfo: " << sizeof(FontInfo) << endl;
|
//lyxerr << "sizeof FontInfo: " << sizeof(FontInfo) << endl;
|
||||||
|
buffer_ = buf;
|
||||||
initMath();
|
initMath();
|
||||||
setDefaults();
|
setDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InsetMathHull::InsetMathHull(HullType type)
|
InsetMathHull::InsetMathHull(HullType type, Buffer * buf)
|
||||||
: InsetMathGrid(getCols(type), 1), type_(type), nonum_(1, false),
|
: InsetMathGrid(getCols(type), 1), type_(type), nonum_(1, false),
|
||||||
label_(1, dummy_pointer), preview_(new RenderPreview(this))
|
label_(1, dummy_pointer), preview_(new RenderPreview(this))
|
||||||
{
|
{
|
||||||
|
buffer_ = buf;
|
||||||
initMath();
|
initMath();
|
||||||
setDefaults();
|
setDefaults();
|
||||||
}
|
}
|
||||||
@ -197,6 +199,7 @@ InsetMathHull & InsetMathHull::operator=(InsetMathHull const & other)
|
|||||||
InsetMathGrid::operator=(other);
|
InsetMathGrid::operator=(other);
|
||||||
type_ = other.type_;
|
type_ = other.type_;
|
||||||
nonum_ = other.nonum_;
|
nonum_ = other.nonum_;
|
||||||
|
buffer_ = other.buffer_;
|
||||||
for (size_t i = 0; i < label_.size(); ++i)
|
for (size_t i = 0; i < label_.size(); ++i)
|
||||||
delete label_[i];
|
delete label_[i];
|
||||||
label_ = other.label_;
|
label_ = other.label_;
|
||||||
@ -811,7 +814,7 @@ void InsetMathHull::glueall()
|
|||||||
MathData ar;
|
MathData ar;
|
||||||
for (idx_type i = 0; i < nargs(); ++i)
|
for (idx_type i = 0; i < nargs(); ++i)
|
||||||
ar.append(cell(i));
|
ar.append(cell(i));
|
||||||
*this = InsetMathHull(hullSimple);
|
*this = InsetMathHull(hullSimple, &buffer());
|
||||||
cell(0) = ar;
|
cell(0) = ar;
|
||||||
setDefaults();
|
setDefaults();
|
||||||
}
|
}
|
||||||
@ -1610,7 +1613,7 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
|
|||||||
laststr = str;
|
laststr = str;
|
||||||
current = ibegin(nucleus());
|
current = ibegin(nucleus());
|
||||||
ar.clear();
|
ar.clear();
|
||||||
mathed_parse_cell(ar, str);
|
mathed_parse_cell(ar, str, Parse::NORMAL, &buffer());
|
||||||
} else {
|
} else {
|
||||||
increment(current);
|
increment(current);
|
||||||
}
|
}
|
||||||
@ -1648,7 +1651,7 @@ void InsetMathHull::write(ostream & os) const
|
|||||||
void InsetMathHull::read(Lexer & lex)
|
void InsetMathHull::read(Lexer & lex)
|
||||||
{
|
{
|
||||||
MathAtom at;
|
MathAtom at;
|
||||||
mathed_parse_normal(at, lex);
|
mathed_parse_normal(at, lex, Parse::NORMAL, &buffer());
|
||||||
operator=(*at->asHullInset());
|
operator=(*at->asHullInset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1656,9 +1659,10 @@ void InsetMathHull::read(Lexer & lex)
|
|||||||
bool InsetMathHull::readQuiet(Lexer & lex)
|
bool InsetMathHull::readQuiet(Lexer & lex)
|
||||||
{
|
{
|
||||||
MathAtom at;
|
MathAtom at;
|
||||||
bool result = mathed_parse_normal(at, lex, Parse::QUIET);
|
bool success = mathed_parse_normal(at, lex, Parse::QUIET, &buffer());
|
||||||
operator=(*at->asHullInset());
|
if (success)
|
||||||
return result;
|
operator=(*at->asHullInset());
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ class RenderPreview;
|
|||||||
class InsetMathHull : public InsetMathGrid {
|
class InsetMathHull : public InsetMathGrid {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
InsetMathHull();
|
InsetMathHull(Buffer * buf = 0);
|
||||||
///
|
///
|
||||||
explicit InsetMathHull(HullType type);
|
explicit InsetMathHull(HullType type, Buffer * buf = 0);
|
||||||
///
|
///
|
||||||
~InsetMathHull();
|
~InsetMathHull();
|
||||||
///
|
///
|
||||||
|
@ -977,7 +977,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
#else
|
#else
|
||||||
if (currentMode() == Inset::TEXT_MODE) {
|
if (currentMode() == Inset::TEXT_MODE) {
|
||||||
cur.recordUndoSelection();
|
cur.recordUndoSelection();
|
||||||
cur.niceInsert(MathAtom(new InsetMathHull("simple")));
|
cur.niceInsert(MathAtom(new InsetMathHull("simple", cur.buffer())));
|
||||||
cur.message(_("create new math text environment ($...$)"));
|
cur.message(_("create new math text environment ($...$)"));
|
||||||
} else {
|
} else {
|
||||||
handleFont(cur, cmd.argument(), "textrm");
|
handleFont(cur, cmd.argument(), "textrm");
|
||||||
@ -996,7 +996,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
cur.macroModeClose();
|
cur.macroModeClose();
|
||||||
docstring const save_selection = grabAndEraseSelection(cur);
|
docstring const save_selection = grabAndEraseSelection(cur);
|
||||||
selClearOrDel(cur);
|
selClearOrDel(cur);
|
||||||
cur.plainInsert(MathAtom(new InsetMathHull(hullRegexp)));
|
cur.plainInsert(MathAtom(new InsetMathHull(hullRegexp, cur.buffer())));
|
||||||
cur.posBackward();
|
cur.posBackward();
|
||||||
cur.pushBackward(*cur.nextInset());
|
cur.pushBackward(*cur.nextInset());
|
||||||
cur.niceInsert(save_selection);
|
cur.niceInsert(save_selection);
|
||||||
|
@ -390,22 +390,24 @@ void InsetNameWrapper::draw(PainterInfo & pi, int x, int y) const
|
|||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
MathMacroTemplate::MathMacroTemplate()
|
MathMacroTemplate::MathMacroTemplate(Buffer * buf)
|
||||||
: InsetMathNest(3), numargs_(0), argsInLook_(0), optionals_(0),
|
: InsetMathNest(3), numargs_(0), argsInLook_(0), optionals_(0),
|
||||||
type_(MacroTypeNewcommand), lookOutdated_(true)
|
type_(MacroTypeNewcommand), lookOutdated_(true)
|
||||||
{
|
{
|
||||||
|
buffer_ = buf;
|
||||||
initMath();
|
initMath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs,
|
MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs,
|
||||||
int optionals, MacroType type,
|
int optionals, MacroType type, Buffer * buf,
|
||||||
vector<MathData> const & optionalValues,
|
vector<MathData> const & optionalValues,
|
||||||
MathData const & def, MathData const & display)
|
MathData const & def, MathData const & display)
|
||||||
: InsetMathNest(optionals + 3), numargs_(numargs), argsInLook_(numargs),
|
: InsetMathNest(optionals + 3), numargs_(numargs), argsInLook_(numargs),
|
||||||
optionals_(optionals), optionalValues_(optionalValues),
|
optionals_(optionals), optionalValues_(optionalValues),
|
||||||
type_(type), lookOutdated_(true)
|
type_(type), lookOutdated_(true)
|
||||||
{
|
{
|
||||||
|
buffer_ = buf;
|
||||||
initMath();
|
initMath();
|
||||||
|
|
||||||
if (numargs_ > 9)
|
if (numargs_ > 9)
|
||||||
@ -423,14 +425,15 @@ MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MathMacroTemplate::MathMacroTemplate(docstring const & str)
|
MathMacroTemplate::MathMacroTemplate(docstring const & str, Buffer * buf)
|
||||||
: InsetMathNest(3), numargs_(0), optionals_(0),
|
: InsetMathNest(3), numargs_(0), optionals_(0),
|
||||||
type_(MacroTypeNewcommand), lookOutdated_(true)
|
type_(MacroTypeNewcommand), lookOutdated_(true)
|
||||||
{
|
{
|
||||||
|
buffer_ = buf;
|
||||||
initMath();
|
initMath();
|
||||||
|
|
||||||
MathData ar;
|
MathData ar;
|
||||||
mathed_parse_cell(ar, str);
|
mathed_parse_cell(ar, str, Parse::NORMAL, buf);
|
||||||
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
|
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
|
||||||
lyxerr << "Cannot read macro from '" << ar << "'" << endl;
|
lyxerr << "Cannot read macro from '" << ar << "'" << endl;
|
||||||
asArray(from_ascii("invalidmacro"), cell(0));
|
asArray(from_ascii("invalidmacro"), cell(0));
|
||||||
@ -1106,7 +1109,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
|
|||||||
void MathMacroTemplate::read(Lexer & lex)
|
void MathMacroTemplate::read(Lexer & lex)
|
||||||
{
|
{
|
||||||
MathData ar;
|
MathData ar;
|
||||||
mathed_parse_cell(ar, lex.getStream());
|
mathed_parse_cell(ar, lex.getStream(), Parse::NORMAL, &buffer());
|
||||||
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
|
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
|
||||||
lyxerr << "Cannot read macro from '" << ar << "'" << endl;
|
lyxerr << "Cannot read macro from '" << ar << "'" << endl;
|
||||||
lyxerr << "Read: " << to_utf8(asString(ar)) << endl;
|
lyxerr << "Read: " << to_utf8(asString(ar)) << endl;
|
||||||
|
@ -26,15 +26,15 @@ namespace lyx {
|
|||||||
class MathMacroTemplate : public InsetMathNest {
|
class MathMacroTemplate : public InsetMathNest {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
MathMacroTemplate();
|
MathMacroTemplate(Buffer * buf = 0);
|
||||||
///
|
///
|
||||||
MathMacroTemplate(docstring const & name, int nargs, int optional,
|
MathMacroTemplate(docstring const & name, int nargs, int optional,
|
||||||
MacroType type,
|
MacroType type, Buffer * buf = 0,
|
||||||
std::vector<MathData> const & optionalValues = std::vector<MathData>(),
|
std::vector<MathData> const & optionalValues = std::vector<MathData>(),
|
||||||
MathData const & def = MathData(),
|
MathData const & def = MathData(),
|
||||||
MathData const & display = MathData());
|
MathData const & display = MathData());
|
||||||
///
|
///
|
||||||
explicit MathMacroTemplate(const docstring & str);
|
explicit MathMacroTemplate(const docstring & str, Buffer * buf = 0);
|
||||||
///
|
///
|
||||||
bool editable() const { return true; }
|
bool editable() const { return true; }
|
||||||
///
|
///
|
||||||
|
@ -64,6 +64,7 @@ following hack as starting point to write some macros:
|
|||||||
#include "MathMacroArgument.h"
|
#include "MathMacroArgument.h"
|
||||||
#include "MathSupport.h"
|
#include "MathSupport.h"
|
||||||
|
|
||||||
|
#include "Buffer.h"
|
||||||
#include "Encoding.h"
|
#include "Encoding.h"
|
||||||
#include "Lexer.h"
|
#include "Lexer.h"
|
||||||
|
|
||||||
@ -359,12 +360,12 @@ public:
|
|||||||
typedef Parse::flags parse_mode;
|
typedef Parse::flags parse_mode;
|
||||||
|
|
||||||
///
|
///
|
||||||
Parser(Lexer & lex, parse_mode mode);
|
Parser(Lexer & lex, parse_mode mode, Buffer * buf);
|
||||||
/// Only use this for reading from .lyx file format, for the reason
|
/// Only use this for reading from .lyx file format, for the reason
|
||||||
/// see Parser::tokenize(istream &).
|
/// see Parser::tokenize(istream &).
|
||||||
Parser(istream & is, parse_mode mode);
|
Parser(istream & is, parse_mode mode, Buffer * buf);
|
||||||
///
|
///
|
||||||
Parser(docstring const & str, parse_mode mode);
|
Parser(docstring const & str, parse_mode mode, Buffer * buf);
|
||||||
|
|
||||||
///
|
///
|
||||||
bool parse(MathAtom & at);
|
bool parse(MathAtom & at);
|
||||||
@ -432,27 +433,36 @@ private:
|
|||||||
parse_mode mode_;
|
parse_mode mode_;
|
||||||
///
|
///
|
||||||
bool success_;
|
bool success_;
|
||||||
|
///
|
||||||
|
Buffer * buffer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Parser::Parser(Lexer & lexer, parse_mode mode)
|
Parser::Parser(Lexer & lexer, parse_mode mode, Buffer * buf)
|
||||||
: lineno_(lexer.lineNumber()), pos_(0), mode_(mode), success_(true)
|
: lineno_(lexer.lineNumber()), pos_(0), mode_(mode), success_(true),
|
||||||
|
buffer_(buf)
|
||||||
{
|
{
|
||||||
|
if (buf)
|
||||||
|
buf->updateMacros();
|
||||||
tokenize(lexer.getStream());
|
tokenize(lexer.getStream());
|
||||||
lexer.eatLine();
|
lexer.eatLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Parser::Parser(istream & is, parse_mode mode)
|
Parser::Parser(istream & is, parse_mode mode, Buffer * buf)
|
||||||
: lineno_(0), pos_(0), mode_(mode), success_(true)
|
: lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf)
|
||||||
{
|
{
|
||||||
|
if (buf)
|
||||||
|
buf->updateMacros();
|
||||||
tokenize(is);
|
tokenize(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Parser::Parser(docstring const & str, parse_mode mode)
|
Parser::Parser(docstring const & str, parse_mode mode, Buffer * buf)
|
||||||
: lineno_(0), pos_(0), mode_(mode), success_(true)
|
: lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf)
|
||||||
{
|
{
|
||||||
|
if (buf)
|
||||||
|
buf->updateMacros();
|
||||||
tokenize(str);
|
tokenize(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -825,14 +835,14 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
Token const & n = getToken();
|
Token const & n = getToken();
|
||||||
if (n.cat() == catMath) {
|
if (n.cat() == catMath) {
|
||||||
// TeX's $$...$$ syntax for displayed math
|
// TeX's $$...$$ syntax for displayed math
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
cell->push_back(MathAtom(new InsetMathHull(hullEquation, buffer_)));
|
||||||
parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
|
parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
|
||||||
getToken(); // skip the second '$' token
|
getToken(); // skip the second '$' token
|
||||||
} else {
|
} else {
|
||||||
// simple $...$ stuff
|
// simple $...$ stuff
|
||||||
putback();
|
putback();
|
||||||
if (mode == InsetMath::UNDECIDED_MODE) {
|
if (mode == InsetMath::UNDECIDED_MODE) {
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
cell->push_back(MathAtom(new InsetMathHull(hullSimple, buffer_)));
|
||||||
parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
|
parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
|
||||||
} else {
|
} else {
|
||||||
// Don't create nested math hulls (bug #5392)
|
// Don't create nested math hulls (bug #5392)
|
||||||
@ -1007,8 +1017,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
if (nextToken().cat() == catBegin)
|
if (nextToken().cat() == catBegin)
|
||||||
parse(display, FLAG_ITEM, InsetMath::MATH_MODE);
|
parse(display, FLAG_ITEM, InsetMath::MATH_MODE);
|
||||||
|
|
||||||
cell->push_back(MathAtom(new MathMacroTemplate(name, nargs,
|
cell->push_back(MathAtom(new MathMacroTemplate(name,
|
||||||
0, MacroTypeDef, vector<MathData>(), def, display)));
|
nargs, 0, MacroTypeDef, buffer_,
|
||||||
|
vector<MathData>(), def, display)));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs() == "newcommand" ||
|
else if (t.cs() == "newcommand" ||
|
||||||
@ -1051,9 +1062,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
if (nextToken().cat() == catBegin)
|
if (nextToken().cat() == catBegin)
|
||||||
parse(display, FLAG_ITEM, InsetMath::MATH_MODE);
|
parse(display, FLAG_ITEM, InsetMath::MATH_MODE);
|
||||||
|
|
||||||
cell->push_back(MathAtom(new MathMacroTemplate(name, nargs,
|
cell->push_back(MathAtom(new MathMacroTemplate(name,
|
||||||
optionals, MacroTypeNewcommand, optionalValues, def, display)));
|
nargs, optionals, MacroTypeNewcommand, buffer_,
|
||||||
|
optionalValues, def, display)));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs() == "newcommandx" ||
|
else if (t.cs() == "newcommandx" ||
|
||||||
@ -1169,9 +1180,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
if (nextToken().cat() == catBegin)
|
if (nextToken().cat() == catBegin)
|
||||||
parse(display, FLAG_ITEM, InsetMath::MATH_MODE);
|
parse(display, FLAG_ITEM, InsetMath::MATH_MODE);
|
||||||
|
|
||||||
cell->push_back(MathAtom(new MathMacroTemplate(name, nargs,
|
cell->push_back(MathAtom(new MathMacroTemplate(name,
|
||||||
optionals, MacroTypeNewcommandx, optionalValues, def,
|
nargs, optionals, MacroTypeNewcommandx, buffer_,
|
||||||
display)));
|
optionalValues, def, display)));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs() == "(") {
|
else if (t.cs() == "(") {
|
||||||
@ -1179,7 +1190,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
cell->push_back(MathAtom(new InsetMathHull(hullSimple, buffer_)));
|
||||||
parse2(cell->back(), FLAG_SIMPLE2, InsetMath::MATH_MODE, false);
|
parse2(cell->back(), FLAG_SIMPLE2, InsetMath::MATH_MODE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1188,7 +1199,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
cell->push_back(MathAtom(new InsetMathHull(hullEquation, buffer_)));
|
||||||
parse2(cell->back(), FLAG_EQUATION, InsetMath::MATH_MODE, false);
|
parse2(cell->back(), FLAG_EQUATION, InsetMath::MATH_MODE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1446,7 +1457,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
cell->push_back(MathAtom(new InsetMathHull(hullSimple, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, true);
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1456,7 +1467,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
cell->push_back(MathAtom(new InsetMathHull(hullEquation, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, (name == "equation"));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, (name == "equation"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1465,7 +1476,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullEqnArray)));
|
cell->push_back(MathAtom(new InsetMathHull(hullEqnArray, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1474,7 +1485,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullAlign)));
|
cell->push_back(MathAtom(new InsetMathHull(hullAlign, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1483,7 +1494,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullFlAlign)));
|
cell->push_back(MathAtom(new InsetMathHull(hullFlAlign, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1494,7 +1505,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
// ignore this for a while
|
// ignore this for a while
|
||||||
getArg('{', '}');
|
getArg('{', '}');
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullAlignAt)));
|
cell->push_back(MathAtom(new InsetMathHull(hullAlignAt, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1505,7 +1516,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
// ignore this for a while
|
// ignore this for a while
|
||||||
getArg('{', '}');
|
getArg('{', '}');
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullXAlignAt)));
|
cell->push_back(MathAtom(new InsetMathHull(hullXAlignAt, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1516,7 +1527,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
// ignore this for a while
|
// ignore this for a while
|
||||||
getArg('{', '}');
|
getArg('{', '}');
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullXXAlignAt)));
|
cell->push_back(MathAtom(new InsetMathHull(hullXXAlignAt, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1525,7 +1536,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullMultline)));
|
cell->push_back(MathAtom(new InsetMathHull(hullMultline, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1534,7 +1545,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
error("bad math environment");
|
error("bad math environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cell->push_back(MathAtom(new InsetMathHull(hullGather)));
|
cell->push_back(MathAtom(new InsetMathHull(hullGather, buffer_)));
|
||||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1681,7 +1692,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
// we must not create an InsetMathSpace.
|
// we must not create an InsetMathSpace.
|
||||||
cell->push_back(MathAtom(new MathMacro(name)));
|
cell->push_back(MathAtom(new MathMacro(name)));
|
||||||
MathData ar;
|
MathData ar;
|
||||||
mathed_parse_cell(ar, '{' + arg + '}');
|
mathed_parse_cell(ar, '{' + arg + '}',
|
||||||
|
Parse::NORMAL, buffer_);
|
||||||
cell->append(ar);
|
cell->append(ar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1749,8 +1761,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs().size()) {
|
else if (t.cs().size()) {
|
||||||
|
bool const is_user_macro =
|
||||||
|
buffer_ && buffer_->getMacro(t.cs(), false);
|
||||||
latexkeys const * l = in_word_set(t.cs());
|
latexkeys const * l = in_word_set(t.cs());
|
||||||
if (l) {
|
if (l && !is_user_macro) {
|
||||||
if (l->inset == "big") {
|
if (l->inset == "big") {
|
||||||
skipSpaces();
|
skipSpaces();
|
||||||
docstring const delim = getToken().asInput();
|
docstring const delim = getToken().asInput();
|
||||||
@ -1800,7 +1814,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
bool is_unicode_symbol = false;
|
bool is_unicode_symbol = false;
|
||||||
if (mode == InsetMath::TEXT_MODE) {
|
if (mode == InsetMath::TEXT_MODE && !is_user_macro) {
|
||||||
int num_tokens = 0;
|
int num_tokens = 0;
|
||||||
docstring cmd = prevToken().asInput();
|
docstring cmd = prevToken().asInput();
|
||||||
CatCode cat = nextToken().cat();
|
CatCode cat = nextToken().cat();
|
||||||
@ -1837,7 +1851,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!is_unicode_symbol) {
|
if (!is_unicode_symbol) {
|
||||||
MathAtom at = createInsetMath(t.cs());
|
MathAtom at = is_user_macro ?
|
||||||
|
MathAtom(new MathMacro(t.cs()))
|
||||||
|
: createInsetMath(t.cs());
|
||||||
InsetMath::mode_type m = mode;
|
InsetMath::mode_type m = mode;
|
||||||
//if (m == InsetMath::UNDECIDED_MODE)
|
//if (m == InsetMath::UNDECIDED_MODE)
|
||||||
//lyxerr << "default creation: m1: " << m << endl;
|
//lyxerr << "default creation: m1: " << m << endl;
|
||||||
@ -1875,35 +1891,40 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
bool mathed_parse_cell(MathData & ar, docstring const & str, Parse::flags f)
|
bool mathed_parse_cell(MathData & ar, docstring const & str,
|
||||||
|
Parse::flags f, Buffer * buf)
|
||||||
{
|
{
|
||||||
return Parser(str, f).parse(ar, 0, f & Parse::TEXTMODE ?
|
return Parser(str, f, buf).parse(ar, 0, f & Parse::TEXTMODE ?
|
||||||
InsetMath::TEXT_MODE : InsetMath::MATH_MODE);
|
InsetMath::TEXT_MODE : InsetMath::MATH_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool mathed_parse_cell(MathData & ar, istream & is, Parse::flags f)
|
bool mathed_parse_cell(MathData & ar, istream & is,
|
||||||
|
Parse::flags f, Buffer * buf)
|
||||||
{
|
{
|
||||||
return Parser(is, f).parse(ar, 0, f & Parse::TEXTMODE ?
|
return Parser(is, f, buf).parse(ar, 0, f & Parse::TEXTMODE ?
|
||||||
InsetMath::TEXT_MODE : InsetMath::MATH_MODE);
|
InsetMath::TEXT_MODE : InsetMath::MATH_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool mathed_parse_normal(MathAtom & t, docstring const & str, Parse::flags f)
|
bool mathed_parse_normal(MathAtom & t, docstring const & str,
|
||||||
|
Parse::flags f, Buffer * buf)
|
||||||
{
|
{
|
||||||
return Parser(str, f).parse(t);
|
return Parser(str, f, buf).parse(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool mathed_parse_normal(MathAtom & t, Lexer & lex, Parse::flags f)
|
bool mathed_parse_normal(MathAtom & t, Lexer & lex,
|
||||||
|
Parse::flags f, Buffer * buf)
|
||||||
{
|
{
|
||||||
return Parser(lex, f).parse(t);
|
return Parser(lex, f, buf).parse(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool mathed_parse_normal(InsetMathGrid & grid, docstring const & str, Parse::flags f)
|
bool mathed_parse_normal(InsetMathGrid & grid, docstring const & str,
|
||||||
|
Parse::flags f, Buffer * buf)
|
||||||
{
|
{
|
||||||
return Parser(str, f).parse1(grid, 0, f & Parse::TEXTMODE ?
|
return Parser(str, f, buf).parse1(grid, 0, f & Parse::TEXTMODE ?
|
||||||
InsetMath::TEXT_MODE : InsetMath::MATH_MODE, false);
|
InsetMath::TEXT_MODE : InsetMath::MATH_MODE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
|
class Buffer;
|
||||||
class MathAtom;
|
class MathAtom;
|
||||||
class MathData;
|
class MathData;
|
||||||
class InsetMathGrid;
|
class InsetMathGrid;
|
||||||
@ -61,17 +62,25 @@ public:
|
|||||||
latexkeys const * in_word_set(docstring const & str);
|
latexkeys const * in_word_set(docstring const & str);
|
||||||
|
|
||||||
/// parse formula from a string
|
/// parse formula from a string
|
||||||
bool mathed_parse_normal(MathAtom &, docstring const &, Parse::flags f = Parse::NORMAL);
|
bool mathed_parse_normal(MathAtom &, docstring const &,
|
||||||
/// ... the LyX lexxer
|
Parse::flags f = Parse::NORMAL, Buffer * buf = 0);
|
||||||
bool mathed_parse_normal(MathAtom &, Lexer &, Parse::flags f = Parse::NORMAL);
|
|
||||||
|
/// parse formula from the LyX lexxer
|
||||||
|
bool mathed_parse_normal(MathAtom &, Lexer &,
|
||||||
|
Parse::flags f = Parse::NORMAL, Buffer * buf = 0);
|
||||||
|
|
||||||
/// parse formula from a string into a grid
|
/// parse formula from a string into a grid
|
||||||
bool mathed_parse_normal(InsetMathGrid &, docstring const &, Parse::flags f = Parse::NORMAL);
|
bool mathed_parse_normal(InsetMathGrid &, docstring const &,
|
||||||
|
Parse::flags f = Parse::NORMAL, Buffer * buf = 0);
|
||||||
|
|
||||||
/// parse a single cell from a string
|
/// parse a single cell from a string
|
||||||
bool mathed_parse_cell(MathData & ar, docstring const &, Parse::flags f = Parse::NORMAL);
|
bool mathed_parse_cell(MathData & ar, docstring const &,
|
||||||
|
Parse::flags f = Parse::NORMAL, Buffer * buf = 0);
|
||||||
|
|
||||||
/// parse a single cell from a stream. Only use this for reading from .lyx
|
/// parse a single cell from a stream. Only use this for reading from .lyx
|
||||||
/// file format, for the reason see Parser::tokenize(std::istream &).
|
/// file format, for the reason see Parser::tokenize(std::istream &).
|
||||||
bool mathed_parse_cell(MathData & ar, std::istream &, Parse::flags f = Parse::NORMAL);
|
bool mathed_parse_cell(MathData & ar, std::istream &,
|
||||||
|
Parse::flags f = Parse::NORMAL, Buffer * buf = 0);
|
||||||
|
|
||||||
void initParser();
|
void initParser();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user