]> git.lyx.org Git - features.git/commitdiff
read/input support for TeX's '\over'
authorAndré Pönitz <poenitz@gmx.net>
Mon, 13 Aug 2001 14:46:06 +0000 (14:46 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 13 Aug 2001 14:46:06 +0000 (14:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2503 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/math_cursor.C
src/mathed/math_parser.C

index 02a744d5b9d24f96f2de00433961aea28f841ff8..75d9423c368c985d2117cf1a49a7e097d85e760e 100644 (file)
@@ -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  <poenitz@gmx.net>
 
        *       math_scopeinset.[Ch]: new inset for {} blocks
index 6279fdfaeb453fab771d48648cfda7c0c6b9d593..48640a855e91e9989ae6b2bd7313051620ad0bf0 100644 (file)
@@ -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;
        }
 
index cb7188d962a8671344036f2f59c169de1e2bcd17..bd6de769d993d3c58a2eb337a8143a63a7f8081f 100644 (file)
@@ -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;
                }