r309937 - [clang-format] Fix parsing of <>-style proto options
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 3 06:43:45 PDT 2017
Author: krasimir
Date: Thu Aug 3 06:43:45 2017
New Revision: 309937
URL: http://llvm.org/viewvc/llvm-project?rev=309937&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=309937&r1=309936&r2=309937&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Aug 3 06:43:45 2017
@@ -1450,6 +1450,15 @@ bool UnwrappedLineParser::parseBracedLis
nextToken();
parseBracedList();
break;
+ case tok::less:
+ if (Style.Language == FormatStyle::LK_Proto) {
+ nextToken();
+ parseBracedList(/*ContinueOnSemicolons=*/false,
+ /*ClosingBraceKind=*/tok::greater);
+ } else {
+ nextToken();
+ }
+ break;
case tok::semi:
// JavaScript (or more precisely TypeScript) can have semicolons in braced
// lists (in so-called TypeMemberLists). Thus, the semicolon cannot be
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=309937&r1=309936&r2=309937&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Aug 3 06:43:45 2017
@@ -356,6 +356,11 @@ TEST_F(FormatTestProto, FormatsOptions)
" }\n"
" field_g: OK\n"
">;");
+
+ verifyFormat("option (MyProto.options) = <\n"
+ " data1 <key1: value1>\n"
+ " data2 {key2: value2}\n"
+ ">;");
}
TEST_F(FormatTestProto, FormatsService) {
More information about the cfe-commits
mailing list