]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_parser.C
forward search in math insets. ugly. seems to work. don't ask why.
[lyx.git] / src / mathed / math_parser.C
index f0b6e4fa99d23cfb75d4d8fa0738fb2831f4e3f4..7538fce72c38fbf3d9d7edfad4b9bada56b79d24 100644 (file)
@@ -45,9 +45,6 @@ point to write some macros:
 
 #include <config.h>
 
-#include <cctype>
-#include <stack>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
@@ -73,22 +70,29 @@ point to write some macros:
 #include "math_splitinset.h"
 #include "math_sqrtinset.h"
 #include "math_support.h"
+
 #include "lyxlex.h"
 #include "debug.h"
+
 #include "support/lstrings.h"
 
+#include <cctype>
+#include <stack>
+#include <algorithm>
+
 using std::istream;
 using std::ostream;
 using std::ios;
 using std::endl;
 using std::stack;
+using std::fill;
 
 
 namespace {
 
 bool stared(string const & s)
 {
-       unsigned n = s.size();
+       unsigned const n = s.size();
        return n && s[n - 1] == '*';
 }
 
@@ -133,6 +137,7 @@ enum {
        FLAG_RIGHT      = 1 << 2,  //  next \\right ends the parsing process
        FLAG_END        = 1 << 3,  //  next \\end ends the parsing process
        FLAG_BRACK_END  = 1 << 4,  //  next closing bracket ends the parsing process
+       FLAG_BOX        = 1 << 5,  //  we are in a box
        FLAG_ITEM       = 1 << 7,  //  read a (possibly braced token)
        FLAG_BLOCK      = 1 << 8,  //  next block ends the parsing process
        FLAG_LEAVE      = 1 << 9   //  leave the loop at the end
@@ -141,12 +146,9 @@ enum {
 
 void catInit()
 {
-       for (int i = 0; i <= 255; ++i) 
-               theCatcode[i] = catOther;
-       for (int i = 'a'; i <= 'z'; ++i) 
-               theCatcode[i] = catLetter;
-       for (int i = 'A'; i <= 'Z'; ++i) 
-               theCatcode[i] = catLetter;
+       fill(theCatcode, theCatcode + 256, catOther);
+       fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
+       fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
 
        theCatcode['\\'] = catEscape;   
        theCatcode['{']  = catBegin;    
@@ -178,7 +180,7 @@ public:
        ///
        Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
        ///
-       Token(const string & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
+       Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
 
        ///
        string const & cs() const { return cs_; }
@@ -500,7 +502,7 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
                return false;
        }
 
-       const int cols = p->ncols();
+       int const cols = p->ncols();
 
        // save global variables
        bool   const saved_num   = curr_num_;
@@ -759,8 +761,16 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                //
                // cat codes
                //
-               if (t.cat() == catMath)
-                       break;
+               if (t.cat() == catMath) {
+                       if (flags & FLAG_BOX) {
+                               // we are inside an mbox, so opening new math is allowed
+                               array.push_back(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
+                               parse_into(array.back()->cell(0), 0);
+                       } else {
+                               // otherwise this is the end of the formula
+                               break;
+                       }
+               }
 
                else if (t.cat() == catLetter)
                        add(array, t.character(), code);
@@ -791,14 +801,14 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                else if (t.cat() == catEnd) {
                        if (flags & FLAG_BRACE_LAST)
                                return;
-                       //lyxerr << "found '}' unexpectedly, array: '" << array << "'\n";
-                       lyxerr << "found '}' unexpectedly\n";
+                       lyxerr << "found '}' unexpectedly, array: '" << array << "'\n";
+                       //lyxerr << "found '}' unexpectedly\n";
                        add(array, '}', LM_TC_TEX);
                }
                
                else if (t.cat() == catAlign) {
-                       //lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
-                       lyxerr << "found tab unexpectedly\n";
+                       lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
+                       //lyxerr << "found tab unexpectedly\n";
                        add(array, '&', LM_TC_TEX);
                }
                
@@ -984,6 +994,12 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                                        code = static_cast<MathTextCodes>(l->id);
                                }
 
+                               else if (l->token == LM_TK_BOX) {
+                                       MathAtom p = createMathInset(t.cs());
+                                       parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX);
+                                       array.push_back(p);
+                               }
+
                                else {
                                        MathAtom p = createMathInset(t.cs());
                                        for (MathInset::idx_type i = 0; i < p->nargs(); ++i)