summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-08-15 05:00:35 +0000
committerDaniel Jasper <djasper@google.com>2014-08-15 05:00:35 +0000
commit497d9fdcf8255d0d5b6164e06dac834510c55663 (patch)
tree10f7a145d8032134907f87b8081af8d12af7e231
parente3981b8faca21fa3212177e2e41eb1aa5bc7da6b (diff)
downloadbcm5719-llvm-497d9fdcf8255d0d5b6164e06dac834510c55663.tar.gz
bcm5719-llvm-497d9fdcf8255d0d5b6164e06dac834510c55663.zip
clang-format: [proto] Understand text-format nesting without :
Before: option (MyProto.options) = { field_c : "OK" msg_field{field_d : 123} }; After: option (MyProto.options) = { field_c : "OK" msg_field{field_d : 123} }; (Note that the colon after "msg_field" is optional). llvm-svn: 215692
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp10
-rw-r--r--clang/unittests/Format/FormatTestProto.cpp5
2 files changed, 11 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 47bfb986c29..0ac30a76ff4 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -311,10 +311,12 @@ private:
if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))
return false;
updateParameterCount(Left, CurrentToken);
- if (CurrentToken->is(tok::colon)) {
- if (CurrentToken->getPreviousNonComment()->is(tok::identifier))
- CurrentToken->getPreviousNonComment()->Type = TT_SelectorName;
- Left->Type = TT_DictLiteral;
+ if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
+ FormatToken *Previous = CurrentToken->getPreviousNonComment();
+ if (Previous->is(tok::identifier))
+ Previous->Type = TT_SelectorName;
+ if (CurrentToken->is(tok::colon))
+ Left->Type = TT_DictLiteral;
}
if (!consumeToken())
return false;
diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp
index 3ff38eab024..a56feedf80b 100644
--- a/clang/unittests/Format/FormatTestProto.cpp
+++ b/clang/unittests/Format/FormatTestProto.cpp
@@ -119,6 +119,11 @@ TEST_F(FormatTestProto, FormatsOptions) {
" field_c: \"OK\"\n"
" msg_field: {field_d: 123}\n"
"};");
+
+ verifyFormat("option (MyProto.options) = {\n"
+ " field_c: \"OK\"\n"
+ " msg_field{field_d: 123}\n"
+ "};");
}
TEST_F(FormatTestProto, FormatsService) {
OpenPOWER on IntegriCloud