tex2lyx: honor grouping in optional arguments.

E.g., \cite[{a literal ] character}]{key}
This commit is contained in:
Juergen Spitzmueller 2018-03-09 13:14:13 +01:00
parent 0513622fd0
commit cba38881d6

View File

@ -494,6 +494,7 @@ Parser::Arg Parser::getFullArg(char left, char right, bool allow_escaping)
if (! good()) if (! good())
return make_pair(false, string()); return make_pair(false, string());
int group_level = 0;
string result; string result;
Token t = get_token(); Token t = get_token();
@ -504,6 +505,15 @@ Parser::Arg Parser::getFullArg(char left, char right, bool allow_escaping)
} else { } else {
while (good()) { while (good()) {
t = get_token(); t = get_token();
// honor grouping
if (left != '{' && t.cat() == catBegin) {
++group_level;
continue;
}
if (left != '{' && t.cat() == catEnd) {
--group_level;
continue;
}
// Ignore comments // Ignore comments
if (t.cat() == catComment) { if (t.cat() == catComment) {
if (!t.cs().empty()) if (!t.cs().empty())
@ -511,13 +521,15 @@ Parser::Arg Parser::getFullArg(char left, char right, bool allow_escaping)
continue; continue;
} }
if (allow_escaping) { if (allow_escaping) {
if (t.cat() != catEscape && t.character() == right) if (t.cat() != catEscape && t.character() == right
&& group_level == 0)
break; break;
} else { } else {
if (t.character() == right) { if (t.character() == right) {
if (t.cat() == catEscape) if (t.cat() == catEscape)
result += '\\'; result += '\\';
break; if (group_level == 0)
break;
} }
} }
result += t.asInput(); result += t.asInput();