X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftex2lyx%2FParser.cpp;h=41ab92063c031a50b2a496d67dd75de963f039a6;hb=298730215c21735f16e7278a5d5a4469fb0b9859;hp=11ecfe12ec410698ec1caa56d4f14ba80ff137a1;hpb=25fe87e55c2449e4305e1b200469a48c75b0ea6e;p=lyx.git diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index 11ecfe12ec..41ab92063c 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -12,7 +12,6 @@ #include "Encoding.h" #include "Parser.h" -#include "support/foreach.h" #include "support/lstrings.h" #include "support/textutils.h" @@ -118,24 +117,19 @@ void debugToken(std::ostream & os, Token const & t, unsigned int flags) // Wrapper // -bool iparserdocstream::setEncoding(std::string const & e) +void iparserdocstream::setEncoding(std::string const & e) { is_ << lyx::setEncoding(e); - if (s_.empty()) - return true; - cerr << "Setting encoding " << e << " too late. The encoding of `" - << to_utf8(s_) << "´ is wrong." << std::endl; - return false; } 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 +140,7 @@ iparserdocstream & iparserdocstream::get(char_type &c) if (s_.empty()) is_.get(c); else { + //cerr << "unparsed: " << to_utf8(s_) <= tokens_.size()) { + if (pos_ >= tokens_.size()) + tokenize_one(); + if (pos_ + 1 >= tokens_.size()) tokenize_one(); - if (pos_ + 1 >= tokens_.size()) - tokenize_one(); - } return pos_ + 1 < tokens_.size() ? tokens_[pos_ + 1] : dummy; } @@ -425,6 +433,13 @@ void Parser::popPosition() { pos_ = positions_.back(); positions_.pop_back(); + deparse(); +} + + +void Parser::dropPosition() +{ + positions_.pop_back(); } @@ -623,11 +638,12 @@ string const Parser::plainCommand(char left, char right, string const & name) } -string const Parser::verbatimStuff(string const & end_string) +Parser::Arg Parser::verbatimStuff(string const & end_string, bool const allow_linebreak) { if (!good()) - return string(); + return Arg(false, string()); + pushPosition(); ostringstream oss; size_t match_index = 0; setCatcodes(VERBATIM_CATCODES); @@ -638,22 +654,38 @@ string const Parser::verbatimStuff(string const & end_string) match_index += t.asInput().length(); if (match_index >= end_string.length()) break; - } else if (match_index) { - oss << end_string.substr(0, match_index) << t.asInput(); - match_index = 0; - } else - oss << t.asInput(); + } else { + if (!allow_linebreak && t.asInput() == "\n") { + cerr << "unexpected end of input" << endl; + popPosition(); + setCatcodes(NORMAL_CATCODES); + return Arg(false, string()); + } + if (match_index) { + oss << end_string.substr(0, match_index) + << t.asInput(); + match_index = 0; + } else + oss << t.asInput(); + } } - setCatcodes(NORMAL_CATCODES); - if (!good()) + + if (!good()) { cerr << "unexpected end of input" << endl; - return oss.str(); + popPosition(); + setCatcodes(NORMAL_CATCODES); + return Arg(false, string()); + } + setCatcodes(NORMAL_CATCODES); + dropPosition(); + return Arg(true, oss.str()); } string const Parser::verbatimEnvironment(string const & name) { - string s = verbatimStuff("\\end{" + name + "}"); + //FIXME: do something if endstring is not found + string s = verbatimStuff("\\end{" + name + "}").second; // ignore one newline at beginning or end of string if (prefixIs(s, "\n")) s.erase(0,1); @@ -673,7 +705,7 @@ string Parser::verbatimOption() putback(); res += '{' + verbatim_item() + '}'; } else - res += t.cs(); + res += t.asInput(); } } return res;