krasimir created this revision. 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.
https://reviews.llvm.org/D36217 Files: lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTestProto.cpp Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -356,6 +356,11 @@ " }\n" " field_g: OK\n" ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " data1 <key1: value1>\n" + " data2 {key2: value2}\n" + ">;"); } TEST_F(FormatTestProto, FormatsService) { Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1450,6 +1450,15 @@ 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
Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -356,6 +356,11 @@ " }\n" " field_g: OK\n" ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " data1 <key1: value1>\n" + " data2 {key2: value2}\n" + ">;"); } TEST_F(FormatTestProto, FormatsService) { Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1450,6 +1450,15 @@ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits