[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
Thu Jun 29 06:31:00 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL306672: [clang-format] Fix parsing of msg{field}-style proto options (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D34749?vs=104410&id=104632#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34749

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/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;
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -201,14 +201,27 @@
                "  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"
                "  msg_field: <field_d: 123>\n"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34749.104632.patch
Type: text/x-patch
Size: 1994 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170629/6f34535c/attachment.bin>


More information about the cfe-commits mailing list