[hawkmoth] Re: [PATCH] parser: fix placement of array brackets

  • From: Jani Nikula <jani@xxxxxxxxxx>
  • To: Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx>, hawkmoth mailing list <hawkmoth@xxxxxxxxxxxxx>
  • Date: Tue, 15 Sep 2020 22:25:18 +0300

On Mon, 14 Sep 2020, Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx> wrote:

Clang understandably splits `char test[10]` in a type `char [10]` and a
variable name `test`. However Sphinx expects the C notation in the
`c:var::` directive so we need to fix that. This was not an issue in
Sphinx 2.

Fixes #17.

Long time no see; thanks for the patch!

---

Hi Jani,

Please note that I have _not_ tested this on Sphinx 2. It's possible
that Sphinx 2 complains about this just like 3 complained about the
previous notation.

It does not flat out fail, but it renders the whole "const char
array[10]" part in bold, and cross references to "array" don't seem to
work properly.

Need to think about the Sphinx 2 backwards compatibility issue a bit.

BR,
Jani.




Cheers,
Bruno


 hawkmoth/parser.py | 6 ++++++
 test/variable.c    | 5 +++++
 test/variable.rst  | 5 +++++
 3 files changed, 16 insertions(+)

diff --git a/hawkmoth/parser.py b/hawkmoth/parser.py
index d063217..83b67c0 100644
--- a/hawkmoth/parser.py
+++ b/hawkmoth/parser.py
@@ -169,6 +169,12 @@ def _recursive_parse(comments, cursor, nest, compat):
     elif cursor.kind == CursorKind.VAR_DECL:
         fmt = docstr.Type.VAR
 
+        # The dimensions should be applied to the name, not the type.
+        dims = ttype.rsplit(' ', 1)[-1]
+        if dims.startswith('[') and dims.endswith(']'):
+            ttype = ttype.rsplit(' ', 1)[0]
+            name = name + dims
+
         return _result(comment, cursor=cursor, fmt=fmt,
                        nest=nest, name=name, ttype=ttype, compat=compat)
 
diff --git a/test/variable.c b/test/variable.c
index 8860339..3eba8b9 100644
--- a/test/variable.c
+++ b/test/variable.c
@@ -2,3 +2,8 @@
  * This is a variable document.
  */
 static int sheesh;
+
+/**
+ * This is a sized array.
+ */
+const char array[10];
diff --git a/test/variable.rst b/test/variable.rst
index 4efaece..bcf7bad 100644
--- a/test/variable.rst
+++ b/test/variable.rst
@@ -3,3 +3,8 @@
 
    This is a variable document.
 
+
+.. c:var:: const char array[10]
+
+   This is a sized array.
+
-- 
2.28.0

Other related posts: