[PATCH] D34749: [clang-format] Fix parsing of msg{field}-style proto options
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 28 07:01:09 PDT 2017
krasimir updated this revision to Diff 104410.
krasimir added a comment.
- Add a msg<field>-style test too
https://reviews.llvm.org/D34749
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestProto.cpp
Index: unittests/Format/FormatTestProto.cpp
===================================================================
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -201,13 +201,26 @@
" 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"
" 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"
+ "}");
+
verifyFormat("option (MyProto.options) = {\n"
" msg_field: <>\n"
" field_c: \"OK\",\n"
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1570,8 +1570,10 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34749.104410.patch
Type: text/x-patch
Size: 1886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170628/c27f62e1/attachment-0001.bin>
More information about the cfe-commits
mailing list