[PATCH] D43294: [clang-format] Recognize percents as format specifiers in protos

2018-02-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325159: [clang-format] Recognize percents as format 
specifiers in protos (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43294?vs=134232=134286#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43294

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) 
&&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43294: [clang-format] Recognize percents as format specifiers in protos

2018-02-14 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Ok.. I guess ;)


Repository:
  rC Clang

https://reviews.llvm.org/D43294



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43294: [clang-format] Recognize percents as format specifiers in protos

2018-02-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
krasimir added a reviewer: djasper.
Herald added subscribers: cfe-commits, klimek.

Frequently, a percent in protos denotes a formatting specifier for string 
replacement.
Thus it is desirable to keep the percent together with what follows after it.


Repository:
  rC Clang

https://reviews.llvm.org/D43294

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) 
&&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits