[clang-format] Fixup a case of text proto message attributes
authorKrasimir Georgiev <krasimir@google.com>
Mon, 19 Feb 2018 15:31:25 +0000 (15:31 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Mon, 19 Feb 2018 15:31:25 +0000 (15:31 +0000)
Summary: This patch fixes a case where a proto message attribute is wrongly identified as an text proto extension.

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D43465

llvm-svn: 325509

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestProto.cpp

index 75a3fdce80306c1e3911f323ebe8d2b6ac326c69..f56230ee88cd46836da8963277d10d7862e0684b 100644 (file)
@@ -375,6 +375,10 @@ private:
         //   (aaa) = aaa
         // ];
         //
+        // extensions 123 [
+        //   (aaa) = aaa
+        // ];
+        //
         // or text proto extensions (in options):
         //
         // option (Aaa.options) = {
@@ -394,6 +398,8 @@ private:
         Left->Type = TT_ArrayInitializerLSquare;
         if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
                                 tok::equal) &&
+            !Left->endsSequence(tok::l_square, tok::numeric_constant,
+                                tok::identifier) &&
             !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
           Left->Type = TT_ProtoExtensionLSquare;
           BindingIncrease = 10;
index 4c61ec1398f5b3f7d227a9d10681e69ec8bc794c..1d6b7502e0983e5b5c0fca8dc74d621fbe558bbc 100644 (file)
@@ -168,6 +168,16 @@ TEST_F(FormatTestProto, MessageFieldAttributes) {
                "    aaaaaaaaaaaaaaaa: true\n"
                "  }\n"
                "];");
+  verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.bbbb'];");
+  verifyFormat("extensions 20\n"
+               "    [(proto3.type) = 'Aaaa.bbbb', (aaa.Aaa) = 'aaa.bbb'];");
+  verifyFormat("extensions 123 [\n"
+               "  (aaa) = aaaa,\n"
+               "  (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
+               "    aaaaaaaaaaaaaaaaa: true,\n"
+               "    aaaaaaaaaaaaaaaa: true\n"
+               "  }\n"
+               "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {