[hawkmoth] [PATCH v2 06/15] util: clean up white space from generated output

  • From: Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx>
  • To: hawkmoth@xxxxxxxxxxxxx
  • Date: Sat, 19 Jan 2019 23:52:20 +0100

The new behaviour is much more consistent regarding new lines. It also
trims trailing white space that was previously abundant. Unfortunately
this breaks just about every test case we have.
---
 hawkmoth/util/docstr.py            | 20 +++++++++-----------
 test/compat-javadoc-basic.stdout   |  7 +++----
 test/compat-javadoc-liberal.stdout |  9 ++++-----
 test/compat-kernel-doc.stdout      | 15 +++++++--------
 test/compat.stdout                 |  3 +--
 test/doc.stdout                    |  1 -
 test/enum.stdout                   |  6 +++---
 test/example-10-macro.stdout       | 10 +++++-----
 test/example-20-variable.stdout    |  8 ++++----
 test/example-30-typedef.stdout     |  2 +-
 test/example-40-enum.stdout        |  6 +++---
 test/example-50-struct.stdout      | 10 +++++-----
 test/example-70-function.stdout    |  4 ++--
 test/example-80-compat.stdout      | 20 ++++++++++----------
 test/example-90-generic.stdout     |  1 -
 test/function-like-macro.stdout    |  4 ++--
 test/function.stdout               |  2 +-
 test/simple-macro.stdout           |  2 +-
 test/struct.stdout                 |  8 ++++----
 test/typedef-enum.stdout           |  8 ++++----
 test/typedef-struct.stdout         |  8 ++++----
 test/typedef.stdout                |  2 +-
 test/union.stdout                  |  8 ++++----
 test/variable.stdout               |  2 +-
 24 files changed, 79 insertions(+), 87 deletions(-)

