From: André Pönitz Date: Mon, 13 Aug 2001 14:46:06 +0000 (+0000) Subject: read/input support for TeX's '\over' X-Git-Tag: 1.6.10~20842 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1e9b743bce48213820fb9ff7be7294c1bfbeb6d1;p=features.git read/input support for TeX's '\over' git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2503 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 02a744d5b9..75d9423c36 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -7,6 +7,9 @@ math_cursor.C: math_hash.C: simplifications + * math_parser.C: + math_cursor.C: reading support for TeX style \over + 2001-08-10 André Pönitz * math_scopeinset.[Ch]: new inset for {} blocks diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 6279fdfaeb..48640a855e 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -35,6 +35,7 @@ #include "math_charinset.h" #include "math_decorationinset.h" #include "math_deliminset.h" +#include "math_fracinset.h" #include "math_funcinset.h" #include "math_macro.h" #include "math_macrotable.h" @@ -1261,22 +1262,10 @@ void MathCursor::interpret(string const & s) char c = s[0]; - lyxerr << "char: '" << c << "' int: " << int(c) << endl; + //lyxerr << "char: '" << c << "' int: " << int(c) << endl; //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt); //lyxerr << "trans: '" << c << "' int: " << int(c) << endl; - latexkeys const * l = in_word_set(s.substr(1)); - if (l) { - lastcode_ = LM_TC_VAR; - niceInsert(createMathInset(l)); - return; - } - - if (MathMacroTable::hasTemplate(s.substr(1))) { - niceInsert(new MathMacro(MathMacroTable::provideTemplate(s.substr(1)))); - return; - } - if (s.size() > 8 && s.substr(0, 8) == "\\matrix ") { int m = 1; int n = 1; @@ -1287,10 +1276,32 @@ void MathCursor::interpret(string const & s) m = std::max(1, m); n = std::max(1, n); v_align += 'c'; - MathArrayInset * pp = new MathArrayInset(m, n); - pp->valign(v_align[0]); - pp->halign(h_align); - niceInsert(pp); + MathArrayInset * p = new MathArrayInset(m, n); + p->valign(v_align[0]); + p->halign(h_align); + niceInsert(p); + return; + } + + if (s == "\\over") { + MathArray ar = array(); + MathFracInset * p = new MathFracInset; + p->cell(0).swap(array()); + pos() = 0; + niceInsert(p); + down(); + return; + } + + latexkeys const * l = in_word_set(s.substr(1)); + if (l) { + lastcode_ = LM_TC_VAR; + niceInsert(createMathInset(l)); + return; + } + + if (MathMacroTable::hasTemplate(s.substr(1))) { + niceInsert(new MathMacro(MathMacroTable::provideTemplate(s.substr(1)))); return; } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index cb7188d962..bd6de769d9 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -30,6 +30,7 @@ #include "math_charinset.h" #include "math_deliminset.h" #include "math_factory.h" +#include "math_fracinset.h" #include "math_funcinset.h" #include "math_macro.h" #include "math_macrotable.h" @@ -99,6 +100,7 @@ lexcode_enum lexcode[256]; const unsigned char LM_TK_OPEN = '{'; +const unsigned char LM_TK_CLOSE = '}'; enum { FLAG_BRACE = 1 << 0, // an opening brace needed @@ -184,9 +186,13 @@ void lexInit() class Parser { public: /// - Parser(LyXLex & lex) : is_(lex.getStream()), lineno_(lex.getLineNo()) {} + Parser(LyXLex & lex) + : is_(lex.getStream()), lineno_(lex.getLineNo()), putback_token_(0) + {} /// - Parser(istream & is) : is_(is), lineno_(0) {} + Parser(istream & is) + : is_(is), lineno_(0), putback_token_(0) + {} /// MathMacroTemplate * parse_macro(); @@ -196,6 +202,8 @@ public: void parse_into(MathArray & array, unsigned flags); /// int lineno() const { return lineno_; } + /// + void putback(int token); private: /// @@ -230,9 +238,18 @@ private: string curr_label_; /// string curr_skip_; + + /// + int putback_token_; }; +void Parser::putback(int token) +{ + putback_token_ = token; +} + + unsigned char Parser::getuchar() { char c = 0; @@ -291,6 +308,12 @@ int Parser::yylex() lexInit(); init_done = true; } + + if (putback_token_) { + int token = putback_token_; + putback_token_ = 0; + return token; + } while (is_.good()) { unsigned char c = getuchar(); @@ -299,29 +322,45 @@ int Parser::yylex() if (lexcode[c] == LexNewLine) { ++lineno_; continue; - } else if (lexcode[c] == LexComment) { + } + + if (lexcode[c] == LexComment) { do { c = getuchar(); } while (c != '\n' && is_.good()); // eat comments - } else if (lexcode[c] == LexOther) { + } + + if (lexcode[c] == LexOther) { ival_ = c; return LM_TK_STR; - } else if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) { + } + + if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) { ival_ = c; return LM_TK_ALPHA; - } else if (lexcode[c] == LexBOP) { + } + + if (lexcode[c] == LexBOP) { ival_ = c; return LM_TK_BOP; - } else if (lexcode[c] == LexMath) { + } + + if (lexcode[c] == LexMath) { ival_ = 0; return LM_TK_MATH; - } else if (lexcode[c] == LexSelf) { + } + + if (lexcode[c] == LexSelf) { return c; - } else if (lexcode[c] == LexArgument) { + } + + if (lexcode[c] == LexArgument) { c = getuchar(); ival_ = c - '0'; return LM_TK_ARGUMENT; - } else if (lexcode[c] == LexESC) { + } + + if (lexcode[c] == LexESC) { c = getuchar(); //lyxerr << "reading second byte: '" << c << "' code: " << lexcode[c] << endl; string s; @@ -575,6 +614,15 @@ void Parser::parse_into(MathArray & array, unsigned flags) } } + if (flags & FLAG_BLOCK) { + if (t == LM_TK_CLOSE || t == '&' || + t == LM_TK_NEWLINE || t == LM_TK_END) { + putback(t); + return; + } + } + + switch (t) { case LM_TK_MATH: @@ -769,8 +817,10 @@ void Parser::parse_into(MathArray & array, unsigned flags) case LM_TK_OVER: { - MathArray ar; - parse_into(ar, FLAG_BLOCK); + MathFracInset * p = new MathFracInset; + p->cell(0).swap(array); + array.push_back(p); + parse_into(p->cell(1), FLAG_BLOCK); break; }