]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/texparser.C
Continue to improve GtkLengthEntry
[lyx.git] / src / tex2lyx / texparser.C
index 8a17a47d33b897e9cd34a09e17790148c87cf153..bdfea89a5357358bb9bc5f4ff6e4495f985adbec 100644 (file)
@@ -20,6 +20,7 @@ using std::endl;
 using std::fill;
 using std::istream;
 using std::istringstream;
+using std::ostringstream;
 using std::ostream;
 using std::string;
 
@@ -323,6 +324,36 @@ string Parser::getOpt()
 }
 
 
+string const Parser::verbatimEnvironment(string const & name)
+{
+       if (!good())
+               return string();
+
+       ostringstream os;
+       for (Token t = get_token(); good(); t = get_token()) {
+               if (t.cat() == catBegin) {
+                       putback();
+                       os << '{' << verbatim_item() << '}';
+               } else if (t.asInput() == "\\begin") {
+                       string const env = getArg('{', '}');
+                       os << "\\begin{" << env << '}'
+                          << verbatimEnvironment(env)
+                          << "\\end{" << env << '}';
+               } else if (t.asInput() == "\\end") {
+                       string const end = getArg('{', '}');
+                       if (end != name)
+                               cerr << "\\end{" << end
+                                    << "} does not match \\begin{" << name
+                                    << "}." << endl;
+                       return os.str();
+               } else
+                       os << t.asInput();
+       }
+       cerr << "unexpected end of input" << endl;
+       return os.str();
+}
+
+
 void Parser::tokenize(istream & is)
 {
        static bool init_done = false;