diff --git a/hawkmoth/util/docstr.py b/hawkmoth/util/docstr.py
index 3995ba3..4886e8f 100644
--- a/hawkmoth/util/docstr.py
+++ b/hawkmoth/util/docstr.py
@@ -29,13 +29,13 @@ class Type(Enum):
 # directive lines.
 _doc_fmt = {
     Type.TEXT:       (0, '\n{text}\n'),
-    Type.VAR:        (1, '.. c:var:: {ttype} {name}\n\n{text}\n'),
-    Type.TYPE:       (1, '.. c:type:: {name}\n\n{text}\n'),
-    Type.ENUM_VAL:   (1, '.. c:macro:: {name}\n\n{text}\n'),
-    Type.MEMBER:     (1, '.. c:member:: {ttype} {parent}.{name}\n\n{text}\n'),
-    Type.MACRO:      (1, '.. c:macro:: {name}\n\n{text}\n'),
-    Type.MACRO_FUNC: (1, '.. c:function:: {name}({args})\n\n{text}\n'),
-    Type.FUNC:       (1, '.. c:function:: {ttype} {name}({args})\n\n{text}\n')
+    Type.VAR:        (1, '\n.. c:var:: {ttype} {name}\n\n{text}\n'),
+    Type.TYPE:       (1, '\n.. c:type:: {name}\n\n{text}\n'),
+    Type.ENUM_VAL:   (1, '\n.. c:macro:: {name}\n\n{text}\n'),
+    Type.MEMBER:     (1, '\n.. c:member:: {ttype} 
{parent}.{name}\n\n{text}\n'),
+    Type.MACRO:      (1, '\n.. c:macro:: {name}\n\n{text}\n'),
+    Type.MACRO_FUNC: (1, '\n.. c:function:: {name}({args})\n\n{text}\n'),
+    Type.FUNC:       (1, '\n.. c:function:: {ttype} 
{name}({args})\n\n{text}\n')
 }
 
 def _strip(comment):
@@ -47,9 +47,7 @@ def _strip(comment):
     comment = re.sub(r'(?m)^[ \t]*\*?[ \t]?', '', comment)
     # Strip leading blank lines.
     comment = re.sub(r'^[\n]*', '', comment)
-    # End in exactly one newline.
-    comment = re.sub(r"[\n]*$", "", comment) + "\n"
-    return comment
+    return comment.strip()
 
 def is_doc(comment):
     """Test if comment is a C documentation comment."""
@@ -67,7 +65,7 @@ def nest(text, nest):
     Returns:
         str: Indented reST documentation string.
     """
-    return re.sub('(?m)^', '   ' * nest, text)
+    return re.sub('(?m)^(?!$)', '   ' * nest, text)
 
 def generate(text, fmt=Type.TEXT, parent=None, name=None,
              ttype=None, args=None, transform=None):
diff --git a/test/compat-javadoc-basic.stdout b/test/compat-javadoc-basic.stdout
index 752e14b..2cd51be 100644
--- a/test/compat-javadoc-basic.stdout
+++ b/test/compat-javadoc-basic.stdout
@@ -8,17 +8,16 @@
 
 .. c:function:: int foo(int quick)
 
-   
+
    :param quick: brown fox
-   
+
    :return: quick brown fox
    @random quick brown fox
-   
+
 
 .. c:function:: int kerneldoc(int quick)
 
    @quick: quick brown fox
    @return: quick brown fox
    @random: quick brown fox
-   
 
diff --git a/test/compat-javadoc-liberal.stdout 
b/test/compat-javadoc-liberal.stdout
index 94e9f7a..e2c52c6 100644
--- a/test/compat-javadoc-liberal.stdout
+++ b/test/compat-javadoc-liberal.stdout
@@ -9,18 +9,17 @@
 
 .. c:function:: int foo(int quick)
 
-   
+
    :param quick: brown fox
-   
+
    :return: quick brown fox
-   
+
    :random: quick brown fox
-   
+
 
 .. c:function:: int kerneldoc(int quick)
 
    @quick: quick brown fox
    @return: quick brown fox
    @random: quick brown fox
-   
 
diff --git a/test/compat-kernel-doc.stdout b/test/compat-kernel-doc.stdout
index 009826d..e2289fd 100644
--- a/test/compat-kernel-doc.stdout
+++ b/test/compat-kernel-doc.stdout
@@ -9,15 +9,14 @@
    @param quick brown fox
    @return quick brown fox
    @random quick brown fox
-   
+
 
 .. c:function:: int kerneldoc(int quick)
 
-   
-   :param quick: quick brown fox
-   
-   :return: quick brown fox
-   
-   :param random: quick brown fox
-   
+
+   :param quick: quick brown fox
+
+   :return: quick brown fox
+
+   :param random: quick brown fox
 
diff --git a/test/compat.stdout b/test/compat.stdout
index d2261d8..e315d87 100644
--- a/test/compat.stdout
+++ b/test/compat.stdout
@@ -9,12 +9,11 @@
    @param quick brown fox
    @return quick brown fox
    @random quick brown fox
-   
+
 
 .. c:function:: int kerneldoc(int quick)
 
    @quick: quick brown fox
    @return: quick brown fox
    @random: quick brown fox
-   
 
diff --git a/test/doc.stdout b/test/doc.stdout
index 650c4c5..1ebad17 100644
--- a/test/doc.stdout
+++ b/test/doc.stdout
@@ -1,4 +1,3 @@
 
 This is a top level comment.
 
-
diff --git a/test/enum.stdout b/test/enum.stdout
index 8b2698b..fa6e8fe 100644
--- a/test/enum.stdout
+++ b/test/enum.stdout
@@ -1,15 +1,15 @@
+
 .. c:type:: enum foo
 
    Enum doc.
-   
+
 
 .. c:macro:: bar
 
    Enumeration comment.
-   
+
 
 .. c:macro:: baz
 
    Another.
-   
 
diff --git a/test/example-10-macro.stdout b/test/example-10-macro.stdout
index 5b98ff1..c645ebb 100644
--- a/test/example-10-macro.stdout
+++ b/test/example-10-macro.stdout
@@ -1,20 +1,20 @@
+
 .. c:macro:: FAILURE
 
    Failure status.
-   
+
 
 .. c:function:: DIE()
 
    Terminate immediately with failure status.
-   
+
    See :c:macro:`FAILURE`.
-   
+
 
 .. c:function:: ARRAY_SIZE(array)
 
    Get the number of elements in an array.
-   
+
    :param array: An array
    :return: Array size
-   
 
diff --git a/test/example-20-variable.stdout b/test/example-20-variable.stdout
index 0cb0c03..17b7c7b 100644
--- a/test/example-20-variable.stdout
+++ b/test/example-20-variable.stdout
@@ -1,12 +1,12 @@
+
 .. c:var:: const int meaning_of_life
 
    The name says it all.
-   
+
 
 .. c:var:: struct list * entries
 
    The list of entries.
-   
-   Use :c:func:`frob` to frobnicate, always in :c:macro:`MODE_PRIMARY` mode.
-   
+
+   Use :c:func:`frob` to frobnicate, always in :c:macro:`MODE_PRIMARY` mode.
 
diff --git a/test/example-30-typedef.stdout b/test/example-30-typedef.stdout
index ba77421..4314f1b 100644
--- a/test/example-30-typedef.stdout
+++ b/test/example-30-typedef.stdout
@@ -1,5 +1,5 @@
+
 .. c:type:: list_data_t
 
    Typedef documentation.
-   
 
diff --git a/test/example-40-enum.stdout b/test/example-40-enum.stdout
index 6e5476d..834fb02 100644
--- a/test/example-40-enum.stdout
+++ b/test/example-40-enum.stdout
@@ -1,15 +1,15 @@
+
 .. c:type:: enum mode
 
    Frobnication modes for :c:func:`frob`.
-   
+
 
 .. c:macro:: MODE_PRIMARY
 
    The primary frobnication mode.
-   
+
 
 .. c:macro:: MODE_SECONDARY
 
    The secondary frobnication mode.
-   
 
diff --git a/test/example-50-struct.stdout b/test/example-50-struct.stdout
index 77e6361..4399019 100644
--- a/test/example-50-struct.stdout
+++ b/test/example-50-struct.stdout
@@ -1,15 +1,15 @@
+
 .. c:type:: struct list
 
    Linked list node.
-   
+
 
 .. c:member:: struct list * list.next
 
-   Next node. 
-   
+   Next node.
+
 
 .. c:member:: int list.data
 
-   Data. 
-   
+   Data.
 
diff --git a/test/example-70-function.stdout b/test/example-70-function.stdout
index aaed616..0bdcdb0 100644
--- a/test/example-70-function.stdout
+++ b/test/example-70-function.stdout
@@ -1,10 +1,10 @@
+
 .. c:function:: int frob(struct list * list, enum mode mode)
 
    List frobnicator.
-   
+
    :param list: The list to frob.
    :param mode: The frobnication mode.
    :return: 0 on success, non-zero error code on error.
    :since: v0.1
-   
 
diff --git a/test/example-80-compat.stdout b/test/example-80-compat.stdout
index cd53beb..b81e629 100644
--- a/test/example-80-compat.stdout
+++ b/test/example-80-compat.stdout
@@ -1,14 +1,14 @@
+
 .. c:function:: int frob2(struct list * list, enum mode mode)
 
    List frobnicator.
-   
-   
-   :param list: The list to frob.
-   
-   :param mode: The frobnication mode.
-   
-   :return: 0 on success, non-zero error code on error.
-   
-   :since: v0.1
-   
+
+
+   :param list: The list to frob.
+
+   :param mode: The frobnication mode.
+
+   :return: 0 on success, non-zero error code on error.
+
+   :since: v0.1
 
diff --git a/test/example-90-generic.stdout b/test/example-90-generic.stdout
index 42b0278..e185c21 100644
--- a/test/example-90-generic.stdout
+++ b/test/example-90-generic.stdout
@@ -4,4 +4,3 @@ constructs. They will be included as generic documentation 
comments, for
 example to describe the design of :c:type:`list` frobnication using
 :c:func:`frob`.
 
-
diff --git a/test/function-like-macro.stdout b/test/function-like-macro.stdout
index bc2dc3b..b9e37ba 100644
--- a/test/function-like-macro.stdout
+++ b/test/function-like-macro.stdout
@@ -1,10 +1,10 @@
+
 .. c:function:: FOO(bar, baz)
 
    A function-like macro.
-   
+
 
 .. c:function:: BAR()
 
    Another
-   
 
diff --git a/test/function.stdout b/test/function.stdout
index 4c95241..e3705ee 100644
--- a/test/function.stdout
+++ b/test/function.stdout
@@ -1,5 +1,5 @@
+
 .. c:function:: int foo(int bar, int baz)
 
    Foo function.
-   
 
diff --git a/test/simple-macro.stdout b/test/simple-macro.stdout
index 7e04d90..7532231 100644
--- a/test/simple-macro.stdout
+++ b/test/simple-macro.stdout
@@ -1,5 +1,5 @@
+
 .. c:macro:: FOO
 
    A simple macro.
-   
 
diff --git a/test/struct.stdout b/test/struct.stdout
index 92bb402..1c32b59 100644
--- a/test/struct.stdout
+++ b/test/struct.stdout
@@ -1,17 +1,17 @@
+
 .. c:type:: struct sample_struct
 
    This is a sample struct
-   
+
    Woohoo.
-   
+
 
 .. c:member:: int sample_struct.jesh
 
    member
-   
+
 
 .. c:member:: struct sample_struct * sample_struct.next
 
    foo next
-   
 
diff --git a/test/typedef-enum.stdout b/test/typedef-enum.stdout
index 831cb5e..9bbb62a 100644
--- a/test/typedef-enum.stdout
+++ b/test/typedef-enum.stdout
@@ -1,20 +1,20 @@
+
 .. c:type:: enum named
 
    named typedeffed enum
-   
+
 
 .. c:macro:: damn
 
    named enumeration
-   
+
 
 .. c:type:: unnamed_t
 
    unnamed typedeffed enum
-   
+
 
 .. c:macro:: shit
 
    unnamed enumeration
-   
 
diff --git a/test/typedef-struct.stdout b/test/typedef-struct.stdout
index fa381ec..41c414f 100644
--- a/test/typedef-struct.stdout
+++ b/test/typedef-struct.stdout
@@ -1,20 +1,20 @@
+
 .. c:type:: struct named
 
    named typedeffed struct
-   
+
 
 .. c:member:: int named.m
 
    named member
-   
+
 
 .. c:type:: typedef_struct
 
    unnamed typedeffed struct
-   
+
 
 .. c:member:: int typedef_struct.m
 
    unnamed member
-   
 
diff --git a/test/typedef.stdout b/test/typedef.stdout
index 83fd2dc..dca0a85 100644
--- a/test/typedef.stdout
+++ b/test/typedef.stdout
@@ -1,5 +1,5 @@
+
 .. c:type:: boo
 
    Typedef comment.
-   
 
diff --git a/test/union.stdout b/test/union.stdout
index 6821b30..40e1b95 100644
--- a/test/union.stdout
+++ b/test/union.stdout
@@ -1,20 +1,20 @@
+
 .. c:type:: union foo
 
    Union documentation.
-   
+
 
 .. c:member:: int foo.foo
 
    int member 1.
-   
+
 
 .. c:member:: int foo.bar
 
    int member 2.
-   
+
 
 .. c:member:: struct _baz foo._baz
 
    struct member.
-   
 
diff --git a/test/variable.stdout b/test/variable.stdout
index ddbeeb3..4efaece 100644
--- a/test/variable.stdout
+++ b/test/variable.stdout
@@ -1,5 +1,5 @@
+
 .. c:var:: int sheesh
 
    This is a variable document.
-   
 
-- 
2.20.1


Other related posts:

  • » [hawkmoth] [PATCH v2 06/15] util: clean up white space from generated output - Bruno Santos