From 2be247f6ef5e35f27a41d92a88790357875c66bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 26 Feb 2001 12:53:35 +0000 Subject: [PATCH] fix macro, small cleanup git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1623 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 18 + src/mathed/formulamacro.C | 87 +- src/mathed/formulamacro.h | 16 +- src/mathed/math_decorationinset.C | 8 +- src/mathed/math_decorationinset.h | 7 +- src/mathed/math_defs.h | 2 +- src/mathed/math_deliminset.C | 6 +- src/mathed/math_deliminset.h | 4 + src/mathed/math_fracinset.C | 6 +- src/mathed/math_fracinset.h | 4 + src/mathed/math_macro.C | 5 - src/mathed/math_macro.h | 2 - src/mathed/math_macroarg.C | 10 +- src/mathed/math_macroarg.h | 52 +- src/mathed/math_macrotemplate.C | 44 +- src/mathed/math_macrotemplate.h | 16 +- src/mathed/math_matrixinset.C | 8 +- src/mathed/math_matrixinset.h | 8 +- src/mathed/math_parser.C | 1518 ++++++++++++++--------------- src/mathed/math_root.C | 2 +- src/mathed/math_root.h | 7 +- src/mathed/math_sqrtinset.C | 5 + src/mathed/math_sqrtinset.h | 6 +- 23 files changed, 957 insertions(+), 884 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 10def87a3c..42d1610769 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,21 @@ +2001-02-26 Lars Gullik Bjønnes + + * 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 * formula.C (LocalDispatch): changed action to be a kb_action (as it diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index beb0d59f66..6b993a6936 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -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; } @@ -100,16 +101,20 @@ int InsetFormulaMacro::DocBook(Buffer const * buf, ostream & os) const void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex) { istream & is = lex.getStream(); - mathed_parser_file(is, lex.GetLineNo()); + mathed_parser_file(is, lex.GetLineNo()); MathedArray ar; - mathed_parse(ar, 0, reinterpret_cast(&tmacro)); - + + mathed_parse(ar, 0, reinterpret_cast(&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(tmacro->Clone()); + opened_ = true; + par = static_cast(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; } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index c63419c6c5..8eab7cc3d2 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -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 diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 45bea19ae6..b4f1a0673a 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -1,5 +1,9 @@ #include +#ifdef __GNUG__ +#pragma implementation +#endif + #include "math_decorationinset.h" #include "math_iter.h" #include "mathed/support.h" @@ -39,8 +43,8 @@ MathDecorationInset::draw(Painter & pain, int x, int y) void MathDecorationInset::Metrics() { - int h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I', - ascent, descent); + int const h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I', + ascent, descent); MathParInset::Metrics(); int w = Width() + 4; if (w < 16) w = 16; diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index dec31955cc..4b1fec44b8 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -1,12 +1,17 @@ +// -*- 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 */ -class MathDecorationInset: public MathParInset { +class MathDecorationInset : public MathParInset { public: /// MathDecorationInset(int, short st = LM_ST_TEXT); diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index c207d821fa..d192c9fb2f 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -120,7 +120,7 @@ enum MathedTextCodes { LM_TC_MAX }; -/// +/// Defined in math_macro.C std::ostream & operator<<(std::ostream &, MathedTextCodes mtc); diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index 0b8e11977b..5db82838bf 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -1,5 +1,9 @@ #include +#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; - mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_); dh_ /= 2; ascent += 2 + dh_; diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index 540290e301..da7eee917d 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -4,6 +4,10 @@ #include "math_parinset.h" +#ifdef __GNUG__ +#pragma interface +#endif + /** A delimiter \author Alejandro Aguilar Sierra */ diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 4ea4fb9278..f38b009f90 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -1,5 +1,9 @@ #include +#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 diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index 1d51a41a06..621bf932fa 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -4,6 +4,10 @@ #include "math_parinset.h" +#ifdef __GNUG__ +#pragma interface +#endif + /** Fraction like objects (frac, stackrel, binom) \author Alejandro Aguilar Sierra */ diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 45b8e51255..1f292a88f7 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -75,11 +75,6 @@ MathMacro::MathMacro(MathMacro * m): } -MathMacro::~MathMacro() -{ -} - - MathedInset * MathMacro::Clone() { return new MathMacro(this); diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 3604468d58..beabf01eb1 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -41,8 +41,6 @@ public: explicit MathMacro(MathMacro *); /// - ~MathMacro(); - /// void draw(Painter &, int, int); /// void Metrics(); diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index b79589ef69..8767066074 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -1,5 +1,9 @@ #include +#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; diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index 678b7ba9a1..1129c2972a 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -4,36 +4,38 @@ #include "math_parinset.h" +#ifdef __GNUG__ +#pragma interface +#endif + /** A macro argument \author Alejandro Aguilar Sierra */ class MathMacroArgument: public MathParInset { public: - /// - MathMacroArgument(); - /// - explicit - MathMacroArgument(int); - /// - ~MathMacroArgument(); - /// - MathedInset * Clone(); - /// - void Metrics(); - /// - void draw(Painter &, int x, int baseline); - /// - void Write(std::ostream &, bool fragile); - /// - void setNumber(int n); - /// Is expanded or not - void setExpand(bool e); - /// Is expanded or not - bool getExpand() const; + /// + MathMacroArgument(); + /// + explicit + MathMacroArgument(int); + /// + MathedInset * Clone(); + /// + void Metrics(); + /// + void draw(Painter &, int x, int baseline); + /// + void Write(std::ostream &, bool fragile); + /// + void setNumber(int n); + /// Is expanded or not + void setExpand(bool e); + /// Is expanded or not + bool getExpand() const; private: - /// - bool expnd_mode_; - /// - int number_; + /// + bool expnd_mode_; + /// + int number_; }; #endif diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 7f0589e666..d2579604ce 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -1,5 +1,9 @@ #include +#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) diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index 7fa1f4b2a4..9844ecce2d 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -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 diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 8ba729f5cc..9d344f0d9a 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -1,5 +1,9 @@ #include +#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_) diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h index 78603f1f8c..fd9e55262a 100644 --- a/src/mathed/math_matrixinset.h +++ b/src/mathed/math_matrixinset.h @@ -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); /// diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index e42dc599b0..6ad9268b4b 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -68,16 +68,17 @@ enum { /// union YYSTYPE { - /// - unsigned char c; - /// - char const * s; - /// - int i; - /// - latexkeys const * l; + /// + unsigned char c; + /// + char const * s; + /// + int i; + /// + latexkeys const * l; }; + static YYSTYPE yylval; @@ -85,48 +86,49 @@ YYSTYPE yylval; static MathedInsetTypes mathed_env = LM_OT_MIN; + string mathed_label; int const latex_mathenv_num = 12; char const * latex_mathenv[latex_mathenv_num] = { - "math", - "displaymath", - "equation", - "eqnarray*", - "eqnarray", - "align*", - "align", - "alignat*", - "alignat", - "multline*", - "multline", - "array" + "math", + "displaymath", + "equation", + "eqnarray*", + "eqnarray", + "align*", + "align", + "alignat*", + "alignat", + "multline*", + "multline", + "array" }; +char const * latex_special_chars = "#$%&_{}"; -char const * latex_special_chars = "#$%&_{}"; - // These are lexical codes, not semantic enum lexcode_enum { - LexNone, - LexESC, - LexAlpha, - LexDigit, - LexBOP, // Binary operators or relations - LexMathSpace, - LexOpen, - LexClose, - LexComment, - LexArgument, - LexSpace, - LexNewLine, - LexOther, - LexSelf + LexNone, + LexESC, + LexAlpha, + LexDigit, + LexBOP, // Binary operators or relations + LexMathSpace, + LexOpen, + LexClose, + LexComment, + LexArgument, + LexSpace, + LexNewLine, + LexOther, + LexSelf }; + static lexcode_enum lexcode[256]; #warning Replace with string //static char yytext[256]; @@ -134,8 +136,9 @@ static array yytext; 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: " @@ -146,212 +149,210 @@ void mathPrintError(string const & msg) 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; - } - - 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[';'] = LexMathSpace; - - lexcode['('] = lexcode[')'] = lexcode['|'] = lexcode['.'] = - lexcode['?'] = LexOther; - - lexcode['\''] = lexcode['@'] = LexAlpha; - - lexcode['['] = lexcode[']'] = lexcode['^'] = lexcode['_'] = - lexcode['&'] = LexSelf; - - lexcode['\\'] = LexESC; - lexcode['{'] = LexOpen; - lexcode['}'] = LexClose; + 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; + } + + 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[';'] = LexMathSpace; + + lexcode['('] = lexcode[')'] = lexcode['|'] = lexcode['.'] = + lexcode['?'] = LexOther; + + lexcode['\''] = lexcode['@'] = LexAlpha; + + lexcode['['] = lexcode[']'] = lexcode['^'] = lexcode['_'] = + lexcode['&'] = LexSelf; + + lexcode['\\'] = LexESC; + lexcode['{'] = LexOpen; + lexcode['}'] = LexClose; } static -char LexGetArg(char lf, bool accept_spaces= false) +char LexGetArg(char lf, bool accept_spaces = false) { - unsigned char c; - char cc; - while (yyis->good()) { - yyis->get(cc); - c = cc; - if (c > ' ') { - if (!lf) - lf = c; - else if (c != lf) { - lyxerr << "Math parse error: unexpected '" - << c << "'" << endl; - return '\0'; - } - break; - } - } - char const rg = - (lf == '{') ? '}' : ((lf == '[') ? ']' : ((lf == '(') ? ')' : 0)); - if (!rg) { - lyxerr << "Math parse error: unknown bracket '" - << lf << "'" << endl; - return '\0'; - } - char * p = &yytext[0]; - int bcnt = 1; - do { - yyis->get(cc); - c = cc; - if (c == lf) ++bcnt; - if (c == rg) --bcnt; - if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0) *(p++) = c; - } while (bcnt > 0 && yyis->good() && p - yytext.data() < 255); - *p = '\0'; - return rg; + // unsigned char c; + // char cc; + while (yyis->good()) { + char cc; + yyis->get(cc); + unsigned char c = cc; + if (c > ' ') { + if (!lf) + lf = c; + else if (c != lf) { + lyxerr << "Math parse error: unexpected '" + << c << "'" << endl; + return '\0'; + } + break; + } + } + char const rg = + (lf == '{') ? '}' : + ((lf == '[') ? ']' + : ((lf == '(') ? ')' : 0)); + if (!rg) { + lyxerr << "Math parse error: unknown bracket '" + << lf << "'" << endl; + return '\0'; + } + char * p = &yytext[0]; + int bcnt = 1; + do { + char cc; + yyis->get(cc); + unsigned char c = cc; + if (c == lf) ++bcnt; + if (c == rg) --bcnt; + if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0) + *(p++) = c; + } while (bcnt > 0 && yyis->good() && p - yytext.data() < 255); + + *p = '\0'; + return rg; } static int yylex(void) { - static int init_done = 0; - - if (!init_done) LexInitCodes(); - - unsigned char c; - char cc; - while (yyis->good()) { - yyis->get(cc); - c = cc; - - if (yy_mtextmode && c == ' ') { - yylval.i= ' '; - return LM_TK_ALPHA; - } else - - if (lexcode[c] == LexNewLine) { - ++yylineno; - continue; - } else - - if (lexcode[c] == LexComment) { - do { - yyis->get(cc); - c = cc; - } while (c != '\n' % yyis->good()); // eat comments - } else - - if (lexcode[c] == LexDigit - || lexcode[c] == LexOther - || lexcode[c] == LexMathSpace) { - yylval.i = c; - return LM_TK_STR; - } else - if (lexcode[c] == LexAlpha) { - yylval.i= c; - return LM_TK_ALPHA; - } else - if (lexcode[c] == LexBOP) { - yylval.i= c; - return LM_TK_BOP; - } else - if (lexcode[c] == LexSelf) { - return c; - } else - if (lexcode[c] == LexArgument) { - yyis->get(cc); - c = cc; - yylval.i = c - '0'; - return LM_TK_ARGUMENT; - } else - if (lexcode[c] == LexOpen) { - return LM_TK_OPEN; - } else - if (lexcode[c] == LexClose) { - return LM_TK_CLOSE; - } else - if (lexcode[c] == LexESC) { - yyis->get(cc); - c = cc; - if (c == '\\') { - return LM_TK_NEWLINE; - } - if (c == '(') { - yylval.i = LM_OT_MIN; - return LM_TK_BEGIN; - } - if (c == ')') { - yylval.i = LM_OT_MIN; - return LM_TK_END; - } - if (c == '[') { - yylval.i = LM_OT_PAR; - return LM_TK_BEGIN; - } - if (c == ']') { - yylval.i = LM_OT_PAR; - return LM_TK_END; - } - if (strchr(latex_special_chars, c)) { - yylval.i = c; - return LM_TK_SPECIAL; - } - if (lexcode[c] == LexMathSpace) { - int i; - for (i = 0; i < 4 && static_cast(c) != latex_mathspace[i][0]; ++i); - yylval.i = (i < 4) ? i : 0; - return LM_TK_SPACE; - } - if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) { - char * p = &yytext[0]; - while ((lexcode[c] == LexAlpha || lexcode[c] == LexDigit) - && p - yytext.data() < 255) { - *p = c; - yyis->get(cc); - c = cc; - ++p; - } - *p = '\0'; - if (yyis->good()) yyis->putback(c); - latexkeys const * l = in_word_set (yytext.data(), strlen(yytext.data())); - if (l) { - if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) { - int i; - LexGetArg('{'); + static int init_done = 0; + + if (!init_done) LexInitCodes(); + + unsigned char c; + char cc; + while (yyis->good()) { + yyis->get(cc); + c = cc; + + if (yy_mtextmode && c == ' ') { + yylval.i= ' '; + return LM_TK_ALPHA; + } else if (lexcode[c] == LexNewLine) { + ++yylineno; + continue; + } else if (lexcode[c] == LexComment) { + do { + yyis->get(cc); + c = cc; + } while (c != '\n' % yyis->good()); // eat comments + } else if (lexcode[c] == LexDigit + || lexcode[c] == LexOther + || lexcode[c] == LexMathSpace) { + yylval.i = c; + return LM_TK_STR; + } else if (lexcode[c] == LexAlpha) { + yylval.i= c; + return LM_TK_ALPHA; + } else if (lexcode[c] == LexBOP) { + yylval.i= c; + return LM_TK_BOP; + } else if (lexcode[c] == LexSelf) { + return c; + } else if (lexcode[c] == LexArgument) { + yyis->get(cc); + c = cc; + yylval.i = c - '0'; + return LM_TK_ARGUMENT; + } else if (lexcode[c] == LexOpen) { + return LM_TK_OPEN; + } else if (lexcode[c] == LexClose) { + return LM_TK_CLOSE; + } else if (lexcode[c] == LexESC) { + yyis->get(cc); + c = cc; + if (c == '\\') { + return LM_TK_NEWLINE; + } + if (c == '(') { + yylval.i = LM_OT_MIN; + return LM_TK_BEGIN; + } + if (c == ')') { + yylval.i = LM_OT_MIN; + return LM_TK_END; + } + if (c == '[') { + yylval.i = LM_OT_PAR; + return LM_TK_BEGIN; + } + if (c == ']') { + yylval.i = LM_OT_PAR; + return LM_TK_END; + } + if (strchr(latex_special_chars, c)) { + yylval.i = c; + return LM_TK_SPECIAL; + } + if (lexcode[c] == LexMathSpace) { + int i; + for (i = 0; i < 4 && static_cast(c) != latex_mathspace[i][0]; ++i); + yylval.i = (i < 4) ? i : 0; + return LM_TK_SPACE; + } + if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) { + char * p = &yytext[0]; + while ((lexcode[c] == LexAlpha || lexcode[c] == LexDigit) + && p - yytext.data() < 255) { + *p = c; + yyis->get(cc); + c = cc; + ++p; + } + *p = '\0'; + if (yyis->good()) yyis->putback(c); + latexkeys const * l = in_word_set (yytext.data(), strlen(yytext.data())); + if (l) { + if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) { + int i; + LexGetArg('{'); // for (i = 0; i < 5 && compare(yytext, latex_mathenv[i], // strlen(latex_mathenv[i])); ++i); - - for (i = 0; i < latex_mathenv_num - && compare(yytext.data(), latex_mathenv[i]); ++i); - yylval.i = i; - } else - if (l->token == LM_TK_SPACE) - yylval.i = l->id; - else - yylval.l = l; - return l->token; - } else { - yylval.s = yytext.data(); - return LM_TK_UNDEF; - } - } - } - } - return 0; + + for (i = 0; + i < latex_mathenv_num + && compare(yytext.data(), latex_mathenv[i]); ++i); + yylval.i = i; + } else if (l->token == LM_TK_SPACE) + yylval.i = l->id; + else + yylval.l = l; + return l->token; + } else { + yylval.s = yytext.data(); + return LM_TK_UNDEF; + } + } + } + } + return 0; } -static +static inline int parse_align(char * hor, char *) { - int nc = 0; - for (char * c = hor; c && *c > ' '; ++c) ++nc; - return nc; + int nc = 0; + for (char * c = hor; c && *c > ' '; ++c) ++nc; + return nc; } @@ -361,7 +362,7 @@ int accent = 0; static int nestaccent[8]; -static +static inline void setAccent(int ac) { if (ac > 0 && accent < 8) { @@ -405,567 +406,564 @@ MathedInset * doAccent(MathedInset * p) } +/** + */ void mathed_parse(MathedArray & array, unsigned flags = 0, MathParInset ** mtx = 0) { - int t = yylex(); - int tprev = 0; - bool panic = false; - static int plevel = -1; - static int size = LM_ST_TEXT; - MathedTextCodes varcode = LM_TC_VAR; - MathedInset * binset = 0; - static MathMacroTemplate * macro = 0; - - int brace = 0; - int acc_brace = 0; - int acc_braces[8]; - MathParInset * mt = (mtx) ? *mtx : 0;//(MathParInset*)0; - MathedRowSt * crow = (mt) ? mt->getRowSt() : 0; - - ++plevel; - MathedIter data(&array); - while (t) { - if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) { - if ((flags & FLAG_BRACK_ARG) && t == '[') { - } - else { - mathPrintError("Expected {. Maybe you forgot to enclose an argument in {}"); - panic = true; - break; - } - } - MathedInsetTypes fractype = LM_OT_FRAC; - switch (t) { - case LM_TK_ALPHA: - { - if (accent) { - 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); - } - break; - } - case LM_TK_NEWCOMMAND: - { - int na = 0; - - LexGetArg('{'); - string const name(&yytext[1]); - - // ugly trick to be removed soon (lyx3) - char const c = yyis->peek(); - if (c == '[') { - LexGetArg('['); - na = lyx::atoi(yytext.data()); - } - 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; - break; - } - if (flags & FLAG_BRACE_OPT) { - flags &= ~FLAG_BRACE_OPT; - flags |= FLAG_BRACE; - } - - if (flags & FLAG_BRACE) - flags &= ~FLAG_BRACE; - else { - data.insert('{', LM_TC_TEX); - } - break; - } - case LM_TK_CLOSE: - { - --brace; - if (brace < 0) { - mathPrintError("Unmatching braces"); - panic = true; - break; - } - if (acc_brace && brace == acc_braces[acc_brace-1]-1) { - --acc_brace; - break; - } - if (flags & FLAG_BRACE_FONT) { - varcode = LM_TC_VAR; - yy_mtextmode = false; - flags &= ~FLAG_BRACE_FONT; - break; - } - if (brace == 0 && (flags & FLAG_BRACE_LAST)) { - --plevel; - return; - } else { - data.insert('}', LM_TC_TEX); - } - break; - } - - case '[': - { - if (flags & FLAG_BRACK_ARG) { - flags &= ~FLAG_BRACK_ARG; - char const rg = LexGetArg('['); - if (rg != ']') { - mathPrintError("Expected ']'"); - panic = true; - break; - } -// if (arg) strcpy(arg, yytext); - } 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); - MathedArray ar; - mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST); - p->setData(ar); -// lyxerr << "UP[" << p->GetStyle() << "]" << endl; - data.insertInset(p, LM_TC_UP); - break; - } - case '_': - { - MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT); - MathedArray ar; - mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST); - p->setData(ar); - data.insertInset(p, LM_TC_DOWN); - break; - } - - case LM_TK_LIMIT: - { - if (binset) { - binset->SetLimits(bool(yylval.l->id)); - binset = 0; - } - break; - } - - case '&': // Tab - { - if ((flags & FLAG_END) && mt && data.getCol()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; - break; - } - case LM_TK_NEWLINE: - { - if (mt && (flags & FLAG_END)) { - if (mt->Permit(LMPF_ALLOW_CR)) { - if (crow) { - crow->setNext(new MathedRowSt(mt->GetColumns() + 1)); // this leaks - crow = crow->getNext(); - } - data.insert('K', LM_TC_CR); - } else - 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) { - data.insertInset(doAccent(yylval.l->id, tc), LM_TC_INSET); - } else - data.insert(yylval.l->id, tc); - } else { - MathFuncInset * bg = new MathFuncInset(yylval.l->name); - if (accent) { - data.insertInset(doAccent(bg), LM_TC_INSET); - } else { + int t = yylex(); + int tprev = 0; + bool panic = false; + static int plevel = -1; + static int size = LM_ST_TEXT; + MathedTextCodes varcode = LM_TC_VAR; + MathedInset * binset = 0; + static MathMacroTemplate * macro = 0; + + int brace = 0; + int acc_brace = 0; + int acc_braces[8]; + MathParInset * mt = (mtx) ? *mtx : 0; + MathedRowSt * crow = (mt) ? mt->getRowSt() : 0; + + ++plevel; + MathedIter data(&array); + while (t) { + if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) { + if ((flags & FLAG_BRACK_ARG) && t == '[') { + } else { + mathPrintError("Expected {. Maybe you forgot to enclose an argument in {}"); + panic = true; + break; + } + } + MathedInsetTypes fractype = LM_OT_FRAC; + switch (t) { + + case LM_TK_ALPHA: + if (accent) { + 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); + } else { + lyxerr[Debug::MATHED] << "mathed_parse: macro arg outside macro def." << endl; + } + + break; + + case LM_TK_NEWCOMMAND: + { + int na = 0; + + LexGetArg('{'); + string const name(&yytext[1]); + + // ugly trick to be removed soon (lyx3) + char const c = yyis->peek(); + if (c == '[') { + LexGetArg('['); + na = lyx::atoi(yytext.data()); + } + 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; + break; + } + if (flags & FLAG_BRACE_OPT) { + flags &= ~FLAG_BRACE_OPT; + flags |= FLAG_BRACE; + } + + if (flags & FLAG_BRACE) + flags &= ~FLAG_BRACE; + else { + data.insert('{', LM_TC_TEX); + } + break; + + case LM_TK_CLOSE: + --brace; + if (brace < 0) { + mathPrintError("Unmatching braces"); + panic = true; + break; + } + if (acc_brace && brace == acc_braces[acc_brace - 1] - 1) { + --acc_brace; + break; + } + if (flags & FLAG_BRACE_FONT) { + varcode = LM_TC_VAR; + yy_mtextmode = false; + flags &= ~FLAG_BRACE_FONT; + break; + } + if (brace == 0 && (flags & FLAG_BRACE_LAST)) { + --plevel; + return; + } else { + data.insert('}', LM_TC_TEX); + } + break; + + case '[': + if (flags & FLAG_BRACK_ARG) { + flags &= ~FLAG_BRACK_ARG; + char const rg = LexGetArg('['); + if (rg != ']') { + mathPrintError("Expected ']'"); + panic = true; + break; + } + // if (arg) strcpy(arg, yytext); + } 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); + MathedArray ar; + mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST); + p->setData(ar); + // lyxerr << "UP[" << p->GetStyle() << "]" << endl; + data.insertInset(p, LM_TC_UP); + break; + } + + case '_': + { + MathParInset * p = new MathParInset(size, "", + LM_OT_SCRIPT); + MathedArray ar; + mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST); + p->setData(ar); + data.insertInset(p, LM_TC_DOWN); + break; + } + + case LM_TK_LIMIT: + if (binset) { + binset->SetLimits(bool(yylval.l->id)); + binset = 0; + } + break; + + case '&': // Tab + if ((flags & FLAG_END) && mt + && data.getCol()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; + break; + + case LM_TK_NEWLINE: + if (mt && (flags & FLAG_END)) { + if (mt->Permit(LMPF_ALLOW_CR)) { + if (crow) { + crow->setNext(new MathedRowSt(mt->GetColumns() + 1)); // this leaks + crow = crow->getNext(); + } + data.insert('K', LM_TC_CR); + } else + 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) { + data.insertInset(doAccent(yylval.l->id, tc), LM_TC_INSET); + } else + data.insert(yylval.l->id, tc); + } else { + MathFuncInset * bg = new MathFuncInset(yylval.l->name); + if (accent) { + data.insertInset(doAccent(bg), LM_TC_INSET); + } else { #warning This is suspisious! (Lgb) - // it should not take a bool as second arg (Lgb) - data.insertInset(bg, true); - } - - } - 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; - case LM_TK_FRAC: - { - MathFracInset * fc = new MathFracInset(fractype); - MathedArray num; - mathed_parse(num, FLAG_BRACE|FLAG_BRACE_LAST); - MathedArray den; - mathed_parse(den, FLAG_BRACE|FLAG_BRACE_LAST); - fc->SetData(num, den); - data.insertInset(fc, LM_TC_ACTIVE_INSET); - break; - } - case LM_TK_SQRT: - { - MathParInset * rt; - - char c; yyis->get(c); - - if (c == '[') { - rt = new MathRootInset(size); - rt->setArgumentIdx(0); - MathedArray ar; - mathed_parse(ar, FLAG_BRACK_END, &rt); - rt->setData(ar); - rt->setArgumentIdx(1); - } else { - yyis->putback(c); - rt = new MathSqrtInset(size); - } - MathedArray ar; - mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST, &rt); - rt->setData(ar); - data.insertInset(rt, LM_TC_ACTIVE_INSET); - break; - } - - case LM_TK_LEFT: - { - int lfd = yylex(); - if (lfd == LM_TK_SYM || lfd == LM_TK_STR || lfd == LM_TK_BOP|| lfd == LM_TK_SPECIAL) - lfd = (lfd == LM_TK_SYM) ? yylval.l->id: yylval.i; + // it should not take a bool as second arg (Lgb) + data.insertInset(bg, true); + } + + } + 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); + MathedArray num; + mathed_parse(num, FLAG_BRACE|FLAG_BRACE_LAST); + MathedArray den; + mathed_parse(den, FLAG_BRACE|FLAG_BRACE_LAST); + fc->SetData(num, den); + data.insertInset(fc, LM_TC_ACTIVE_INSET); + break; + } + + case LM_TK_SQRT: + { + MathParInset * rt; + + char c; + yyis->get(c); + + if (c == '[') { + rt = new MathRootInset(size); + rt->setArgumentIdx(0); + MathedArray ar; + mathed_parse(ar, FLAG_BRACK_END, &rt); + rt->setData(ar); + rt->setArgumentIdx(1); + } else { + yyis->putback(c); + rt = new MathSqrtInset(size); + } + MathedArray ar; + mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST, &rt); + rt->setData(ar); + data.insertInset(rt, LM_TC_ACTIVE_INSET); + break; + } + + case LM_TK_LEFT: + { + int lfd = yylex(); + if (lfd == LM_TK_SYM || lfd == LM_TK_STR || lfd == LM_TK_BOP|| lfd == LM_TK_SPECIAL) + lfd = (lfd == LM_TK_SYM) ? yylval.l->id: yylval.i; // lyxerr << "L[" << lfd << " " << lfd << "]"; - MathedArray ar; - mathed_parse(ar, FLAG_RIGHT); - int rgd = yylex(); + MathedArray ar; + mathed_parse(ar, FLAG_RIGHT); + int rgd = yylex(); // lyxerr << "R[" << rgd << "]"; - if (rgd == LM_TK_SYM || rgd == LM_TK_STR || rgd == LM_TK_BOP || rgd == LM_TK_SPECIAL) - rgd = (rgd == LM_TK_SYM) ? yylval.l->id: yylval.i; - MathDelimInset * dl = new MathDelimInset(lfd, rgd); - dl->setData(ar); - data.insertInset(dl, LM_TC_ACTIVE_INSET); + if (rgd == LM_TK_SYM || rgd == LM_TK_STR || rgd == LM_TK_BOP || rgd == LM_TK_SPECIAL) + rgd = (rgd == LM_TK_SYM) ? yylval.l->id: yylval.i; + MathDelimInset * dl = new MathDelimInset(lfd, rgd); + dl->setData(ar); + data.insertInset(dl, LM_TC_ACTIVE_INSET); // lyxerr << "RL[" << lfd << " " << rgd << "]"; - break; - } - case LM_TK_RIGHT: - { - if (flags & FLAG_RIGHT) { - --plevel; - return; - } else { - mathPrintError("Unmatched right delimiter"); + break; + } + + case LM_TK_RIGHT: + if (flags & FLAG_RIGHT) { + --plevel; + return; + } else { + mathPrintError("Unmatched right delimiter"); // panic = true; - } - break; - } - - case LM_TK_FONT: - { - varcode = static_cast(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, - size); - MathedArray ar; - mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST); - sq->setData(ar); - data.insertInset(sq, LM_TC_ACTIVE_INSET); - break; - } - - case LM_TK_ACCENT: - setAccent(yylval.l->id); - break; - - case LM_TK_NONUM: - { - if (crow) - crow->setNumbered(false); - break; - } - - case LM_TK_PMOD: - case LM_TK_FUNC: - { + } + break; + + case LM_TK_FONT: + varcode = static_cast(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, + size); + MathedArray ar; + mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST); + sq->setData(ar); + data.insertInset(sq, LM_TC_ACTIVE_INSET); + break; + } + + case LM_TK_ACCENT: + setAccent(yylval.l->id); + break; + + case LM_TK_NONUM: + if (crow) + crow->setNumbered(false); + break; + + case LM_TK_PMOD: + case LM_TK_FUNC: + { #warning This must leak. (Lgb) - // if (accent) this must leak... (Lgb) - MathedInset * bg = new MathFuncInset(yylval.l->name); - if (accent) { - data.insert(t, LM_TC_CONST); - } else - 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: - { - - MathMacro * p = - MathMacroTable::mathMTable.getMacro(yylval.s); - if (p) { - if (accent) - data.insertInset(doAccent(p), p->getTCode()); - else - data.insertInset(p, p->getTCode()); - for (int i = 0; p->setArgumentIdx(i); ++i) { - MathedArray ar; - mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST); - p->setData(ar); + // if (accent) this must leak... (Lgb) + MathedInset * bg = new MathFuncInset(yylval.l->name); + if (accent) { + data.insert(t, LM_TC_CONST); + } else + 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: + { + + MathMacro * p = + MathMacroTable::mathMTable.getMacro(yylval.s); + if (p) { + if (accent) + data.insertInset(doAccent(p), p->getTCode()); + else + data.insertInset(p, p->getTCode()); + for (int i = 0; p->setArgumentIdx(i); ++i) { + MathedArray ar; + mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST); + p->setData(ar); + } + } else { + MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF); + if (accent) { + data.insertInset(doAccent(q), LM_TC_INSET); + } else { + data.insertInset(q, LM_TC_INSET); + } } - } - else { - MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF); - if (accent) { - data.insertInset(doAccent(q), LM_TC_INSET); - } else { - data.insertInset(q, LM_TC_INSET); - } - } - break; - } - case LM_TK_END: - { - if (mathed_env != yylval.i && yylval.i != LM_OT_MATRIX) - mathPrintError("Unmatched environment"); - // debug info [made that conditional -JMarc] - if (lyxerr.debugging(Debug::MATHED)) - lyxerr << "[" << yylval.i << "]" << endl; - --plevel; - if (mt) { // && (flags & FLAG_END)) { - mt->setData(array); - array.clear(); - } - return; - } - case LM_TK_BEGIN: - { - if (yylval.i == LM_OT_MATRIX) { - char ar[120], ar2[8]; - ar[0] = ar2[0] = '\0'; - char rg = LexGetArg(0); - if (rg == ']') { - strcpy(ar2, yytext.data()); - rg = LexGetArg('{'); - } - strcpy(ar, yytext.data()); - int const nc = parse_align(ar, ar2); - MathParInset * mm = new MathMatrixInset(nc, 0); - mm->SetAlign(ar2[0], ar); - data.insertInset(mm, LM_TC_ACTIVE_INSET); - mathed_parse(mm->GetData(), FLAG_END, &mm); - } else if (is_eqn_type(yylval.i)) { - if (plevel!= 0) { - mathPrintError("Misplaced environment"); - break; - } - if (!mt) { - mathPrintError("0 paragraph."); - panic = true; - } - - mathed_env = static_cast(yylval.i); - if (mathed_env != LM_OT_MIN) { - size = LM_ST_DISPLAY; - if (is_multiline(mathed_env)) { - int cols = 1; - if (is_multicolumn(mathed_env)) { - if (mathed_env != LM_OT_ALIGNAT && - mathed_env != LM_OT_ALIGNATN && - yyis->good()) { - char c; - yyis->get(c); - if (c != '%') - lyxerr << "Math parse error: unexpected '" - << c << "'" << endl; - } - LexGetArg('{'); - cols = strToInt(string(yytext.data())); - } - mt = create_multiline(mathed_env, cols); - if (mtx) *mtx = mt; - flags |= FLAG_END; + break; + } + + case LM_TK_END: + if (mathed_env != yylval.i && yylval.i != LM_OT_MATRIX) + mathPrintError("Unmatched environment"); + // debug info [made that conditional -JMarc] + if (lyxerr.debugging(Debug::MATHED)) + lyxerr << "[" << yylval.i << "]" << endl; + --plevel; + if (mt) { // && (flags & FLAG_END)) { + mt->setData(array); + array.clear(); + } + return; + + case LM_TK_BEGIN: + if (yylval.i == LM_OT_MATRIX) { + char ar[120]; + char ar2[8]; + ar[0] = ar2[0] = '\0'; + char rg = LexGetArg(0); + if (rg == ']') { + strcpy(ar2, yytext.data()); + rg = LexGetArg('{'); + } + strcpy(ar, yytext.data()); + int const nc = parse_align(ar, ar2); + MathParInset * mm = new MathMatrixInset(nc, 0); + mm->SetAlign(ar2[0], ar); + data.insertInset(mm, LM_TC_ACTIVE_INSET); + mathed_parse(mm->GetData(), FLAG_END, &mm); + } else if (is_eqn_type(yylval.i)) { + if (plevel!= 0) { + mathPrintError("Misplaced environment"); + break; + } + if (!mt) { + mathPrintError("0 paragraph."); + panic = true; + } + + mathed_env = static_cast(yylval.i); + if (mathed_env != LM_OT_MIN) { + size = LM_ST_DISPLAY; + if (is_multiline(mathed_env)) { + int cols = 1; + if (is_multicolumn(mathed_env)) { + if (mathed_env != LM_OT_ALIGNAT && + mathed_env != LM_OT_ALIGNATN && + yyis->good()) { + char c; + yyis->get(c); + if (c != '%') + lyxerr << "Math parse error: unexpected '" + << c << "'" << endl; + } + LexGetArg('{'); + cols = strToInt(string(yytext.data())); + } + mt = create_multiline(mathed_env, cols); + if (mtx) *mtx = mt; + flags |= FLAG_END; // data.Insert(' ', LM_TC_TAB); // data.Insert(' ', LM_TC_TAB); // data.Reset(); - } - mt->SetStyle(size); - mt->SetType(mathed_env); - crow = mt->getRowSt(); - } - + } + mt->SetStyle(size); + mt->SetType(mathed_env); + crow = mt->getRowSt(); + } + #ifdef DEBUG - lyxerr << "MATH BEGIN[" << mathed_env << "]" << endl; + lyxerr << "MATH BEGIN[" << mathed_env << "]" << endl; #endif - } else { + } else { // lyxerr << "MATHCRO[" << yytext << "]"; - MathMacro * p = - MathMacroTable::mathMTable.getMacro(yytext.data()); - if (p) { - data.insertInset(p, p->getTCode()); - p->setArgumentIdx(0); - mathed_parse(p->GetData(), FLAG_END, reinterpret_cast(&p)); + MathMacro * p = + MathMacroTable::mathMTable.getMacro(yytext.data()); + if (p) { + data.insertInset(p, p->getTCode()); + p->setArgumentIdx(0); + mathed_parse(p->GetData(), FLAG_END, reinterpret_cast(&p)); // for (int i = 0; p->setArgumentIdx(i); ++i) // p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST)); - } else - mathPrintError("Unrecognized environment"); - } - break; - } - - case LM_TK_MACRO: - { - MathedInset * p = - MathMacroTable::mathMTable.getMacro(yylval.l->name); - - if (p) { - if (accent) { - data.insertInset(doAccent(p), LM_TC_INSET); - } else - data.insertInset(p, static_cast(p)->getTCode()); - } - break; - } - - case LM_TK_LABEL: - { - char const rg = LexGetArg('\0', true); - if (rg != '}') { - mathPrintError("Expected '{'"); - // debug info - lyxerr << "[" << yytext.data() << "]" << endl; - panic = true; - break; - } - if (crow) { - crow->setLabel(yytext.data()); - } else { - mathed_label = yytext.data(); - } + } else + mathPrintError("Unrecognized environment"); + } + break; + + case LM_TK_MACRO: + { + MathedInset * p = + MathMacroTable::mathMTable.getMacro(yylval.l->name); + + if (p) { + if (accent) { + data.insertInset(doAccent(p), LM_TC_INSET); + } else + data.insertInset(p, static_cast(p)->getTCode()); + } + break; + } + + case LM_TK_LABEL: + { + char const rg = LexGetArg('\0', true); + if (rg != '}') { + mathPrintError("Expected '{'"); + // debug info + lyxerr << "[" << yytext.data() << "]" << endl; + panic = true; + break; + } + if (crow) { + crow->setLabel(yytext.data()); + } else { + mathed_label = yytext.data(); + } #ifdef DEBUG - lyxerr << "Label[" << mathed_label << "]" << endl; + lyxerr << "Label[" << mathed_label << "]" << endl; #endif - break; - } - default: - mathPrintError("Unrecognized token"); - // debug info - lyxerr << "[" << t << " " << yytext.data() << "]" << endl; - break; - } - tprev = t; - if (panic) { - lyxerr << " Math Panic, expect problems!" << endl; - // Search for the end command. - do { - t = yylex (); - } while (t != LM_TK_END && t); - } else - t = yylex (); - - if ((flags & FLAG_BRACE_OPT)/* && t!= '^' && t!= '_'*/) { - flags &= ~FLAG_BRACE_OPT; - //data.Insert (LM_TC_CLOSE); - break; - } - } - --plevel; + 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; + // Search for the end command. + do { + t = yylex (); + } while (t != LM_TK_END && t); + } else + t = yylex (); + + if ((flags & FLAG_BRACE_OPT)/* && t!= '^' && t!= '_'*/) { + flags &= ~FLAG_BRACE_OPT; + //data.Insert (LM_TC_CLOSE); + break; + } + } + --plevel; } void mathed_parser_file(istream & is, int lineno) { - yyis = &is; - yylineno = lineno; - if (!MathMacroTable::built) - MathMacroTable::mathMTable.builtinMacros(); + yyis = &is; + yylineno = lineno; + if (!MathMacroTable::built) + MathMacroTable::mathMTable.builtinMacros(); } int mathed_parser_lineno() { - return yylineno; + return yylineno; } - diff --git a/src/mathed/math_root.C b/src/mathed/math_root.C index 4414c57d56..96583fd590 100644 --- a/src/mathed/math_root.C +++ b/src/mathed/math_root.C @@ -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; diff --git a/src/mathed/math_root.h b/src/mathed/math_root.h index 02c856911b..474c81c363 100644 --- a/src/mathed/math_root.h +++ b/src/mathed/math_root.h @@ -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 diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index a8c5cad14d..0d868c63a6 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -1,5 +1,9 @@ #include +#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) {} diff --git a/src/mathed/math_sqrtinset.h b/src/mathed/math_sqrtinset.h index 5c73159ae8..8ab0f2a87f 100644 --- a/src/mathed/math_sqrtinset.h +++ b/src/mathed/math_sqrtinset.h @@ -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 */ -- 2.39.2