r306672 - [clang-format] Fix parsing of msg{field}-style proto options
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 29 06:30:41 PDT 2017
Author: krasimir
Date: Thu Jun 29 06:30:41 2017
New Revision: 306672
URL: http://llvm.org/viewvc/llvm-project?rev=306672&view=rev
Log:
[clang-format] Fix parsing of msg{field}-style proto options
Summary:
This patch makes the `{` in `msg_field{field: OK}` in a proto option scope be
treated as an assignment operator. Previosly the added test case was formatted
as:
```
option (MyProto.options) = {
field_a: OK
field_b{field_c: OK} field_d: OKOKOK field_e: OK
}
```
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D34749
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=306672&r1=306671&r2=306672&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jun 29 06:30:41 2017
@@ -1570,8 +1570,10 @@ private:
const FormatToken *NextNonComment = Current->getNextNonComment();
if (Current->is(TT_ConditionalExpr))
return prec::Conditional;
- if (NextNonComment && NextNonComment->is(tok::colon) &&
- NextNonComment->is(TT_DictLiteral))
+ if (NextNonComment && Current->is(TT_SelectorName) &&
+ (NextNonComment->is(TT_DictLiteral) ||
+ (Style.Language == FormatStyle::LK_Proto &&
+ NextNonComment->is(tok::less))))
return prec::Assignment;
if (Current->is(TT_JsComputedPropertyName))
return prec::Assignment;
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=306672&r1=306671&r2=306672&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Jun 29 06:30:41 2017
@@ -201,6 +201,12 @@ TEST_F(FormatTestProto, FormatsOptions)
" field_c: \"OK\"\n"
" msg_field{field_d: 123}\n"
"};");
+ verifyFormat("option (MyProto.options) = {\n"
+ " field_a: OK\n"
+ " field_b{field_c: OK}\n"
+ " field_d: OKOKOK\n"
+ " field_e: OK\n"
+ "}");
// Support syntax with <> instead of {}.
verifyFormat("option (MyProto.options) = {\n"
@@ -209,6 +215,13 @@ TEST_F(FormatTestProto, FormatsOptions)
"};");
verifyFormat("option (MyProto.options) = {\n"
+ " field_a: OK\n"
+ " field_b<field_c: OK>\n"
+ " field_d: OKOKOK\n"
+ " field_e: OK\n"
+ "}");
+
+ verifyFormat("option (MyProto.options) = {\n"
" msg_field: <>\n"
" field_c: \"OK\",\n"
" msg_field: <field_d: 123>\n"
More information about the cfe-commits
mailing list