]> git.lyx.org Git - lyx.git/commitdiff
small parser stuff
authorAndré Pönitz <poenitz@gmx.net>
Fri, 10 Aug 2001 07:52:04 +0000 (07:52 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 10 Aug 2001 07:52:04 +0000 (07:52 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2472 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_parser.C

index 2def6913c6c8ad650ce72b8afcc0cc5c96388561..587c86c978505386193ac782e8fc2d0f60a1f0c6 100644 (file)
@@ -15,8 +15,6 @@
  *   the GNU General Public Licence version 2 or later.
  */
 
-// {[(
-
 #include <config.h>
 
 #include <cctype>
@@ -58,13 +56,13 @@ using std::istream;
 using std::endl;
 
 
+namespace {
 
 // These are lexical codes, not semantic
 enum lexcode_enum {
        LexNone,
        LexESC,
        LexAlpha,
-       LexDigit,
        LexBOP,         // Binary operators or relations
        LexOpen,
        LexClose,
@@ -80,8 +78,6 @@ enum lexcode_enum {
 lexcode_enum lexcode[256];  
 
 
-namespace {
-
 void mathed_parse_into(MathArray & array, unsigned flags);
 
 unsigned char getuchar(std::istream * is)
@@ -165,7 +161,7 @@ void lexInit()
 {
        for (int i = 0; i <= 255; ++i) {
                if (isdigit(i))
-                       lexcode[i] = LexDigit;
+                       lexcode[i] = LexOther;
                else if (isspace(i))
                        lexcode[i] = LexSpace;
                else
@@ -254,7 +250,7 @@ int yylex()
                        do {
                                c = getuchar(yyis);
                        } while (c != '\n' && yyis->good());  // eat comments
-               } else if (lexcode[c] == LexDigit || lexcode[c] == LexOther) {
+               } else if (lexcode[c] == LexOther) {
                        yylval.i = c;
                        return LM_TK_STR;
                } else if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) {
@@ -486,7 +482,7 @@ MathMatrixInset * mathed_parse_normal()
 latexkeys const * read_delim()
 {
        int ld = yylex();
-       lyxerr << "found symbol: " << ld << "\n";
+       //lyxerr << "found symbol: " << ld << "\n";
        latexkeys const * l = in_word_set(".");
        switch (ld) {
                case LM_TK_SYM:
@@ -494,14 +490,14 @@ latexkeys const * read_delim()
                case LM_TK_SPECIAL:
                case LM_TK_BEGIN:
                        l = yylval.l;
-                       lyxerr << "found key 1: '" << l << "'\n";
-                       lyxerr << "found key 1: '" << l->name << "'\n";
+                       //lyxerr << "found key 1: '" << l << "'\n";
+                       //lyxerr << "found key 1: '" << l->name << "'\n";
                        break;
                case LM_TK_STR:
                        string s;
                        s += yylval.i;
                        l = in_word_set(s);
-                       lyxerr << "found key 2: '" << l->name << "'\n";
+                       //lyxerr << "found key 2: '" << l->name << "'\n";
        }
        return l;
 }
@@ -835,6 +831,21 @@ void mathed_parse_into(MathArray & array, unsigned flags)
        --plevel;
 }
 
+void mathed_parse_end(LyXLex & lex)
+{
+       // Update line number
+       lex.setLineNo(yylineno);
+
+       // reading of end_inset
+       while (lex.isOK()) {
+               lex.nextToken();
+               if (lex.getString() == "\\end_inset")
+                       break;
+               lyxerr[Debug::MATHED] << "InsetFormula::Read: Garbage before \\end_inset,"
+                       " or missing \\end_inset!" << endl;
+       }
+}
+
 }
 
 
@@ -849,79 +860,50 @@ MathArray mathed_parse_cell(string const & str)
 }
 
 
+
 MathMacroTemplate * mathed_parse_macro(string const & str)
 {
        istringstream is(str.c_str());
        return mathed_parse_macro(is);
 }
 
+MathMacroTemplate * mathed_parse_macro(istream & is)
+{
+       yyis     = &is;
+       yylineno = 0;
+       return mathed_parse_macro();
+}
 
-MathMatrixInset * mathed_parse_normal(string const & str)
+MathMacroTemplate * mathed_parse_macro(LyXLex & lex)
 {
-       istringstream is(str.c_str());
-       return mathed_parse_normal(is);
+       yyis     = &lex.getStream();
+       yylineno = lex.getLineNo();
+       MathMacroTemplate * p = mathed_parse_macro();
+       mathed_parse_end(lex);
+       return p;
 }
 
 
 
-MathMatrixInset * mathed_parse_normal(istream & is)
+MathMatrixInset * mathed_parse_normal(string const & str)
 {
-       yyis     = &is;
-       yylineno = 0;
-       return mathed_parse_normal();
+       istringstream is(str.c_str());
+       return mathed_parse_normal(is);
 }
 
-
-MathMacroTemplate * mathed_parse_macro(istream & is)
+MathMatrixInset * mathed_parse_normal(istream & is)
 {
        yyis     = &is;
        yylineno = 0;
-       return mathed_parse_macro();
+       return mathed_parse_normal();
 }
 
-
-
 MathMatrixInset * mathed_parse_normal(LyXLex & lex)
 {
        yyis     = &lex.getStream();
        yylineno = lex.getLineNo();
-
        MathMatrixInset * p = mathed_parse_normal();
-
-       // Update line number
-       lex.setLineNo(yylineno);
-
-       // reading of end_inset
-       while (lex.isOK()) {
-               lex.nextToken();
-               if (lex.getString() == "\\end_inset")
-                       break;
-               lyxerr[Debug::MATHED] << "InsetFormula::Read: Garbage before \\end_inset,"
-                       " or missing \\end_inset!" << endl;
-       }
-
+       mathed_parse_end(lex);
        return p;
 }
 
-MathMacroTemplate * mathed_parse_macro(LyXLex & lex)
-{
-       yyis     = &lex.getStream();
-       yylineno = lex.getLineNo();
-
-       MathMacroTemplate * p = mathed_parse_macro();
-
-       // Update line number
-       lex.setLineNo(yylineno);
-
-       // reading of end_inset
-       while (lex.isOK()) {
-               lex.nextToken();
-               if (lex.getString() == "\\end_inset")
-                       break;
-               lyxerr[Debug::MATHED] << "InsetFormula::Read: Garbage before \\end_inset,"
-                       " or missing \\end_inset!" << endl;
-       }
-
-       return p;
-}
-//]})