macro handling cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4620 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-07-12 14:24:47 +00:00
parent 80357480fe
commit 22b1e8d33a
12 changed files with 197 additions and 306 deletions

View File

@ -41,7 +41,6 @@
#include "math_arrayinset.h"
#include "math_charinset.h"
#include "math_cursor.h"
#include "math_factory.h"
#include "math_fontinset.h"
#include "math_hullinset.h"
#include "math_iterator.h"
@ -91,11 +90,11 @@ InsetFormulaBase::InsetFormulaBase()
: view_(0), font_(), xo_(0), yo_(0)
{
// This is needed as long the math parser is not re-entrant
MathMacroTable::builtinMacros();
initMath();
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
//lyxerr << "sizeof(MathMetricsInfo): " << sizeof(MathMetricsInfo) << "\n";
//lyxerr << "sizeof(MathCharInset): " << sizeof(MathCharInset) << "\n";
//lyxerr << "sizeof(LyXFont): " << sizeof(LyXFont) << "\n";
//lyxerr << "sizeof MathMetricsInfo: " << sizeof(MathMetricsInfo) << "\n";
//lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << "\n";
//lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << "\n";
}
@ -958,20 +957,14 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
} else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary
// formula otherwise
InsetFormulaBase * f;
if (sel.find("\\newcommand") == string::npos &&
sel.find("\\def") == string::npos)
{
InsetFormula * f = new InsetFormula(sel);
bv->getLyXText()->cutSelection(bv);
openNewInset(bv, f);
} else {
string name;
if (!mathed_parse_macro(name, sel))
return;
InsetFormulaMacro * f = new InsetFormulaMacro(sel);
bv->getLyXText()->cutSelection(bv);
openNewInset(bv, f);
}
f = new InsetFormula(sel);
else
f = new InsetFormulaMacro(sel);
bv->getLyXText()->cutSelection(bv);
openNewInset(bv, f);
}
bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
}

View File

@ -23,6 +23,7 @@
#include "math_parser.h"
#include "math_macro.h"
#include "math_macrotable.h"
#include "math_macrotemplate.h"
#include "math_support.h"
#include "math_mathmlstream.h"
#include "BufferView.h"
@ -36,10 +37,13 @@
#include "lyxtext.h"
#include "lyxfont.h"
#include <sstream>
using std::ostream;
extern MathCursor * mathcursor;
InsetFormulaMacro::InsetFormulaMacro()
{
// inset name is inherited from Inset
@ -50,15 +54,14 @@ InsetFormulaMacro::InsetFormulaMacro()
InsetFormulaMacro::InsetFormulaMacro(string const & name, int nargs)
{
setInsetName(name);
MathMacroTable::create(name, nargs);
MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs)));
}
InsetFormulaMacro::InsetFormulaMacro(string const & s)
{
string name;
mathed_parse_macro(name, s);
setInsetName(name);
std::istringstream is(s);
read(is);
}
@ -107,10 +110,15 @@ int InsetFormulaMacro::docbook(Buffer const * buf, ostream & os, bool) const
void InsetFormulaMacro::read(Buffer const *, LyXLex & lex)
{
string name;
mathed_parse_macro(name, lex);
setInsetName(name);
//lyxerr << "metrics disabled";
read(lex.getStream());
}
void InsetFormulaMacro::read(std::istream & is)
{
MathMacroTemplate * p = new MathMacroTemplate(is);
MathMacroTable::create(MathAtom(p));
setInsetName(p->name());
metrics();
}

View File

@ -25,11 +25,11 @@
class MathMacroTemplate;
// InsetFormulaMacro's only knows its name and asks the global
// An InsetFormulaMacro only knows its name and asks the global
// MathMacroTable if it needs to know more.
///
class InsetFormulaMacro: public InsetFormulaBase {
class InsetFormulaMacro : public InsetFormulaBase {
public:
///
InsetFormulaMacro();
@ -68,6 +68,8 @@ public:
///
MathAtom & par();
private:
///
void read(std::istream & is);
/// prefix in inset
string prefix() const;
};

View File

@ -16,9 +16,9 @@ public:
///
void addDer(MathArray const & der);
///
void metrics(MathMetricsInfo & st) const;
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo &, int x, int y) const;
void draw(MathPainterInfo & pi, int x, int y) const;
///
void normalize(NormalStream &) const;

View File

@ -15,6 +15,7 @@
#include "math_lefteqninset.h"
#include "math_macro.h"
#include "math_macrotable.h"
#include "math_macrotemplate.h"
#include "math_macroarg.h"
#include "math_parboxinset.h"
#include "math_rootinset.h"
@ -82,14 +83,22 @@ void initSymbols()
}
std::ifstream fs(filename.c_str());
while (fs) {
string line;
while (getline(fs, line)) {
int charid = 0;
int fallbackid = 0;
latexkeys tmp;
string line;
getline(fs, line);
if (line.size() > 1 && line[0] == '#')
if (line.size() > 0 && line[0] == '#')
continue;
// special case of pre-defined macros
if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
lyxerr << "defining: '" << line << "'\n";
istringstream is(line);
MathMacroTable::create(MathAtom(new MathMacroTemplate(is)));
continue;
}
istringstream is(line);
is >> tmp.name >> tmp.inset;
if (isFontName(tmp.inset))
@ -147,15 +156,18 @@ void initSymbols()
} // namespace anon
latexkeys const * in_word_set(string const & str)
void initMath()
{
static bool initialized = false;
if (!initialized) {
initSymbols();
initialized = true;
}
}
latexkeys const * in_word_set(string const & str)
{
WordList::iterator it = theWordList.find(str);
//lyxerr << "looking up '" << str << "' found: "
// << (it != theWordList.end()) << "\n";

View File

@ -298,6 +298,7 @@ std::ostream & operator<<(std::ostream &, MathAtom const &);
string asString(MathArray const & ar);
MathArray asArray(string const & str);
void initMath();
/// here to ssave a few includes in the insets
class Dialogs;

View File

@ -34,112 +34,22 @@ void MathMacroTable::dump()
MathAtom & MathMacroTable::provide(string const & name)
{
builtinMacros();
table_type::iterator pos = macro_table.find(name);
if (pos == macro_table.end()) {
lyxerr << "MathMacroTable::provideTemplate: no template with name '"
<< name << "' available.\n";
}
return pos->second;
}
void MathMacroTable::create(string const & name, int na)
void MathMacroTable::create(MathAtom const & at)
{
macro_table[name] = MathAtom(new MathMacroTemplate(name, na));
}
void MathMacroTable::create
(string const & name, int na, MathArray const & ar1, MathArray const & ar2)
{
MathAtom t(new MathMacroTemplate(name, na));
t->cell(0) = ar1;
t->cell(1) = ar2;
macro_table[name] = t;
}
void MathMacroTable::define(string const & display)
{
string name;
mathed_parse_macro(name, display);
macro_table[at->asMacroTemplate()->name()] = at;
}
bool MathMacroTable::has(string const & name)
{
builtinMacros();
return macro_table.find(name) != macro_table.end();
}
void MathMacroTable::builtinMacros()
{
static bool built = false;
if (built)
return;
built = true;
//lyxerr[Debug::MATHED] << "Building macros\n";
//define("\\def\\emptyset{\\not0}");
define("\\def\\notin{\\not\\in}");
define("\\def\\slash{/}");
//define("\\def\\mathcircumflex{\\^}");
// fontmath.ltx
define("\\def\\longleftrightarrow{\\leftarrow\\kern-8mu\\rightarrow}");
define("\\def\\Longleftrightarrow{\\Leftarrow\\kern-8mu\\Rightarrow}");
define("\\def\\doteq{\\stackrel{\\cdot}{\\=}}");
//if (math_font_available(LM_TC_CMSY)) {
define("\\def\\longrightarrow{\\lyxbar\\kern-6mu\\rightarrow}");
define("\\def\\longleftarrow{\\leftarrow\\kern-6mu\\lyxbar}");
define("\\def\\mapsto{\\mapstochar\\kern-4mu\\rightarrow}");
define("\\def\\longmapsto{\\mapstochar\\kern-3mu\\lyxbar\\kern-6mu\\rightarrow}");
//}
//if (math_font_available(LM_TC_CMR) && math_font_available(LM_TC_CMSY)) {
define("\\def\\Longrightarrow{\\lyxeq\\kern-5mu\\Rightarrow}");
define("\\def\\Longleftarrow{\\Leftarrow\\kern-5mu\\lyxeq}");
define("\\def\\models{\\vert\\kern-3mu\\lyxeq}");
//}
//if (math_font_available(LM_TC_CMM)) {
define("\\def\\hookrightarrow{\\lhook\\kern-8mu\\rightarrow}");
define("\\def\\hookleftarrow{\\leftarrow\\kern-8mu\\rhook}");
define("\\def\\bowtie{\\triangleright\\kern-2mu\\triangleleft}");
//}
//if (math_font_available(LM_TC_MSA)) {
//amsfonts.sty
define("\\def\\dashrightarrow{\\lyxdabar\\lyxdabar\\lyxright}");
define("\\def\\dashleftarrow{\\lyxleft\\lyxdabar\\lyxdabar}");
define("\\def\\dasharrow{\\dashrightarrow}");
define("\\def\\leadsto{\\rightsquigarrow}");
// amssymb.sty
define("\\def\\restriction{\\upharpoonright}");
define("\\def\\Doteq{\\doteqdot}");
define("\\def\\doublecup{\\Cup}");
define("\\def\\doublecap{\\Cap}");
//}
//if (math_font_available(LM_TC_MSB)) {
define("\\def\\Join{\\ltimes\\kern-12mu\\rtimes}");
//}
//
define("\\def\\mathcircumflex{\\mbox{\\^{}}}\n" "{\\hat{}}");
//define("\def\lint", 4, "\\int_#1^#2#3 d#4}");
//define("\\def\\silentmult{\\cdot}");
//define("\def\binom", 2, "\\left(\\frac#1#2\\right)}");
}

View File

@ -10,30 +10,23 @@
#pragma interface
#endif
class MathArray;
///
struct MathMacroTable {
class MathMacroTable {
public:
///
static void create(string const &, int);
static void create(MathAtom const &);
///
static void create(string const &, int, MathArray const &, MathArray const &);
static MathAtom & provide(string const & name);
///
static MathAtom & provide(string const &);
///
static bool has(string const &);
///
static void builtinMacros();
static bool has(string const & name);
///
static void dump();
private:
/// create internal macros (like \longrightarrow...)
static void define(string const & display);
///
typedef std::map<string, MathAtom> table_type;
//
static table_type macro_table;
};
#endif

View File

@ -4,6 +4,7 @@
#include "math_macrotemplate.h"
#include "math_mathmlstream.h"
#include "math_parser.h"
#include "frontends/Painter.h"
#include "debug.h"
@ -13,12 +14,29 @@ MathMacroTemplate::MathMacroTemplate()
{}
MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs,
MathArray const & ar1, MathArray const & ar2)
: MathNestInset(2), numargs_(numargs), name_(nm)
{
if (numargs_ > 9)
lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
<< numargs_ << std::endl;
cell(0) = ar1;
cell(1) = ar2;
}
MathMacroTemplate::MathMacroTemplate(std::istream & is)
: MathNestInset(2), numargs_(0), name_()
{
MathArray ar;
mathed_parse_cell(ar, is);
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
lyxerr << "cannot read macro from '" << ar << "'\n";
return;
}
operator=( *(ar[0]->asMacroTemplate()) );
}
@ -70,6 +88,7 @@ void MathMacroTemplate::draw(MathPainterInfo & pi, int x, int y) const
}
void MathMacroTemplate::write(WriteStream & os) const
{
if (os.latex()) {

View File

@ -21,7 +21,10 @@ public:
///
MathMacroTemplate();
///
MathMacroTemplate(string const & name, int nargs);
MathMacroTemplate(string const & name, int nargs,
MathArray const & = MathArray(), MathArray const & = MathArray());
///
explicit MathMacroTemplate(std::istream & is);
///
MathInset * clone() const;
///

View File

@ -48,7 +48,6 @@ following hack as starting point to write some macros:
#include "math_factory.h"
#include "math_kerninset.h"
#include "math_macro.h"
#include "math_macrotable.h"
#include "math_macrotemplate.h"
#include "math_hullinset.h"
#include "math_parboxinset.h"
@ -226,11 +225,9 @@ public:
Parser(istream & is);
///
bool parse_macro(string & name);
bool parse(MathAtom & at);
///
bool parse_normal(MathAtom & at);
///
void parse_into(MathArray & array, unsigned flags, bool mathmode);
void parse(MathArray & array, unsigned flags, bool mathmode);
///
int lineno() const { return lineno_; }
///
@ -238,9 +235,9 @@ public:
private:
///
void parse_into1(MathGridInset & grid, unsigned flags, bool mathmode, bool numbered);
void parse1(MathGridInset & grid, unsigned flags, bool mathmode, bool numbered);
///
void parse_into2(MathAtom & at, unsigned flags, bool mathmode, bool numbered);
void parse2(MathAtom & at, unsigned flags, bool mathmode, bool numbered);
/// get arg delimited by 'left' and 'right'
string getArg(char left, char right);
///
@ -500,89 +497,12 @@ void Parser::error(string const & msg)
}
bool Parser::parse_macro(string & name)
{
int nargs = 0;
name = "{error}";
skipSpaces();
if (nextToken().cs() == "def") {
getToken();
name = getToken().cs();
string pars;
while (good() && nextToken().cat() != catBegin)
pars += getToken().cs();
if (!good()) {
error("bad stream in parse_macro\n");
return false;
}
//lyxerr << "read \\def parameter list '" << pars << "'\n";
if (!pars.empty()) {
error("can't handle non-empty parameter lists\n");
return false;
}
} else if (nextToken().cs() == "newcommand") {
// skip the 'newcommand'
getToken();
if (getToken().cat() != catBegin) {
error("'{' in \\newcommand expected (1) \n");
return false;
}
name = getToken().cs();
if (getToken().cat() != catEnd) {
error("'}' in \\newcommand expected\n");
return false;
}
string arg = getArg('[', ']');
if (!arg.empty())
nargs = atoi(arg.c_str());
} else {
lyxerr << "\\newcommand or \\def expected\n";
return false;
}
if (getToken().cat() != catBegin) {
error("'{' in macro definition expected (2)\n");
return false;
}
MathArray ar1;
parse_into(ar1, FLAG_BRACE_LAST, true);
// we cannot handle recursive stuff at all
MathArray test;
test.push_back(createMathInset(name));
if (ar1.contains(test)) {
error("we cannot handle recursive macros at all.\n");
return false;
}
// is a version for display attached?
MathArray ar2;
parse_into(ar2, FLAG_ITEM, true);
MathMacroTable::create(name, nargs, ar1, ar2);
return true;
}
bool Parser::parse_normal(MathAtom & at)
bool Parser::parse(MathAtom & at)
{
skipSpaces();
MathArray ar;
parse_into(ar, false, false);
parse(ar, false, false);
if (ar.size() != 1 || ar.front()->getType() == "none") {
lyxerr << "unusual contents found: " << ar << endl;
at.reset(new MathParInset);
@ -597,22 +517,22 @@ bool Parser::parse_normal(MathAtom & at)
}
void Parser::parse_into(MathArray & array, unsigned flags, bool mathmode)
void Parser::parse(MathArray & array, unsigned flags, bool mathmode)
{
MathGridInset grid(1, 1);
parse_into1(grid, flags, mathmode, false);
parse1(grid, flags, mathmode, false);
array = grid.cell(0);
}
void Parser::parse_into2(MathAtom & at, unsigned flags,
void Parser::parse2(MathAtom & at, unsigned flags,
bool mathmode, bool numbered)
{
parse_into1(*(at->asGridInset()), flags, mathmode, numbered);
parse1(*(at->asGridInset()), flags, mathmode, numbered);
}
void Parser::parse_into1(MathGridInset & grid, unsigned flags,
void Parser::parse1(MathGridInset & grid, unsigned flags,
bool mathmode, bool numbered)
{
int limits = 0;
@ -674,13 +594,13 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
if (n.cat() == catMath) {
// TeX's $$...$$ syntax for displayed math
cell->push_back(MathAtom(new MathHullInset("equation")));
parse_into2(cell->back(), FLAG_SIMPLE, true, false);
parse2(cell->back(), FLAG_SIMPLE, true, false);
getToken(); // skip the second '$' token
} else {
// simple $...$ stuff
putback();
cell->push_back(MathAtom(new MathHullInset("simple")));
parse_into2(cell->back(), FLAG_SIMPLE, true, false);
parse2(cell->back(), FLAG_SIMPLE, true, false);
}
}
@ -708,7 +628,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else if (t.cat() == catBegin) {
MathArray ar;
parse_into(ar, FLAG_BRACE_LAST, mathmode);
parse(ar, FLAG_BRACE_LAST, mathmode);
// do not create a BraceInset if they were written by LyX
// this helps to keep the annoyance of "a choose b" to a minimum
if (ar.size() == 1 && ar[0]->extraBraces())
@ -745,7 +665,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
p = cell->back()->asScriptInset();
}
p->ensure(up);
parse_into(p->cell(up), FLAG_ITEM, mathmode);
parse(p->cell(up), FLAG_ITEM, mathmode);
p->limits(limits);
limits = 0;
}
@ -759,14 +679,72 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
//
// control sequences
//
else if (t.cs() == "def" || t.cs() == "newcommand") {
string name;
int nargs = 0;
if (t.cs() == "def") {
// get name
name = getToken().cs();
// read parameter
string pars;
while (good() && nextToken().cat() != catBegin) {
pars += getToken().cs();
++nargs;
}
nargs /= 2;
//lyxerr << "read \\def parameter list '" << pars << "'\n";
} else { // t.cs() == "newcommand"
if (getToken().cat() != catBegin) {
error("'{' in \\newcommand expected (1) \n");
return;
}
name = getToken().cs();
if (getToken().cat() != catEnd) {
error("'}' in \\newcommand expected\n");
return;
}
string arg = getArg('[', ']');
if (!arg.empty())
nargs = atoi(arg.c_str());
}
MathArray ar1;
parse(ar1, FLAG_ITEM, true);
// we cannot handle recursive stuff at all
//MathArray test;
//test.push_back(createMathInset(name));
//if (ar1.contains(test)) {
// error("we cannot handle recursive macros at all.\n");
// return;
//}
// is a version for display attached?
skipSpaces();
MathArray ar2;
if (nextToken().cat() == catBegin) {
parse(ar2, FLAG_ITEM, true);
}
cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
}
else if (t.cs() == "(") {
cell->push_back(MathAtom(new MathHullInset("simple")));
parse_into2(cell->back(), FLAG_SIMPLE2, true, false);
parse2(cell->back(), FLAG_SIMPLE2, true, false);
}
else if (t.cs() == "[") {
cell->push_back(MathAtom(new MathHullInset("equation")));
parse_into2(cell->back(), FLAG_EQUATION, true, false);
parse2(cell->back(), FLAG_EQUATION, true, false);
}
else if (t.cs() == "protect")
@ -811,7 +789,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else if (t.cs() == "multicolumn") {
// extract column count and insert dummy cells
MathArray count;
parse_into(count, FLAG_ITEM, mathmode);
parse(count, FLAG_ITEM, mathmode);
int cols = 1;
if (!extractNumber(count, cols)) {
lyxerr << " can't extract number of cells from " << count << "\n";
@ -832,11 +810,11 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
// read special alignment
MathArray align;
parse_into(align, FLAG_ITEM, mathmode);
parse(align, FLAG_ITEM, mathmode);
//grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
// parse the remaining contents into the "real" cell
parse_into(*cell, FLAG_ITEM, mathmode);
parse(*cell, FLAG_ITEM, mathmode);
}
#endif
@ -863,27 +841,27 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else if (t.cs() == "sqrt") {
MathArray ar;
parse_into(ar, FLAG_OPTION, mathmode);
parse(ar, FLAG_OPTION, mathmode);
if (ar.size()) {
cell->push_back(MathAtom(new MathRootInset));
cell->back()->cell(0) = ar;
parse_into(cell->back()->cell(1), FLAG_ITEM, mathmode);
parse(cell->back()->cell(1), FLAG_ITEM, mathmode);
} else {
cell->push_back(MathAtom(new MathSqrtInset));
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode);
parse(cell->back()->cell(0), FLAG_ITEM, mathmode);
}
}
else if (t.cs() == "ref") {
cell->push_back(MathAtom(new RefInset));
parse_into(cell->back()->cell(1), FLAG_OPTION, mathmode);
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode);
parse(cell->back()->cell(1), FLAG_OPTION, mathmode);
parse(cell->back()->cell(0), FLAG_ITEM, mathmode);
}
else if (t.cs() == "left") {
string l = getToken().asString();
MathArray ar;
parse_into(ar, FLAG_RIGHT, mathmode);
parse(ar, FLAG_RIGHT, mathmode);
string r = getToken().asString();
cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
}
@ -902,71 +880,71 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
string const valign = getArg('[', ']') + 'c';
string const halign = getArg('{', '}');
cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
parse_into2(cell->back(), FLAG_END, mathmode, false);
parse2(cell->back(), FLAG_END, mathmode, false);
}
else if (name == "split" || name == "cases" ||
name == "gathered" || name == "aligned") {
cell->push_back(createMathInset(name));
parse_into2(cell->back(), FLAG_END, mathmode, false);
parse2(cell->back(), FLAG_END, mathmode, false);
}
else if (name == "math") {
cell->push_back(MathAtom(new MathHullInset("simple")));
parse_into2(cell->back(), FLAG_END, true, true);
parse2(cell->back(), FLAG_END, true, true);
}
else if (name == "equation" || name == "equation*"
|| name == "displaymath") {
cell->push_back(MathAtom(new MathHullInset("equation")));
parse_into2(cell->back(), FLAG_END, true, (name == "equation"));
parse2(cell->back(), FLAG_END, true, (name == "equation"));
}
else if (name == "eqnarray" || name == "eqnarray*") {
cell->push_back(MathAtom(new MathHullInset("eqnarray")));
parse_into2(cell->back(), FLAG_END, true, !stared(name));
parse2(cell->back(), FLAG_END, true, !stared(name));
}
else if (name == "align" || name == "align*") {
cell->push_back(MathAtom(new MathHullInset("align")));
parse_into2(cell->back(), FLAG_END, true, !stared(name));
parse2(cell->back(), FLAG_END, true, !stared(name));
}
else if (name == "alignat" || name == "alignat*") {
// ignore this for a while
getArg('{', '}');
cell->push_back(MathAtom(new MathHullInset("alignat")));
parse_into2(cell->back(), FLAG_END, true, !stared(name));
parse2(cell->back(), FLAG_END, true, !stared(name));
}
else if (name == "xalignat" || name == "xalignat*") {
// ignore this for a while
getArg('{', '}');
cell->push_back(MathAtom(new MathHullInset("xalignat")));
parse_into2(cell->back(), FLAG_END, true, !stared(name));
parse2(cell->back(), FLAG_END, true, !stared(name));
}
else if (name == "xxalignat") {
// ignore this for a while
getArg('{', '}');
cell->push_back(MathAtom(new MathHullInset("xxalignat")));
parse_into2(cell->back(), FLAG_END, true, !stared(name));
parse2(cell->back(), FLAG_END, true, !stared(name));
}
else if (name == "multline" || name == "multline*") {
cell->push_back(MathAtom(new MathHullInset("multline")));
parse_into2(cell->back(), FLAG_END, true, !stared(name));
parse2(cell->back(), FLAG_END, true, !stared(name));
}
else if (name == "gather" || name == "gather*") {
cell->push_back(MathAtom(new MathHullInset("gather")));
parse_into2(cell->back(), FLAG_END, true, !stared(name));
parse2(cell->back(), FLAG_END, true, !stared(name));
}
else if (latexkeys const * l = in_word_set(name)) {
if (l->inset == "matrix") {
cell->push_back(createMathInset(name));
parse_into2(cell->back(), FLAG_END, mathmode, false);
parse2(cell->back(), FLAG_END, mathmode, false);
}
}
@ -974,7 +952,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
// lyxerr << "unknow math inset begin '" << name << "'\n";
// create generic environment inset
cell->push_back(MathAtom(new MathEnvInset(name)));
parse_into(cell->back()->cell(0), FLAG_END, mathmode);
parse(cell->back()->cell(0), FLAG_END, mathmode);
}
}
@ -998,7 +976,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else if (t.cs() == "label") {
MathArray ar;
parse_into(ar, FLAG_ITEM, false);
parse(ar, FLAG_ITEM, false);
if (grid.asHullInset()) {
grid.asHullInset()->label(cellrow, asString(ar));
} else {
@ -1010,19 +988,19 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
MathAtom p = createMathInset(t.cs());
cell->swap(p->cell(0));
parse_into(p->cell(1), flags, mathmode);
parse(p->cell(1), flags, mathmode);
cell->push_back(p);
return;
}
else if (t.cs() == "substack") {
cell->push_back(createMathInset(t.cs()));
parse_into2(cell->back(), FLAG_ITEM, mathmode, false);
parse2(cell->back(), FLAG_ITEM, mathmode, false);
}
else if (t.cs() == "xymatrix") {
cell->push_back(createMathInset(t.cs()));
parse_into2(cell->back(), FLAG_ITEM, mathmode, false);
parse2(cell->back(), FLAG_ITEM, mathmode, false);
}
#if 0
@ -1030,12 +1008,12 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else if (1 && t.cs() == "ar") {
MathXYArrowInset * p = new MathXYArrowInset;
// try to read target
parse_into(p->cell(0), FLAG_OTPTION, mathmode);
parse(p->cell(0), FLAG_OTPTION, mathmode);
// try to read label
if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
p->up_ = nextToken().cat() == catSuper;
getToken();
parse_into(p->cell(1), FLAG_ITEM, mathmode);
parse(p->cell(1), FLAG_ITEM, mathmode);
//lyxerr << "read label: " << p->cell(1) << "\n";
}
@ -1051,30 +1029,30 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
lyxerr << "starting font " << t.cs() << "\n";
MathAtom p = createMathInset(t.cs());
bool textmode = (t.cs()[0] == 't');
parse_into(p->cell(0), FLAG_ITEM, !textmode);
parse(p->cell(0), FLAG_ITEM, !textmode);
cell->push_back(p);
//lyxerr << "ending font\n";
}
else if (l->inset == "oldfont") {
cell->push_back(createMathInset(t.cs()));
parse_into(cell->back()->cell(0), flags, l->extra == "mathmode");
parse(cell->back()->cell(0), flags, l->extra == "mathmode");
return;
}
else if (l->inset == "style") {
cell->push_back(createMathInset(t.cs()));
parse_into(cell->back()->cell(0), flags, mathmode);
parse(cell->back()->cell(0), flags, mathmode);
return;
}
else if (l->inset == "parbox") {
// read optional positioning and width
MathArray pos, width;
parse_into(pos, FLAG_OPTION, false);
parse_into(width, FLAG_ITEM, false);
parse(pos, FLAG_OPTION, false);
parse(width, FLAG_ITEM, false);
cell->push_back(createMathInset(t.cs()));
parse_into(cell->back()->cell(0), FLAG_ITEM, false);
parse(cell->back()->cell(0), FLAG_ITEM, false);
cell->back()->asParboxInset()->setPosition(asString(pos));
cell->back()->asParboxInset()->setWidth(asString(width));
}
@ -1082,7 +1060,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else {
MathAtom p = createMathInset(t.cs());
for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
parse_into(p->cell(i), FLAG_ITEM, l->extra != "forcetext");
parse(p->cell(i), FLAG_ITEM, l->extra != "forcetext");
cell->push_back(p);
}
}
@ -1090,7 +1068,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else {
MathAtom p = createMathInset(t.cs());
for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
parse_into(p->cell(i), FLAG_ITEM, mathmode);
parse(p->cell(i), FLAG_ITEM, mathmode);
cell->push_back(p);
}
}
@ -1117,45 +1095,24 @@ void mathed_parse_cell(MathArray & ar, string const & str)
void mathed_parse_cell(MathArray & ar, istream & is)
{
Parser(is).parse_into(ar, 0, true);
Parser(is).parse(ar, 0, true);
}
bool mathed_parse_macro(string & name, string const & str)
{
istringstream is(str.c_str());
return Parser(is).parse_macro(name);
}
bool mathed_parse_macro(string & name, istream & is)
{
return Parser(is).parse_macro(name);
}
bool mathed_parse_macro(string & name, LyXLex & lex)
{
return Parser(lex).parse_macro(name);
}
bool mathed_parse_normal(MathAtom & t, string const & str)
{
istringstream is(str.c_str());
return Parser(is).parse_normal(t);
return Parser(is).parse(t);
}
bool mathed_parse_normal(MathAtom & t, istream & is)
{
return Parser(is).parse_normal(t);
return Parser(is).parse(t);
}
bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
{
return Parser(lex).parse_normal(t);
return Parser(lex).parse(t);
}

View File

@ -55,13 +55,6 @@ bool mathed_parse_normal(MathAtom &, std::istream &);
/// ... the LyX lexxer
bool mathed_parse_normal(MathAtom &, LyXLex &);
/// parse a macro definition from a string, enter it into the macro table
bool mathed_parse_macro(string &, string const &);
/// ... a stream
bool mathed_parse_macro(string &, std::istream &);
/// ... the LyX lexxer
bool mathed_parse_macro(string &, LyXLex &);
/// parse a single cell from a string
void mathed_parse_cell(MathArray & ar, string const &);
/// ... a stream