[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 06:54:49 PDT 2017
krasimir created this revision.
Herald added a subscriber: klimek.
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
}
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,6 +201,12 @@
" 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"
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1570,7 +1570,7 @@
const FormatToken *NextNonComment = Current->getNextNonComment();
if (Current->is(TT_ConditionalExpr))
return prec::Conditional;
- if (NextNonComment && NextNonComment->is(tok::colon) &&
+ if (NextNonComment && Current->is(TT_SelectorName) &&
NextNonComment->is(TT_DictLiteral))
return prec::Assignment;
if (Current->is(TT_JsComputedPropertyName))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34749.104409.patch
Type: text/x-patch
Size: 1240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170628/f25720c1/attachment.bin>
More information about the cfe-commits
mailing list