[PATCH] D47870: [clang-format] Consider tok::hashhash in python-style comments

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 7 02:53:20 PDT 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334179: [clang-format] Consider tok::hashhash in python-style comments (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47870?vs=150275&id=150284#toc

Repository:
  rC Clang

https://reviews.llvm.org/D47870

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/FormatTokenLexer.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: lib/Format/FormatTokenLexer.cpp
===================================================================
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -334,7 +334,7 @@
 
 void FormatTokenLexer::tryParsePythonComment() {
   FormatToken *HashToken = Tokens.back();
-  if (HashToken->isNot(tok::hash))
+  if (!HashToken->isOneOf(tok::hash, tok::hashhash))
     return;
   // Turn the remainder of this line into a comment.
   const char *CommentBegin =
Index: lib/Format/BreakableToken.cpp
===================================================================
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -44,7 +44,8 @@
                                             const FormatStyle &Style) {
   static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", "//",
                                                     "//!"};
-  static const char *const KnownTextProtoPrefixes[] = {"//", "#"};
+  static const char *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###",
+                                                       "####"};
   ArrayRef<const char *> KnownPrefixes(KnownCStylePrefixes);
   if (Style.Language == FormatStyle::LK_TextProto)
     KnownPrefixes = KnownTextProtoPrefixes;
Index: unittests/Format/FormatTestTextProto.cpp
===================================================================
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -347,6 +347,28 @@
                "cccccccccccccccccccccccc: 3849");
 }
 
+TEST_F(FormatTestTextProto, UnderstandsHashHashComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  EXPECT_EQ("aaa: 100\n"
+            "##this is a double-hash comment.\n"
+            "bb: 100\n"
+            "## another double-hash comment.\n"
+            "### a triple-hash comment\n"
+            "cc: 200\n"
+            "#### a quadriple-hash comment\n"
+            "dd: 100\n",
+            format("aaa: 100\n"
+                   "##this is a double-hash comment.\n"
+                   "bb: 100\n"
+                   "## another double-hash comment.\n"
+                   "### a triple-hash comment\n"
+                   "cc: 200\n"
+                   "#### a quadriple-hash comment\n"
+                   "dd: 100\n",
+                   Style));
+}
+
 TEST_F(FormatTestTextProto, FormatsExtensions) {
   verifyFormat("[type] { key: value }");
   verifyFormat("[type] {\n"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47870.150284.patch
Type: text/x-patch
Size: 2522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180607/4ad525b3/attachment.bin>


More information about the cfe-commits mailing list