]> git.lyx.org Git - features.git/blobdiff - src/mathed/math_parser.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / mathed / math_parser.C
index 1efd8ec7db9ad6c69975764716cf6ef029797128..0264350e87bb209ba58a9a910fb9f919be713e43 100644 (file)
@@ -48,6 +48,7 @@ following hack as starting point to write some macros:
 #include "math_factory.h"
 #include "math_kerninset.h"
 #include "math_macro.h"
+#include "math_macroarg.h"
 #include "math_macrotemplate.h"
 #include "math_parboxinset.h"
 #include "math_parinset.h"
@@ -61,17 +62,22 @@ following hack as starting point to write some macros:
 #include "ref_inset.h"
 
 #include "lyxlex.h"
-#include "Lsstream.h"
 #include "debug.h"
 
+#include <sstream>
 
-using std::istream;
-using std::ostream;
-using std::ios;
+#ifndef CXX_GLOBAL_CSTD
+using std::atoi;
+#endif
 using std::endl;
 using std::fill;
+
+using std::string;
+using std::ios;
+using std::istream;
+using std::istringstream;
+using std::ostream;
 using std::vector;
-using std::atoi;
 
 
 //#define FILEDEBUG
@@ -142,31 +148,6 @@ enum {
 };
 
 
-void catInit()
-{
-       fill(theCatcode, theCatcode + 256, catOther);
-       fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
-       fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
-
-       theCatcode[int('\\')] = catEscape;
-       theCatcode[int('{')]  = catBegin;
-       theCatcode[int('}')]  = catEnd;
-       theCatcode[int('$')]  = catMath;
-       theCatcode[int('&')]  = catAlign;
-       theCatcode[int('\n')] = catNewline;
-       theCatcode[int('#')]  = catParameter;
-       theCatcode[int('^')]  = catSuper;
-       theCatcode[int('_')]  = catSub;
-       theCatcode[int(0x7f)] = catIgnore;
-       theCatcode[int(' ')]  = catSpace;
-       theCatcode[int('\t')] = catSpace;
-       theCatcode[int('\r')] = catNewline;
-       theCatcode[int('~')]  = catActive;
-       theCatcode[int('%')]  = catComment;
-}
-
-
-
 //
 // Helper class for parsing
 //
@@ -211,7 +192,6 @@ ostream & operator<<(ostream & os, Token const & t)
 
 
 class Parser {
-
 public:
        ///
        typedef  MathInset::mode_type mode_type;
@@ -410,13 +390,6 @@ void Parser::tokenize(istream & is)
 
 void Parser::tokenize(string const & buffer)
 {
-       static bool init_done = false;
-
-       if (!init_done) {
-               catInit();
-               init_done = true;
-       }
-
        istringstream is(buffer.c_str(), ios::in | ios::binary);
 
        char c;
@@ -719,7 +692,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        if (flags & FLAG_BRACE_LAST)
                                return;
                        error("found '}' unexpectedly");
-                       //lyx::Assert(0);
+                       //BOOST_ASSERT(false);
                        //add(cell, '}', LM_TC_TEX);
                }
 
@@ -753,7 +726,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        //if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() &&
                        //    p->nuc().back()->extraBraces())
                        //      p->nuc() = p->nuc().back()->asNestInset()->cell(0);
-                       parse(p->cell(up), FLAG_ITEM, mode);
+                       parse(p->cell(p->idxOfScript(up)), FLAG_ITEM, mode);
                        if (limits) {
                                p->limits(limits);
                                limits = 0;
@@ -1130,6 +1103,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        return;
                }
 
+               else if (t.cs() == "color") {
+                       MathAtom at = createMathInset(t.cs());
+                       parse(at.nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
+                       parse(at.nucleus()->cell(1), flags, mode);
+                       cell->push_back(at);
+                       return;
+               }
+
                else if (t.cs() == "substack") {
                        cell->push_back(createMathInset(t.cs()));
                        parse2(cell->back(), FLAG_ITEM, mode, false);
@@ -1152,7 +1133,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
 
                // Disabled
                else if (1 && t.cs() == "ar") {
-                       MathXYArrowInset * p = new MathXYArrowInset;
+                       auto_ptr<MathXYArrowInset> p(new MathXYArrowInset);
                        // try to read target
                        parse(p->cell(0), FLAG_OTPTION, mode);
                        // try to read label
@@ -1163,7 +1144,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                //lyxerr << "read label: " << p->cell(1) << endl;
                        }
 
-                       cell->push_back(MathAtom(p));
+                       cell->push_back(MathAtom(p.release()));
                        //lyxerr << "read cell: " << cell << endl;
                }
 #endif
@@ -1278,3 +1259,27 @@ void mathed_parse_normal(MathGridInset & grid, string const & str)
        istringstream is(str.c_str());
        Parser(is).parse1(grid, 0, MathInset::MATH_MODE, false);
 }
+
+
+void initParser()
+{
+       fill(theCatcode, theCatcode + 256, catOther);
+       fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
+       fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
+
+       theCatcode[int('\\')] = catEscape;
+       theCatcode[int('{')]  = catBegin;
+       theCatcode[int('}')]  = catEnd;
+       theCatcode[int('$')]  = catMath;
+       theCatcode[int('&')]  = catAlign;
+       theCatcode[int('\n')] = catNewline;
+       theCatcode[int('#')]  = catParameter;
+       theCatcode[int('^')]  = catSuper;
+       theCatcode[int('_')]  = catSub;
+       theCatcode[int(0x7f)] = catIgnore;
+       theCatcode[int(' ')]  = catSpace;
+       theCatcode[int('\t')] = catSpace;
+       theCatcode[int('\r')] = catNewline;
+       theCatcode[int('~')]  = catActive;
+       theCatcode[int('%')]  = catComment;
+}