commit 590185d3ef903714090c0461d4e1c427679a2833
Author: Juergen Spitzmueller <sp...@lyx.org>
Date: Fri Mar 9 13:14:13 2018 +0100
Advertising
tex2lyx: honor grouping in optional arguments.
E.g., \cite[{a literal ] character}]{key}
(cherry picked from commit cba38881d6b9fa3ff5dd0ebe50239fc384309082)
---
src/tex2lyx/Parser.cpp | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index 35748b9..6e29623 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -494,6 +494,7 @@ Parser::Arg Parser::getFullArg(char left, char right, bool
allow_escaping)
if (! good())
return make_pair(false, string());
+ int group_level = 0;
string result;
Token t = get_token();
@@ -504,6 +505,15 @@ Parser::Arg Parser::getFullArg(char left, char right, bool
allow_escaping)
} else {
while (good()) {
t = get_token();
+ // honor grouping
+ if (left != '{' && t.cat() == catBegin) {
+ ++group_level;
+ continue;
+ }
+ if (left != '{' && t.cat() == catEnd) {
+ --group_level;
+ continue;
+ }
// Ignore comments
if (t.cat() == catComment) {
if (!t.cs().empty())
@@ -511,13 +521,15 @@ Parser::Arg Parser::getFullArg(char left, char right,
bool allow_escaping)
continue;
}
if (allow_escaping) {
- if (t.cat() != catEscape && t.character() ==
right)
+ if (t.cat() != catEscape && t.character() ==
right
+ && group_level == 0)
break;
} else {
if (t.character() == right) {
if (t.cat() == catEscape)
result += '\\';
- break;
+ if (group_level == 0)
+ break;
}
}
result += t.asInput();