]> git.lyx.org Git - lyx.git/commitdiff
tex2lyx: support for inline listings (fixes last part of #8066)
authorUwe Stöhr <uwestoehr@web.de>
Mon, 5 Mar 2012 22:04:22 +0000 (22:04 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Mon, 5 Mar 2012 22:04:22 +0000 (22:04 +0000)
OK also for branch?

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40860 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 06027e880ad2d0209116f7ebf840535a739e3258..290b7ba7b77925150d6497250937fc7314565456 100644 (file)
@@ -502,6 +502,28 @@ string const Parser::plainEnvironment(string const & name)
 }
 
 
+string const Parser::plainCommand(char left, char right, string const & name)
+{
+       if (!good())
+               return string();
+       // ceck if first token is really the start character
+       Token tok = get_token();
+       if (tok.character() != left) {
+               cerr << "first character does not match start character of command \\" << name << endl;
+               return string();
+       }
+       ostringstream os;
+       for (Token t = get_token(); good(); t = get_token()) {
+               if (t.character() == right) {
+                       return os.str();
+               } else
+                       os << t.asInput();
+       }
+       cerr << "unexpected end of input" << endl;
+       return os.str();
+}
+
+
 void Parser::tokenize_one()
 {
        catInit();
index 2f4e26a5873be876e107b649ed21e1cba1cbbdd6..3b852e1090ff7e55eac0f6fc50c85694e8b898ef 100644 (file)
@@ -202,6 +202,13 @@ public:
        * This function is designed to parse verbatim environments.
        */
        std::string const plainEnvironment(std::string const & name);
+       /*
+       * Basically the same as plainEnvironment(std::string const & name) but
+       * instead of \begin and \end commands the parsing is started/stopped
+       * at given characters.
+       * This function is designed to parse verbatim commands.
+       */
+       std::string const plainCommand(char left, char right, std::string const & name);
        /*!
         * Returns the character of the current token and increments
         * the token position.
index 65f4e3ce49e1580b0f4c5d56c788ba146c131048..e083e39ec8a147e8104186f1e8167e3e31103722 100644 (file)
@@ -1118,7 +1118,7 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer,
 }
 
 
-void parse_listings(Parser & p, ostream & os, Context & parent_context)
+void parse_listings(Parser & p, ostream & os, Context & parent_context, bool in_line)
 {
        parent_context.check_layout(os);
        begin_inset(os, "listings\n");
@@ -1133,11 +1133,20 @@ void parse_listings(Parser & p, ostream & os, Context & parent_context)
                }
                os << "lstparams " << '"' << arg << '"' << '\n';
        }
-       os << "inline false\n"
-          << "status collapsed\n";
+       if (in_line)
+               os << "inline true\n";
+       else
+               os << "inline false\n";
+       os << "status collapsed\n";
        Context context(true, parent_context.textclass);
        context.layout = &parent_context.textclass.plainLayout();
-       string const s = p.plainEnvironment("lstlisting");
+       string s;
+       if (in_line) {
+               s = p.plainCommand('!', '!', "lstinline");
+               context.new_paragraph(os);
+               context.check_layout(os);
+       } else
+               s = p.plainEnvironment("lstlisting");
        for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
                if (*it == '\\')
                        os << "\n\\backslash\n";
@@ -1399,7 +1408,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                eat_whitespace(p, os, parent_context, false);
                // FIXME handle the automatic color package loading
                // uwestoehr asks: In what case color is loaded?
-               parse_listings(p, os, parent_context);
+               parse_listings(p, os, parent_context, false);
                p.skip_spaces();
        }
 
@@ -2787,6 +2796,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        end_inset(os);
                }
 
+               else if (t.cs() == "lstinline") {
+                       p.skip_spaces();
+                       parse_listings(p, os, context, true);
+               }
+
                else if (t.cs() == "ensuremath") {
                        p.skip_spaces();
                        context.check_layout(os);