]> git.lyx.org Git - features.git/commitdiff
Some fixes to parsing in tex2lyx
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 22 Feb 2013 14:32:13 +0000 (15:32 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 22 Feb 2013 14:53:40 +0000 (15:53 +0100)
* put_almost_back and putback are actually the same thing
* add Parser::dropPosition
* deparse on Parser::popPosition

src/tex2lyx/Parser.cpp
src/tex2lyx/Parser.h

index 11ecfe12ec410698ec1caa56d4f14ba80ff137a1..d87ff29546518c39322fe750ce84af98a0f7599f 100644 (file)
@@ -131,11 +131,11 @@ bool iparserdocstream::setEncoding(std::string const & e)
 
 void iparserdocstream::putback(char_type c)
 {
-       s_ += c;
+       s_ = c + s_;
 }
 
 
-void iparserdocstream::put_almost_back(docstring s)
+void iparserdocstream::putback(docstring s)
 {
        s_ = s + s_;
 }
@@ -146,6 +146,7 @@ iparserdocstream & iparserdocstream::get(char_type &c)
        if (s_.empty())
                is_.get(c);
        else {
+               //cerr << "unparsed: " << to_utf8(s_) <<endl;
                c = s_[0];
                s_.erase(0,1);
        }
@@ -186,7 +187,7 @@ void Parser::deparse()
        for(size_type i = pos_ ; i < tokens_.size() ; ++i) {
                s += tokens_[i].asInput();
        }
-       is_.put_almost_back(from_utf8(s));
+       is_.putback(from_utf8(s));
        tokens_.erase(tokens_.begin() + pos_, tokens_.end());
        // make sure that next token is read
        tokenize_one();
@@ -425,6 +426,13 @@ void Parser::popPosition()
 {
        pos_ = positions_.back();
        positions_.pop_back();
+       deparse();
+}
+
+
+void Parser::dropPosition()
+{
+       positions_.pop_back();
 }
 
 
index 3d2bf567ef4c29c94133d1c346e622ea1cf0e9fc..42243c6465a581a4427bca8f183310519831aef7 100644 (file)
@@ -135,9 +135,9 @@ public:
        // the stream
        void putback(char_type c);
 
-       // add before the list of characters to read before actually reading
+       // add to the list of characters to read before actually reading
        // the stream
-       void put_almost_back(docstring s);
+       void putback(docstring s);
 
        /// Like std::istream::get()
        iparserdocstream & get(char_type &c);
@@ -206,6 +206,8 @@ public:
        void pushPosition();
        /// restore previous position
        void popPosition();
+       /// forget last saved position
+       void dropPosition();
        /// dump contents to screen
        void dump() const;