r215692 - clang-format: [proto] Understand text-format nesting without :
Daniel Jasper
djasper at google.com
Thu Aug 14 22:00:35 PDT 2014
Author: djasper
Date: Fri Aug 15 00:00:35 2014
New Revision: 215692
URL: http://llvm.org/viewvc/llvm-project?rev=215692&view=rev
Log:
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).
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=215692&r1=215691&r2=215692&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Aug 15 00:00:35 2014
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=215692&r1=215691&r2=215692&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Fri Aug 15 00:00:35 2014
@@ -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) {
More information about the cfe-commits
mailing list