[clang-format] Fix parsing of <>-style proto options

Summary:
This patch fixes the parsing of proto option fields like `option op = <...>`.
Previously the parser did not enter the right code path inside the angle braces,
causing the contents to be split into several unwrapped lines inside.

I'll just go ahead and commit this since it's a straightforward bugfix.

Reviewers: djasper, klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D36217

llvm-svn: 309937
This commit is contained in:
Krasimir Georgiev 2017-08-03 13:43:45 +00:00
parent 55aebd689e
commit fa4dbb6820
2 changed files with 14 additions and 0 deletions

View File

@ -1450,6 +1450,15 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
nextToken(); nextToken();
parseBracedList(); parseBracedList();
break; break;
case tok::less:
if (Style.Language == FormatStyle::LK_Proto) {
nextToken();
parseBracedList(/*ContinueOnSemicolons=*/false,
/*ClosingBraceKind=*/tok::greater);
} else {
nextToken();
}
break;
case tok::semi: case tok::semi:
// JavaScript (or more precisely TypeScript) can have semicolons in braced // JavaScript (or more precisely TypeScript) can have semicolons in braced
// lists (in so-called TypeMemberLists). Thus, the semicolon cannot be // lists (in so-called TypeMemberLists). Thus, the semicolon cannot be

View File

@ -356,6 +356,11 @@ TEST_F(FormatTestProto, FormatsOptions) {
" }\n" " }\n"
" field_g: OK\n" " field_g: OK\n"
">;"); ">;");
verifyFormat("option (MyProto.options) = <\n"
" data1 <key1: value1>\n"
" data2 {key2: value2}\n"
">;");
} }
TEST_F(FormatTestProto, FormatsService) { TEST_F(FormatTestProto, FormatsService) {