mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
tex2lyx: honor grouping in optional arguments.
E.g., \cite[{a literal ] character}]{key}
(cherry picked from commit cba38881d6
)
This commit is contained in:
parent
ce2e155490
commit
590185d3ef
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user