On Tue, 08 Jan 2019, Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx> wrote:
The concept is not fully realized yet, but now there is actual recursion. The
immediate effect of this is that nested structures are now documented as
expected.
---
hawkmoth/hawkmoth.py | 27 ++++++++++++++-------------
test/union.stdout | 2 +-
2 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/hawkmoth/hawkmoth.py b/hawkmoth/hawkmoth.py
index d6075f9..49f1eb1 100755
--- a/hawkmoth/hawkmoth.py
+++ b/hawkmoth/hawkmoth.py
@@ -171,19 +171,8 @@ def _recursive_parse(comments, cursor, nest, **options):
nest += 1
for c in cursor.get_children():
- if c.kind != CursorKind.FIELD_DECL:
- # FIXME: Recurse for new structure or union.
- pass
-
if c.hash in comments:
- comment = comments[c.hash]
- text = comment.spelling
- fmt = docstr.Type.MEMBER
- name = c.spelling
- ttype = c.type.spelling
-
- result.extend(_result(comment, cursor=cursor, fmt=fmt,
nest=nest,
- name=name, ttype=ttype, compat=compat))
+ result.extend(_recursive_parse(comments, c, nest, **options))
return result
@@ -205,10 +194,16 @@ def _recursive_parse(comments, cursor, nest, **options):
name = c.spelling
result.extend(_result(comment, cursor=cursor, fmt=fmt,
- nest=nest, name=name, compat=compat))
+ nest=nest, name=name, compat=compat))
return result
+ if cursor.kind == CursorKind.FIELD_DECL:
+ fmt = docstr.Type.MEMBER
+
+ return _result(comment, cursor=cursor, fmt=fmt,
+ nest=nest, name=name, ttype=ttype, compat=compat)
+
if cursor.kind == CursorKind.FUNCTION_DECL:
# FIXME: check args against comment
# FIXME: children may contain extra stuff if the return type is a
@@ -226,6 +221,12 @@ def _recursive_parse(comments, cursor, nest, **options):
return _result(comment, cursor=cursor, fmt=fmt, nest=nest,
name=name, ttype=ttype, args=args, compat=compat)
+ # FIXME: If we reach here, nothing matched. This is a warning or even
error
+ # and it should be logged, but it should also return an empty list so
that
+ # it doesn't break. I.e. the parser needs to pass warnings and errors to
the
+ # Sphinx extension.
+ return []
+
# return a list of (comment, metadata) tuples
# options - dictionary with directive options
def parse(filename, **options):
diff --git a/test/union.stdout b/test/union.stdout
index 8298e1f..a6cc7b5 100644
--- a/test/union.stdout
+++ b/test/union.stdout
@@ -14,7 +14,7 @@
int member 2.
- .. c:member:: struct _baz _baz
+ .. c:type:: struct _baz
struct member.
--
2.20.1