diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-08-03 13:43:45 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-08-03 13:43:45 +0000 |
commit | fa4dbb682013751dddd228c553a3ff4f2dff2401 (patch) | |
tree | a02cf8ca4a9bff3e0e38d38303344a328195cf2a | |
parent | 55aebd689ea880a65e8720be73519dc03016409c (diff) | |
download | bcm5719-llvm-fa4dbb682013751dddd228c553a3ff4f2dff2401.tar.gz bcm5719-llvm-fa4dbb682013751dddd228c553a3ff4f2dff2401.zip |
[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
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 9 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestProto.cpp | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 753eada8f1b..32853dc209e 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1450,6 +1450,15 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons, 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 diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index 639da87c6ea..ca26c543959 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -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) { |