fix macro, small cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1623 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-26 12:53:35 +00:00
parent b6cff00278
commit 2be247f6ef
23 changed files with 964 additions and 891 deletions

View File

@ -1,3 +1,21 @@
2001-02-26 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* math_macroarg.C (MathMacroArgument): delete
* math_macro.C (~MathMacro): delete
* math_macrotemplate.C (~MathMacroTemplate): delete
* math_decorationinset.[Ch]: add pragma
* math_deliminset.[Ch]: likewise
* math_fracinset.[Ch]: likewise
* math_macroarg.[Ch]: likewise
* math_macrotemplate.[Ch]: likewise
* math_matrixinset.[Ch]: likewise
* formulamacro.C (Read): set contents of tmacro_ to ar.
* formulamacro.h: add '_' to private variables.
* formalamacro.C: changes because of this.
2001-02-23 Juergen Vigna <jug@sad.it>
* formula.C (LocalDispatch): changed action to be a kb_action (as it

View File

@ -34,6 +34,7 @@
#include "support/lyxlib.h"
#include "mathed/support.h"
#include "support/LOstream.h"
#include "debug.h"
using std::ostream;
using std::istream;
@ -41,20 +42,20 @@ using std::istream;
InsetFormulaMacro::InsetFormulaMacro()
: InsetFormula(true)
{
tmacro = 0;
opened = false;
tmacro_ = 0;
opened_ = false;
}
InsetFormulaMacro::InsetFormulaMacro(string nm, int na, bool /*e*/)
: InsetFormula(true), name(nm)
InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
: InsetFormula(true), name_(nm)
{
tmacro = MathMacroTable::mathMTable.getTemplate(name);
if (!tmacro) {
tmacro = new MathMacroTemplate(name.c_str(), na);
MathMacroTable::mathMTable.addTemplate(tmacro);
tmacro_ = MathMacroTable::mathMTable.getTemplate(name_);
if (!tmacro_) {
tmacro_ = new MathMacroTemplate(name_, na);
MathMacroTable::mathMTable.addTemplate(tmacro_);
}
opened = false;
opened_ = false;
}
@ -66,21 +67,21 @@ InsetFormulaMacro::~InsetFormulaMacro()
Inset * InsetFormulaMacro::Clone(Buffer const &) const
{
return new InsetFormulaMacro(name);
return new InsetFormulaMacro(name_);
}
void InsetFormulaMacro::Write(Buffer const *, ostream & os) const
{
os << "FormulaMacro ";
tmacro->WriteDef(os, false);
tmacro_->WriteDef(os, false);
}
int InsetFormulaMacro::Latex(Buffer const *, ostream & os, bool /*fragile*/,
bool /*free_spacing*/) const
{
tmacro->WriteDef(os, true); // or false?
tmacro_->WriteDef(os, true); // or false?
return 2;
}
@ -102,14 +103,18 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
istream & is = lex.getStream();
mathed_parser_file(is, lex.GetLineNo());
MathedArray ar;
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro));
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro_));
tmacro_->setData(ar);
// Update line number
lex.setLineNo(mathed_parser_lineno());
MathMacroTable::mathMTable.addTemplate(tmacro);
name = tmacro->GetName();
par = tmacro;
MathMacroTable::mathMTable.addTemplate(tmacro_);
name_ = tmacro_->GetName();
par = tmacro_;
// reading of end_inset in the inset!!!
while (lex.IsOK()) {
lex.nextToken();
@ -121,8 +126,8 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const
{
if (opened) {
tmacro->update();
if (opened_) {
tmacro_->update();
return InsetFormula::ascent(pain, f);
}
return lyxfont::maxAscent(f) + 3;
@ -131,8 +136,8 @@ int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const
int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const
{
if (opened) {
tmacro->update();
if (opened_) {
tmacro_->update();
return InsetFormula::descent(pain, f);
}
return lyxfont::maxDescent(f) + 1;
@ -141,12 +146,12 @@ int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const
int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const
{
if (opened) {
tmacro->update();
if (opened_) {
tmacro_->update();
return InsetFormula::width(bv, f);
}
string ilabel(_("Macro: "));
ilabel += name;
ilabel += name_;
return 6 + lyxfont::width(ilabel, f);
}
@ -156,11 +161,11 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
{
Painter & pain = bv->painter();
LyXFont font(f);
tmacro->update();
if (opened) {
tmacro->setEditMode(true);
tmacro_->update();
if (opened_) {
tmacro_->setEditMode(true);
InsetFormula::draw(bv, font, baseline, x, cleared);
tmacro->setEditMode(false);
tmacro_->setEditMode(false);
} else {
font.setColor(LColor::math);
@ -172,7 +177,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
pain.rectangle(int(x), y, w, h, LColor::mathframe);
string s(_("Macro: "));
s += name;
s += name_;
pain.text(int(x + 2), baseline, s, font);
x += width(bv, font) - 1;
}
@ -187,17 +192,17 @@ string const InsetFormulaMacro::EditMessage() const
void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button)
{
opened = true;
par = static_cast<MathParInset*>(tmacro->Clone());
opened_ = true;
par = static_cast<MathParInset*>(tmacro_->Clone());
InsetFormula::Edit(bv, x, y, button);
}
void InsetFormulaMacro::InsetUnlock(BufferView * bv)
{
opened = false;
tmacro->setData(par->GetData());
tmacro->setEditMode(false);
opened_ = false;
tmacro_->setData(par->GetData());
tmacro_->setEditMode(false);
InsetFormula::InsetUnlock(bv);
}
@ -207,19 +212,19 @@ InsetFormulaMacro::LocalDispatch(BufferView * bv,
kb_action action, string const & arg)
{
if (action == LFUN_MATH_MACROARG) {
int i = lyx::atoi(arg) - 1;
if (i >= 0 && i < tmacro->getNoArgs()) {
mathcursor->insertInset(tmacro->getMacroPar(i),
int const i = lyx::atoi(arg) - 1;
if (i >= 0 && i < tmacro_->getNoArgs()) {
mathcursor->insertInset(tmacro_->getMacroPar(i),
LM_TC_INSET);
InsetFormula::UpdateLocal(bv);
}
return DISPATCHED;
}
tmacro->setEditMode(true);
tmacro->Metrics();
tmacro_->setEditMode(true);
tmacro_->Metrics();
RESULT result = InsetFormula::LocalDispatch(bv, action, arg);
tmacro->setEditMode(false);
tmacro_->setEditMode(false);
return result;
}

View File

@ -33,7 +33,7 @@ public:
InsetFormulaMacro();
///
explicit
InsetFormulaMacro(string name, int na = 0, bool env = false);
InsetFormulaMacro(string name, int na = 0);
///
~InsetFormulaMacro();
///
@ -58,7 +58,7 @@ public:
///
Inset * Clone(Buffer const &) const;
///
Inset::Code LyxCode() const { return Inset::MATHMACRO_CODE; }
Inset::Code LyxCode() const;
/// what appears in the minibuffer when opening
string const EditMessage() const;
///
@ -70,11 +70,17 @@ public:
private:
///
bool opened;
bool opened_;
///
string name;
string name_;
///
MathMacroTemplate * tmacro;
MathMacroTemplate * tmacro_;
};
inline
Inset::Code InsetFormulaMacro::LyxCode() const
{
return Inset::MATHMACRO_CODE;
}
#endif

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_decorationinset.h"
#include "math_iter.h"
#include "mathed/support.h"
@ -39,7 +43,7 @@ MathDecorationInset::draw(Painter & pain, int x, int y)
void
MathDecorationInset::Metrics()
{
int h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
int const h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
ascent, descent);
MathParInset::Metrics();
int w = Width() + 4;

View File

@ -1,8 +1,13 @@
// -*- C++ -*-
#ifndef MATH_DECORATIONINSET_H
#define MATH_DECORATIONINSET_H
#include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Decorations over (below) a math object
\author Alejandro Aguilar Sierra
*/

View File

@ -120,7 +120,7 @@ enum MathedTextCodes {
LM_TC_MAX
};
///
/// Defined in math_macro.C
std::ostream & operator<<(std::ostream &, MathedTextCodes mtc);

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_deliminset.h"
#include "math_iter.h"
#include "math_parser.h"
@ -78,8 +82,8 @@ void
MathDelimInset::Metrics()
{
MathParInset::Metrics();
int d;
int d;
mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_);
dh_ /= 2;
ascent += 2 + dh_;

View File

@ -4,6 +4,10 @@
#include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** A delimiter
\author Alejandro Aguilar Sierra
*/

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_fracinset.h"
#include "math_iter.h"
#include "LColor.h"
@ -96,7 +100,7 @@ MathedArray & MathFracInset::GetData()
bool MathFracInset::Inside(int x, int y)
{
int xx = xo() - (width - w0_) / 2;
int const xx = xo() - (width - w0_) / 2;
return x >= xx
&& x <= xx + width

View File

@ -4,6 +4,10 @@
#include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Fraction like objects (frac, stackrel, binom)
\author Alejandro Aguilar Sierra
*/

View File

@ -75,11 +75,6 @@ MathMacro::MathMacro(MathMacro * m):
}
MathMacro::~MathMacro()
{
}
MathedInset * MathMacro::Clone()
{
return new MathMacro(this);

View File

@ -41,8 +41,6 @@ public:
explicit
MathMacro(MathMacro *);
///
~MathMacro();
///
void draw(Painter &, int, int);
///
void Metrics();

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macroarg.h"
#include "mathed/support.h"
#include "debug.h"
@ -19,12 +23,6 @@ MathMacroArgument::MathMacroArgument(int n)
}
MathMacroArgument::~MathMacroArgument()
{
lyxerr << "help, destroyme!" << std::endl;
}
MathedInset * MathMacroArgument::Clone()
{
return this;

View File

@ -4,6 +4,10 @@
#include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** A macro argument
\author Alejandro Aguilar Sierra
*/
@ -15,8 +19,6 @@ public:
explicit
MathMacroArgument(int);
///
~MathMacroArgument();
///
MathedInset * Clone();
///
void Metrics();

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macrotemplate.h"
#include "math_macro.h"
#include "macro_support.h"
@ -8,24 +12,6 @@
using std::ostream;
void MathMacroTemplate::setTCode(MathedTextCodes t)
{
tcode_ = t;
}
MathedTextCodes MathMacroTemplate::getTCode() const
{
return tcode_;
}
int MathMacroTemplate::getNoArgs() const
{
return nargs_;
}
MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags_(flg), nargs_(na)
@ -44,8 +30,26 @@ MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
}
MathMacroTemplate::~MathMacroTemplate()
{}
//MathMacroTemplate::~MathMacroTemplate()
//{}
void MathMacroTemplate::setTCode(MathedTextCodes t)
{
tcode_ = t;
}
MathedTextCodes MathMacroTemplate::getTCode() const
{
return tcode_;
}
int MathMacroTemplate::getNoArgs() const
{
return nargs_;
}
void MathMacroTemplate::setEditMode(bool ed)

View File

@ -7,6 +7,10 @@
#include "math_parinset.h"
#include "math_macroarg.h"
#ifdef __GNUG__
#pragma interface
#endif
class MathMacro;
/** This class contains the macro definition
@ -18,7 +22,7 @@ public:
explicit
MathMacroTemplate(string const &, int na = 0, int f = 0);
///
~MathMacroTemplate();
//~MathMacroTemplate();
///
void draw(Painter &, int, int);
///
@ -45,9 +49,7 @@ public:
/// Replace the appropriate arguments with a specific macro's data
void update(MathMacro * m = 0);
///
short flags() const {
return flags_;
}
short flags() const;
private:
///
short flags_;
@ -58,4 +60,10 @@ private:
///
int nargs_;
};
inline
short MathMacroTemplate::flags() const {
return flags_;
}
#endif

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_matrixinset.h"
#include "math_rowst.h"
#include "math_xiter.h"
@ -171,7 +175,7 @@ void MathMatrixInset::Metrics()
cxrow = cxrow->getNext();
}
int hl = Descent();
int const hl = Descent();
h -= MATH_ROWSEP;
// Compute vertical align
@ -229,7 +233,7 @@ void MathMatrixInset::Metrics()
lf = (ws_[i] - cxrow->getTab(i))/2;
break;
}
int ww = (isvoid) ? lf : lf + cxrow->getTab(i);
int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
cxrow->setTab(i, lf + rg);
rg = ws_[i] - ww + MATH_COLSEP;
if (cxrow == row_)

View File

@ -6,6 +6,10 @@
#include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Multiline math paragraph base class.
This is the base to all multiline editable math objects
like array and eqnarray.
@ -20,9 +24,9 @@ public:
explicit
MathMatrixInset(MathMatrixInset *);
///
MathedInset * Clone();
~MathMatrixInset();
///
virtual ~MathMatrixInset();
MathedInset * Clone();
///
void draw(Painter &, int, int);
///

View File

@ -78,6 +78,7 @@ union YYSTYPE {
latexkeys const * l;
};
static
YYSTYPE yylval;
@ -85,6 +86,7 @@ YYSTYPE yylval;
static
MathedInsetTypes mathed_env = LM_OT_MIN;
string mathed_label;
@ -105,10 +107,9 @@ char const * latex_mathenv[latex_mathenv_num] = {
};
char const * latex_special_chars = "#$%&_{}";
// These are lexical codes, not semantic
enum lexcode_enum {
LexNone,
@ -127,6 +128,7 @@ enum lexcode_enum {
LexSelf
};
static lexcode_enum lexcode[256];
#warning Replace with string
//static char yytext[256];
@ -135,7 +137,8 @@ static int yylineno;
static istream * yyis;
static bool yy_mtextmode= false;
static
static inline
void mathPrintError(string const & msg)
{
lyxerr << "Line ~" << yylineno << ": Math parse error: "
@ -147,20 +150,25 @@ static
void LexInitCodes()
{
for (int i = 0; i <= 255; ++i) {
if (isalpha(i)) lexcode[i] = LexAlpha;
else if (isdigit(i)) lexcode[i] = LexDigit;
else if (isspace(i)) lexcode[i] = LexSpace;
else lexcode[i] = LexNone;
if (isalpha(i))
lexcode[i] = LexAlpha;
else if (isdigit(i))
lexcode[i] = LexDigit;
else if (isspace(i))
lexcode[i] = LexSpace;
else
lexcode[i] = LexNone;
}
lexcode['\t'] = lexcode['\f'] = lexcode[' '] = LexSpace;
lexcode['\n'] = LexNewLine;
lexcode['%'] = LexComment;
lexcode['#'] = LexArgument;
lexcode['+'] = lexcode['-'] = lexcode['*'] = lexcode['/'] =
lexcode['<'] = lexcode['>'] = lexcode['='] = LexBOP;
lexcode['+'] = lexcode['-'] = lexcode['*'] = lexcode['/']
= lexcode['<'] = lexcode['>'] = lexcode['='] = LexBOP;
lexcode['!'] = lexcode[','] = lexcode[':'] = lexcode[';'] = LexMathSpace;
lexcode['!'] = lexcode[','] = lexcode[':']
= lexcode[';'] = LexMathSpace;
lexcode['('] = lexcode[')'] = lexcode['|'] = lexcode['.'] =
lexcode['?'] = LexOther;
@ -179,11 +187,12 @@ void LexInitCodes()
static
char LexGetArg(char lf, bool accept_spaces = false)
{
unsigned char c;
char cc;
// unsigned char c;
// char cc;
while (yyis->good()) {
char cc;
yyis->get(cc);
c = cc;
unsigned char c = cc;
if (c > ' ') {
if (!lf)
lf = c;
@ -196,7 +205,9 @@ char LexGetArg(char lf, bool accept_spaces= false)
}
}
char const rg =
(lf == '{') ? '}' : ((lf == '[') ? ']' : ((lf == '(') ? ')' : 0));
(lf == '{') ? '}' :
((lf == '[') ? ']'
: ((lf == '(') ? ')' : 0));
if (!rg) {
lyxerr << "Math parse error: unknown bracket '"
<< lf << "'" << endl;
@ -205,12 +216,15 @@ char LexGetArg(char lf, bool accept_spaces= false)
char * p = &yytext[0];
int bcnt = 1;
do {
char cc;
yyis->get(cc);
c = cc;
unsigned char c = cc;
if (c == lf) ++bcnt;
if (c == rg) --bcnt;
if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0) *(p++) = c;
if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0)
*(p++) = c;
} while (bcnt > 0 && yyis->good() && p - yytext.data() < 255);
*p = '\0';
return rg;
}
@ -232,50 +246,37 @@ int yylex(void)
if (yy_mtextmode && c == ' ') {
yylval.i= ' ';
return LM_TK_ALPHA;
} else
if (lexcode[c] == LexNewLine) {
} else if (lexcode[c] == LexNewLine) {
++yylineno;
continue;
} else
if (lexcode[c] == LexComment) {
} else if (lexcode[c] == LexComment) {
do {
yyis->get(cc);
c = cc;
} while (c != '\n' % yyis->good()); // eat comments
} else
if (lexcode[c] == LexDigit
} else if (lexcode[c] == LexDigit
|| lexcode[c] == LexOther
|| lexcode[c] == LexMathSpace) {
yylval.i = c;
return LM_TK_STR;
} else
if (lexcode[c] == LexAlpha) {
} else if (lexcode[c] == LexAlpha) {
yylval.i= c;
return LM_TK_ALPHA;
} else
if (lexcode[c] == LexBOP) {
} else if (lexcode[c] == LexBOP) {
yylval.i= c;
return LM_TK_BOP;
} else
if (lexcode[c] == LexSelf) {
} else if (lexcode[c] == LexSelf) {
return c;
} else
if (lexcode[c] == LexArgument) {
} else if (lexcode[c] == LexArgument) {
yyis->get(cc);
c = cc;
yylval.i = c - '0';
return LM_TK_ARGUMENT;
} else
if (lexcode[c] == LexOpen) {
} else if (lexcode[c] == LexOpen) {
return LM_TK_OPEN;
} else
if (lexcode[c] == LexClose) {
} else if (lexcode[c] == LexClose) {
return LM_TK_CLOSE;
} else
if (lexcode[c] == LexESC) {
} else if (lexcode[c] == LexESC) {
yyis->get(cc);
c = cc;
if (c == '\\') {
@ -326,11 +327,11 @@ int yylex(void)
// for (i = 0; i < 5 && compare(yytext, latex_mathenv[i],
// strlen(latex_mathenv[i])); ++i);
for (i = 0; i < latex_mathenv_num
for (i = 0;
i < latex_mathenv_num
&& compare(yytext.data(), latex_mathenv[i]); ++i);
yylval.i = i;
} else
if (l->token == LM_TK_SPACE)
} else if (l->token == LM_TK_SPACE)
yylval.i = l->id;
else
yylval.l = l;
@ -346,7 +347,7 @@ int yylex(void)
}
static
static inline
int parse_align(char * hor, char *)
{
int nc = 0;
@ -361,7 +362,7 @@ int accent = 0;
static
int nestaccent[8];
static
static inline
void setAccent(int ac)
{
if (ac > 0 && accent < 8) {
@ -405,6 +406,8 @@ MathedInset * doAccent(MathedInset * p)
}
/**
*/
void mathed_parse(MathedArray & array, unsigned flags = 0,
MathParInset ** mtx = 0)
{
@ -420,7 +423,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
int brace = 0;
int acc_brace = 0;
int acc_braces[8];
MathParInset * mt = (mtx) ? *mtx : 0;//(MathParInset*)0;
MathParInset * mt = (mtx) ? *mtx : 0;
MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
++plevel;
@ -428,8 +431,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
while (t) {
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
if ((flags & FLAG_BRACK_ARG) && t == '[') {
}
else {
} else {
mathPrintError("Expected {. Maybe you forgot to enclose an argument in {}");
panic = true;
break;
@ -437,21 +439,26 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
}
MathedInsetTypes fractype = LM_OT_FRAC;
switch (t) {
case LM_TK_ALPHA:
{
if (accent) {
data.insertInset(doAccent(yylval.i, varcode), LM_TC_INSET);
data.insertInset(doAccent(yylval.i, varcode),
LM_TC_INSET);
} else
data.insert(yylval.i, varcode); //LM_TC_VAR);
break;
}
case LM_TK_ARGUMENT:
{
if (macro) {
data.insertInset(macro->getMacroPar(yylval.i-1), LM_TC_INSET);
data.insertInset(macro
->getMacroPar(yylval.i - 1),
LM_TC_INSET);
} else {
lyxerr[Debug::MATHED] << "mathed_parse: macro arg outside macro def." << endl;
}
break;
}
case LM_TK_NEWCOMMAND:
{
int na = 0;
@ -467,25 +474,24 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
}
macro = new MathMacroTemplate(name, na);
flags = FLAG_BRACE|FLAG_BRACE_LAST;
*mtx = macro;
macro->setData(array);
break;
}
case LM_TK_SPECIAL:
{
data.insert(yylval.i, LM_TC_SPECIAL);
break;
}
case LM_TK_STR:
{
if (accent) {
data.insertInset(doAccent(yylval.i, LM_TC_CONST), LM_TC_INSET);
} else
data.insert(yylval.i, LM_TC_CONST);
break;
}
case LM_TK_OPEN:
{
++brace;
if (accent && tprev == LM_TK_ACCENT) {
acc_braces[acc_brace++] = brace;
@ -502,9 +508,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insert('{', LM_TC_TEX);
}
break;
}
case LM_TK_CLOSE:
{
--brace;
if (brace < 0) {
mathPrintError("Unmatching braces");
@ -528,10 +533,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insert('}', LM_TC_TEX);
}
break;
}
case '[':
{
if (flags & FLAG_BRACK_ARG) {
flags &= ~FLAG_BRACK_ARG;
char const rg = LexGetArg('[');
@ -544,20 +547,19 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
} else
data.insert('[', LM_TC_CONST);
break;
}
case ']':
{
if (flags & FLAG_BRACK_END) {
--plevel;
return;
} else
data.insert(']', LM_TC_CONST);
break;
}
case '^':
{
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
MathParInset * p = new MathParInset(size, "",
LM_OT_SCRIPT);
MathedArray ar;
mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar);
@ -565,9 +567,11 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insertInset(p, LM_TC_UP);
break;
}
case '_':
{
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
MathParInset * p = new MathParInset(size, "",
LM_OT_SCRIPT);
MathedArray ar;
mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar);
@ -576,28 +580,26 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
}
case LM_TK_LIMIT:
{
if (binset) {
binset->SetLimits(bool(yylval.l->id));
binset = 0;
}
break;
}
case '&': // Tab
{
if ((flags & FLAG_END) && mt && data.getCol()<mt->GetColumns() - 1) {
if ((flags & FLAG_END) && mt
&& data.getCol()<mt->GetColumns() - 1) {
data.setNumCols(mt->GetColumns());
data.insert('T', LM_TC_TAB);
} else
mathPrintError("Unexpected tab");
// debug info. [made that conditional -JMarc]
if (lyxerr.debugging(Debug::MATHED))
lyxerr << data.getCol() << " " << mt->GetColumns() << endl;
lyxerr << data.getCol() << " "
<< mt->GetColumns() << endl;
break;
}
case LM_TK_NEWLINE:
{
if (mt && (flags & FLAG_END)) {
if (mt->Permit(LMPF_ALLOW_CR)) {
if (crow) {
@ -609,15 +611,15 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
mathPrintError("Unexpected newline");
}
break;
}
case LM_TK_BIGSYM:
{
binset = new MathBigopInset(yylval.l->name, yylval.l->id);
data.insertInset(binset, LM_TC_INSET);
break;
}
case LM_TK_SYM:
{
if (yylval.l->id < 256) {
MathedTextCodes tc = MathIsBOPS(yylval.l->id) ? LM_TC_BOPS: LM_TC_SYMB;
if (accent) {
@ -636,38 +638,37 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
}
break;
}
case LM_TK_BOP:
{
if (accent) {
data.insertInset(doAccent(yylval.i, LM_TC_BOP), LM_TC_INSET);
} else
data.insert(yylval.i, LM_TC_BOP);
break;
}
case LM_TK_STY:
{
if (mt) {
mt->UserSetSize(yylval.l->id);
}
break;
}
case LM_TK_SPACE:
{
if (yylval.i >= 0) {
MathSpaceInset * sp = new MathSpaceInset(yylval.i);
data.insertInset(sp, LM_TC_INSET);
}
break;
}
case LM_TK_DOTS:
{
MathDotsInset * p = new MathDotsInset(yylval.l->name, yylval.l->id);
data.insertInset(p, LM_TC_INSET);
break;
}
case LM_TK_STACK:
fractype = LM_OT_STACKREL;
// fallthru
case LM_TK_FRAC:
{
MathFracInset * fc = new MathFracInset(fractype);
@ -679,11 +680,13 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insertInset(fc, LM_TC_ACTIVE_INSET);
break;
}
case LM_TK_SQRT:
{
MathParInset * rt;
char c; yyis->get(c);
char c;
yyis->get(c);
if (c == '[') {
rt = new MathRootInset(size);
@ -721,8 +724,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
// lyxerr << "RL[" << lfd << " " << rgd << "]";
break;
}
case LM_TK_RIGHT:
{
if (flags & FLAG_RIGHT) {
--plevel;
return;
@ -731,15 +734,13 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
// panic = true;
}
break;
}
case LM_TK_FONT:
{
varcode = static_cast<MathedTextCodes>(yylval.l->id);
yy_mtextmode = bool(varcode == LM_TC_TEXTRM);
flags |= (FLAG_BRACE|FLAG_BRACE_FONT);
break;
}
case LM_TK_WIDE:
{
MathDecorationInset * sq = new MathDecorationInset(yylval.l->id,
@ -756,11 +757,9 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
break;
case LM_TK_NONUM:
{
if (crow)
crow->setNumbered(false);
break;
}
case LM_TK_PMOD:
case LM_TK_FUNC:
@ -774,12 +773,12 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
data.insertInset(bg, LM_TC_INSET);
break;
}
case LM_TK_FUNCLIM:
{
data.insertInset(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM),
LM_TC_INSET);
break;
}
case LM_TK_UNDEF:
{
@ -795,8 +794,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST);
p->setData(ar);
}
}
else {
} else {
MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF);
if (accent) {
data.insertInset(doAccent(q), LM_TC_INSET);
@ -806,8 +804,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
}
break;
}
case LM_TK_END:
{
if (mathed_env != yylval.i && yylval.i != LM_OT_MATRIX)
mathPrintError("Unmatched environment");
// debug info [made that conditional -JMarc]
@ -819,11 +817,11 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
array.clear();
}
return;
}
case LM_TK_BEGIN:
{
if (yylval.i == LM_OT_MATRIX) {
char ar[120], ar2[8];
char ar[120];
char ar2[8];
ar[0] = ar2[0] = '\0';
char rg = LexGetArg(0);
if (rg == ']') {
@ -893,7 +891,6 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
mathPrintError("Unrecognized environment");
}
break;
}
case LM_TK_MACRO:
{
@ -929,12 +926,14 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
#endif
break;
}
default:
mathPrintError("Unrecognized token");
// debug info
lyxerr << "[" << t << " " << yytext.data() << "]" << endl;
break;
}
} // end of switch
tprev = t;
if (panic) {
lyxerr << " Math Panic, expect problems!" << endl;
@ -968,4 +967,3 @@ int mathed_parser_lineno()
{
return yylineno;
}

View File

@ -19,8 +19,8 @@
#pragma implementation
#endif
#include "math_iter.h"
#include "math_root.h"
#include "math_iter.h"
#include "support/LOstream.h"
using std::ostream;

View File

@ -15,13 +15,12 @@
#ifndef MATH_ROOT
#define MATH_ROOT
#ifdef __GNUG__
#pragma interface
#endif
#include "math_sqrtinset.h"
#include "symbol_def.h"
#ifdef __GNUG__
#pragma interface
#endif
/** The general n-th root inset.
\author Alejandro Aguilar Sierra

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_sqrtinset.h"
#include "math_iter.h"
#include "LColor.h"
@ -9,6 +13,7 @@
using std::ostream;
MathSqrtInset::MathSqrtInset(short st)
: MathParInset(st, "sqrt", LM_OT_SQRT) {}

View File

@ -1,9 +1,13 @@
// -*- C++ -*-
#ifndef MATH_SQRTINSET_H
#define MATH_SQRTINSET_H
#include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** The square root inset.
\author Alejandro Aguilar Siearra
*/