From: Jean-Marc Lasgouttes Date: Fri, 15 Feb 2013 16:03:18 +0000 (+0100) Subject: Implement deparsing of tokens X-Git-Tag: 2.1.0beta1~710 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=47b8ab14db71c6932ba5a8f159fc71a745792aca;p=features.git Implement deparsing of tokens When switching catcodes (for example to verbatim), there are in general some tokens that have already been parsed according to the old catcodes. It is therefore needed to "forget" those token and reparse them. The basic idea is to use idocstream::putback() to feed the characters back to the stream, but this does not work (probably because we disable buffering). Therefore, we implement a simple stream-like class that implements putback(). --- diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index 7139d1e3fa..d7d3144b4b 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -12,6 +12,7 @@ #include "Encoding.h" #include "Parser.h" +#include "support/foreach.h" #include "support/lstrings.h" #include "support/textutils.h" @@ -29,7 +30,7 @@ namespace { * \p c must have catcode catNewline, and it must be the last character read * from \p is. */ -char_type getNewline(idocstream & is, char_type c) +char_type getNewline(iparserdocstream & is, char_type c) { // we have to handle 3 different line endings: // - UNIX (\n) @@ -140,6 +141,20 @@ Parser::~Parser() } +void Parser::deparse() +{ + for(size_type i = pos_ ; i < tokens_.size() ; ++i) { + docstring const s = from_utf8(tokens_[i].asInput()); + //cerr << "deparsing [" << to_utf8(s) << "]" <