From 47b8ab14db71c6932ba5a8f159fc71a745792aca Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 15 Feb 2013 17:03:18 +0100 Subject: [PATCH] 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(). --- src/tex2lyx/Parser.cpp | 25 ++++++++++++++++++++++--- src/tex2lyx/Parser.h | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) 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) << "]" <