]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/Parser.cpp
Cmake build: support tests
[lyx.git] / src / tex2lyx / Parser.cpp
index 5d0335ac82143e61fff34a4aaf99c1e172ab56fa..01f14b8dc9da9f3e031e37f964f6060c0eb35ff0 100644 (file)
@@ -383,7 +383,7 @@ bool Parser::hasOpt()
 }
 
 
-Parser::Arg Parser::getFullArg(char left, char right)
+Parser::Arg Parser::getFullArg(char left, char right, bool allow_escaping)
 {
        skip_spaces(true);
 
@@ -393,36 +393,40 @@ Parser::Arg Parser::getFullArg(char left, char right)
                return make_pair(false, string());
 
        string result;
-       char c = getChar();
+       Token t = get_token();
 
-       if (c != left) {
+       if (t.cat() == catComment || t.cat() == catEscape ||
+           t.character() != left) {
                putback();
                return make_pair(false, string());
        } else {
-               // in case of the '+' as delimiter single a '\' is allowed
-               // as content, for example "\verb+\+" (reported as bug #4468)
-               // we need special handling because single \ are normally ignored
-               // or taken as start of a command
-               if (c == '+')
-                       if (next_token().cat() == catEscape)
-                               result += '\\';
-               while ((c = getChar()) != right && good()) {
+               for (t = get_token(); good(); t = get_token()) {
                        // Ignore comments
-                       if (curr_token().cat() == catComment) {
-                               if (!curr_token().cs().empty())
-                                       cerr << "Ignoring comment: " << curr_token().asInput();
+                       if (t.cat() == catComment) {
+                               if (!t.cs().empty())
+                                       cerr << "Ignoring comment: " << t.asInput();
+                               continue;
                        }
-                       else
-                               result += curr_token().asInput();
+                       if (allow_escaping) {
+                               if (t.cat() != catEscape && t.character() == right)
+                                       break;
+                       } else {
+                               if (t.character() == right) {
+                                       if (t.cat() == catEscape)
+                                               result += '\\';
+                                       break;
+                               }
+                       }
+                       result += t.asInput();
                }
        }
        return make_pair(true, result);
 }
 
 
-string Parser::getArg(char left, char right)
+string Parser::getArg(char left, char right, bool allow_escaping)
 {
-       return getFullArg(left, right).second;
+       return getFullArg(left, right, allow_escaping).second;
 }
 
 
@@ -548,7 +552,7 @@ void Parser::tokenize_one()
                push_back(Token(s, catSpace));
                break;
        }
-               
+
        case catNewline: {
                ++lineno_;
                docstring s(1, getNewline(is_, c));
@@ -561,7 +565,7 @@ void Parser::tokenize_one()
                push_back(Token(s, catNewline));
                break;
        }
-               
+
        case catComment: {
                // We don't treat "%\n" combinations here specially because
                // we want to preserve them in the preamble
@@ -577,7 +581,7 @@ void Parser::tokenize_one()
                push_back(Token(s, catComment));
                break;
        }
-               
+
        case catEscape: {
                is_.get(c);
                if (!is_) {
@@ -595,12 +599,12 @@ void Parser::tokenize_one()
                }
                break;
        }
-               
+
        case catIgnore: {
                cerr << "ignoring a char: " << c << "\n";
                break;
        }
-               
+
        default:
                push_back(Token(docstring(1, c), catcode(c)));
        }