From ece9f3739ca93eb6621788fae3715d464ec0f08e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 26 Jul 2001 16:14:23 +0000 Subject: [PATCH] nest step... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2362 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 24 ++++++++++----------- src/mathed/math_cursor.C | 12 +++++++---- src/mathed/math_cursor.h | 2 +- src/mathed/math_decorationinset.C | 27 ++++++++++++----------- src/mathed/math_decorationinset.h | 7 ++++-- src/mathed/math_dotsinset.C | 21 +++++++++--------- src/mathed/math_dotsinset.h | 8 ++++--- src/mathed/math_macrotable.C | 36 ++++++++++++++++++++----------- src/mathed/math_macrotable.h | 2 ++ src/mathed/math_parser.C | 25 ++++++++++++++------- 10 files changed, 99 insertions(+), 65 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 21d1696ec2..8ae66c7cb7 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -76,10 +76,10 @@ void handleFont(BufferView * bv, MathTextCodes t) mathcursor->handleFont(t); } -void handleAccent(BufferView * bv, string const & name, int code) +void handleAccent(BufferView * bv, string const & name) { bv->lockedInsetStoreUndo(Undo::EDIT); - mathcursor->handleAccent(name, code); + mathcursor->handleAccent(name); } void handleDelim(BufferView * bv, int l, int r) @@ -533,16 +533,16 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, // --- accented characters ------------------------------ - case LFUN_UMLAUT: handleAccent(bv, "ddot", LM_ddot); break; - case LFUN_CIRCUMFLEX: handleAccent(bv, "hat", LM_hat); break; - case LFUN_GRAVE: handleAccent(bv, "grave", LM_grave); break; - case LFUN_ACUTE: handleAccent(bv, "acute", LM_acute); break; - case LFUN_TILDE: handleAccent(bv, "tilde", LM_tilde); break; - case LFUN_MACRON: handleAccent(bv, "bar", LM_bar); break; - case LFUN_DOT: handleAccent(bv, "dot", LM_dot); break; - case LFUN_CARON: handleAccent(bv, "check", LM_check); break; - case LFUN_BREVE: handleAccent(bv, "breve", LM_breve); break; - case LFUN_VECTOR: handleAccent(bv, "vec", LM_vec); break; + case LFUN_UMLAUT: handleAccent(bv, "ddot"); break; + case LFUN_CIRCUMFLEX: handleAccent(bv, "hat"); break; + case LFUN_GRAVE: handleAccent(bv, "grave"); break; + case LFUN_ACUTE: handleAccent(bv, "acute"); break; + case LFUN_TILDE: handleAccent(bv, "tilde"); break; + case LFUN_MACRON: handleAccent(bv, "bar"); break; + case LFUN_DOT: handleAccent(bv, "dot"); break; + case LFUN_CARON: handleAccent(bv, "check"); break; + case LFUN_BREVE: handleAccent(bv, "breve"); break; + case LFUN_VECTOR: handleAccent(bv, "vec"); break; // Greek mode case LFUN_GREEK: diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 4ffe77a4f2..cfebdbaf5f 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -684,7 +684,7 @@ void MathCursor::interpret(string const & s) break; case LM_TK_DECORATION: - p = new MathDecorationInset(l->name, l->id); + p = new MathDecorationInset(l); break; case LM_TK_SPACE: @@ -692,7 +692,7 @@ void MathCursor::interpret(string const & s) break; case LM_TK_DOTS: - p = new MathDotsInset(l->name, l->id); + p = new MathDotsInset(l); break; case LM_TK_MACRO: @@ -862,9 +862,13 @@ void MathCursor::handleFont(MathTextCodes t) } -void MathCursor::handleAccent(string const & name, int code) +void MathCursor::handleAccent(string const & name) { - MathDecorationInset * p = new MathDecorationInset(name, code); + latexkeys const * l = in_word_set(name); + if (!l) + return; + + MathDecorationInset * p = new MathDecorationInset(l); if (selection_) { selCut(); p->cell(0) = theSelection.glue(); diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 1d03668863..3372505d6a 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -156,7 +156,7 @@ public: /// void handleFont(MathTextCodes t); /// - void handleAccent(string const & name, int code); + void handleAccent(string const & name); /// void handleDelim(int l, int r); /// Splits cells and shifts right part to the next cell diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index e547aa52db..dd87a10ec5 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -11,10 +11,10 @@ using std::ostream; -MathDecorationInset::MathDecorationInset(string const & name, int d) - : MathInset(1, name), deco_(d) +MathDecorationInset::MathDecorationInset(latexkeys const * key) + : MathInset(1), key_(key) { - upper_ = deco_ != LM_underline && deco_ != LM_underbrace; + upper_ = key_->id != LM_underline && key_->id != LM_underbrace; } @@ -43,7 +43,7 @@ void MathDecorationInset::metrics(MathStyles st) descent_ += dh_ + 2; } - if (deco_ == LM_not) { + if (key_->id == LM_not) { ascent_ += dh_; descent_ += dh_; dh_ = height(); @@ -56,34 +56,35 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) xo(x); yo(x); xcell(0).draw(pain, x, y); - mathed_draw_deco(pain, x, y + dy_, width_, dh_, deco_); + mathed_draw_deco(pain, x, y + dy_, width_, dh_, key_->id); } void MathDecorationInset::write(ostream & os, bool fragile) const { + string name = key_->name; if (fragile && - (name_ == "overbrace" || - name_ == "underbrace" || - name_ == "overleftarrow" || - name_ == "overrightarrow")) + (name == "overbrace" || + name == "underbrace" || + name == "overleftarrow" || + name == "overrightarrow")) os << "\\protect"; - os << '\\' << name_; + os << '\\' << name; - if (deco_ == LM_not) + if (key_->id == LM_not) os << ' '; else os << '{'; cell(0).write(os, fragile); - if (deco_ != LM_not) + if (key_->id != LM_not) os << '}'; } void MathDecorationInset::writeNormal(ostream & os) const { - os << "[" << name_ << " "; + os << "[" << key_->name << " "; cell(0).writeNormal(os); os << "] "; } diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index d9bc683930..cf90fb1df9 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -11,10 +11,13 @@ /** Decorations and accents over (below) a math object \author Alejandro Aguilar Sierra */ + +struct latexkeys; + class MathDecorationInset : public MathInset { public: /// - MathDecorationInset(string const & name, int); + explicit MathDecorationInset(latexkeys const *); /// MathInset * clone() const; /// @@ -27,7 +30,7 @@ public: void writeNormal(std::ostream & os) const; private: /// - int deco_; + latexkeys const * key_; /// bool upper_; /// height of deco diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index 4466879a55..35cb293964 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -4,13 +4,14 @@ #include "math_dotsinset.h" #include "mathed/support.h" +#include "mathed/math_parser.h" #include "support/LOstream.h" using std::ostream; -MathDotsInset::MathDotsInset(string const & name, int id) - : MathInset(0, name), code_(id) +MathDotsInset::MathDotsInset(latexkeys const * key) + : key_(key) {} @@ -22,12 +23,12 @@ MathInset * MathDotsInset::clone() const void MathDotsInset::draw(Painter & pain, int x, int y) { - mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, code_); - if (code_ == LM_vdots || code_ == LM_ddots) + mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_->id); + if (key_->id == LM_vdots || key_->id == LM_ddots) ++x; - if (code_ != LM_vdots) + if (key_->id != LM_vdots) --y; - mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, code_); + mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_->id); } @@ -35,9 +36,9 @@ void MathDotsInset::metrics(MathStyles st) { size(st); mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_); - switch (code_) { + switch (key_->id) { case LM_ldots: dh_ = 0; break; - case LM_cdots: dh_ = ascent_/2; break; + case LM_cdots: dh_ = ascent_ / 2; break; case LM_vdots: width_ /= 2; case LM_ddots: dh_ = ascent_; break; } @@ -46,11 +47,11 @@ void MathDotsInset::metrics(MathStyles st) void MathDotsInset::write(ostream & os, bool /* fragile */) const { - os << '\\' << name() << ' '; + os << '\\' << key_->name << ' '; } void MathDotsInset::writeNormal(ostream & os) const { - os << "[" << name() << "] "; + os << "[" << key_->name << "] "; } diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index 9f0937a127..cf8fb21fce 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -9,13 +9,15 @@ #pragma interface #endif +struct latexkeys; + /// The different kinds of ellipsis class MathDotsInset : public MathInset { public: /// - MathDotsInset(string const &, int); + explicit MathDotsInset(latexkeys const *); /// - MathInset * clone() const; + MathInset * clone() const; /// void draw(Painter &, int, int); /// @@ -28,6 +30,6 @@ protected: /// int dh_; /// - int code_; + latexkeys const * key_; }; #endif diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index ab116755c4..c18456063f 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -20,6 +20,9 @@ using std::endl; +MathArray mathed_parse_cell(string const &); + + MathMacroTable::table_type MathMacroTable::macro_table; @@ -67,6 +70,15 @@ MathMacroTemplate & MathMacroTable::provideTemplate(string const & name) } +void MathMacroTable::createTemplate + (string const & name, int na, string const & text) +{ + MathMacroTemplate * t = new MathMacroTemplate(name, na); + t->cell(0) = mathed_parse_cell(text); + insertTemplate(t); +} + + bool MathMacroTable::hasTemplate(string const & name) { builtinMacros(); @@ -90,27 +102,25 @@ void MathMacroTable::builtinMacros() built = true; lyxerr[Debug::MATHED] << "Building macros" << endl; - + +/* // This macro doesn't have arguments { MathMacroTemplate * t = new MathMacroTemplate("notin", 0); - MathDecorationInset * p = new MathDecorationInset("not", LM_not); + MathDecorationInset * p = new MathDecorationInset("not"); p->cell(0).push_back(LM_in, LM_TC_SYMB); t->push_back(p); insertTemplate(t); } - -/* - // This macro doesn't have arguments - { - MathMacroTemplate & m = createTemplate("silentmult", 0); - istringstream is("\\cdot\0"); - mathed_parser_file(is, 0); - MathMatrixInset * p = &m; - mathed_parse(m.array, p, 0); - } */ + createTemplate("silentmult", 0, "\\cdot"); + createTemplate("emptyset", 0, "\\not0"); + createTemplate("notin", 0, "\\not\\in"); + + + +/* { MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0); MathDecorationInset * p = new MathDecorationInset("not", LM_not); @@ -118,8 +128,10 @@ void MathMacroTable::builtinMacros() t->push_back(p); insertTemplate(t); } +*/ { + MathMacroTemplate * t = new MathMacroTemplate("land", 0); t->push_back(LM_wedge, LM_TC_SYMB); insertTemplate(t); diff --git a/src/mathed/math_macrotable.h b/src/mathed/math_macrotable.h index 3d3241640f..68ea049476 100644 --- a/src/mathed/math_macrotable.h +++ b/src/mathed/math_macrotable.h @@ -26,6 +26,8 @@ public: static bool hasTemplate(string const &); /// static MathMacro * cloneTemplate(string const &); + /// + static void createTemplate(string const &, int, string const &); private: /// static void builtinMacros(); diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index b855c0732b..8bc608ac66 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -310,7 +310,7 @@ int yylex() } if (lexcode[c] == LexAlpha) { yytext.erase(); - while (lexcode[c] == LexAlpha) { + while (lexcode[c] == LexAlpha && yyis->good()) { yytext += c; c = getuchar(yyis); } @@ -512,9 +512,7 @@ void mathed_parse(MathArray & array, unsigned flags) ++plevel; while (t) { - //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i - // << " TK_LIMIT " << LM_TK_LIMIT << "\n"; - + //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i << "\n"; // << " plevel: " << plevel << " "; //array.dump(lyxerr); //lyxerr << "\n"; @@ -647,7 +645,7 @@ void mathed_parse(MathArray & array, unsigned flags) break; case LM_TK_DOTS: - array.push_back(new MathDotsInset(yylval.l->name, yylval.l->id)); + array.push_back(new MathDotsInset(yylval.l)); break; case LM_TK_CHOOSE: @@ -727,8 +725,7 @@ void mathed_parse(MathArray & array, unsigned flags) case LM_TK_DECORATION: { - MathDecorationInset * p - = new MathDecorationInset(yylval.l->name, yylval.l->id); + MathDecorationInset * p = new MathDecorationInset(yylval.l); mathed_parse(p->cell(0), FLAG_ITEM); array.push_back(p); break; @@ -805,7 +802,7 @@ void mathed_parse(MathArray & array, unsigned flags) // Search for the end command. do { t = yylex(); - } while (t != LM_TK_END && t); + } while (yyis->good() && t != LM_TK_END && t); } else t = yylex(); @@ -815,6 +812,18 @@ void mathed_parse(MathArray & array, unsigned flags) } + +MathArray mathed_parse_cell(string const & str) +{ + istringstream is(str.c_str()); + yyis = &is; + yylineno = 0; + MathArray ar; + mathed_parse(ar, 0); + return ar; +} + + MathInset * mathed_parse(string const & str) { istringstream is(str.c_str()); -- 2.39.2