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
This commit is contained in:
Daniel Jasper 2014-08-15 05:00:35 +00:00
parent e3981b8fac
commit 497d9fdcf8
2 changed files with 11 additions and 4 deletions

View File

@ -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;

View File

@ -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) {