]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/texparser.C
Add a Buffer::fully_loaded member function, returning true only when
[lyx.git] / src / tex2lyx / texparser.C
index d1014f71c602288ed6fee5565308c08831401f6f..e5612667d2ce3a2a8f1283c349ba545f6c5baf16 100644 (file)
@@ -1,20 +1,27 @@
+/**
+ * \file texparser.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "texparser.h"
-#include "Lsstream.h"
 
 #include <iostream>
+#include <sstream>
 
 using std::cerr;
 using std::endl;
 using std::fill;
-using std::ios;
 using std::istream;
 using std::istringstream;
 using std::ostream;
 using std::string;
-using std::vector;
 
 
 namespace {
@@ -38,30 +45,30 @@ void catInit()
        fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
        fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
 
-       theCatcode['\\'] = catEscape;
-       theCatcode['{']  = catBegin;
-       theCatcode['}']  = catEnd;
-       theCatcode['$']  = catMath;
-       theCatcode['&']  = catAlign;
+       theCatcode[int('\\')] = catEscape;
+       theCatcode[int('{')]  = catBegin;
+       theCatcode[int('}')]  = catEnd;
+       theCatcode[int('$')]  = catMath;
+       theCatcode[int('&')]  = catAlign;
        theCatcode[10]   = catNewline;
-       theCatcode['#']  = catParameter;
-       theCatcode['^']  = catSuper;
-       theCatcode['_']  = catSub;
-       theCatcode['\7f'] = catIgnore;
-       theCatcode[' ']  = catSpace;
-       theCatcode['\t'] = catSpace;
+       theCatcode[int('#')]  = catParameter;
+       theCatcode[int('^')]  = catSuper;
+       theCatcode[int('_')]  = catSub;
+       theCatcode[0x7f] = catIgnore;
+       theCatcode[int(' ')]  = catSpace;
+       theCatcode[int('\t')] = catSpace;
        theCatcode[13]   = catIgnore;
-       theCatcode['~']  = catActive;
-       theCatcode['%']  = catComment;
+       theCatcode[int('~')]  = catActive;
+       theCatcode[int('%')]  = catComment;
 
        // This is wrong!
-       theCatcode['@']  = catLetter;
+       theCatcode[int('@')]  = catLetter;
 }
 
 }
 
 
-// 
+//
 // catcodes
 //
 
@@ -166,12 +173,12 @@ Token const & Parser::get_token()
 }
 
 
-void Parser::skipSpaces()
+void Parser::skip_spaces()
 {
        while (1) {
                if (next_token().cat() == catSpace || next_token().cat() == catNewline)
                        get_token();
-               else if (next_token().cat() == catComment) 
+               else if (next_token().cat() == catComment)
                        while (next_token().cat() != catNewline)
                                get_token();
                else
@@ -202,7 +209,7 @@ char Parser::getChar()
 
 string Parser::getArg(char left, char right)
 {
-       skipSpaces();
+       skip_spaces();
 
        string result;
        char c = getChar();
@@ -219,7 +226,7 @@ string Parser::getArg(char left, char right)
 
 string Parser::getOpt()
 {
-       string res = getArg('[', ']');
+       string const res = getArg('[', ']');
        return res.size() ? '[' + res + ']' : string();
 }
 
@@ -253,14 +260,21 @@ void Parser::tokenize(istream & is)
                                break;
                        }
 
-/*
                        case catComment: {
+                               push_back(Token(c, catComment));
                                while (is.get(c) && catcode(c) != catNewline)
-                                       ;
+                                       push_back(Token(c, catLetter));
+                               push_back(Token(c, catNewline));
                                ++lineno_;
+                               is.get(c);
+                               if (catcode(c) == catNewline) {
+                                       push_back(Token("par"));
+                                       ++lineno_;
+                               } else {
+                                       is.putback(c);
+                               }
                                break;
                        }
-*/
 
                        case catEscape: {
                                is.get(c);
@@ -341,7 +355,7 @@ string Parser::verbatim_item()
 {
        if (!good())
                error("stream bad");
-       skipSpaces();
+       skip_spaces();
        if (next_token().cat() == catBegin) {
                Token t = get_token(); // skip brace
                string res;
@@ -361,11 +375,11 @@ string Parser::verbatim_item()
 
 void Parser::setCatCode(char c, CatCode cat)
 {
-       theCatcode[c] = cat;    
+       theCatcode[(unsigned char)c] = cat;
 }
 
 
 CatCode Parser::getCatCode(char c) const
 {
-       return theCatcode[c];
+       return theCatcode[(unsigned char)c];
 }