Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javadoc: allow space before parameter direction indication #244

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/hawkmoth/ext/javadoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ class _param(_field_list):
_field_name = 'param'

def header(self):
mo = re.match(r'^(\[(?P<direction>[a-zA-Z, ]+)\])?(?P<sp1>\s*)(?P<name>([a-zA-Z0-9_]+|\.\.\.))(?P<sp2>\s*(?P<desc>.*))', # noqa: E501
mo = re.match(r'^((?P<sp0>\s*)\[(?P<direction>[a-zA-Z, ]+)\])?(?P<sp1>\s*)(?P<name>([a-zA-Z0-9_]+|\.\.\.))(?P<sp2>\s*(?P<desc>.*))', # noqa: E501
self.rest())
if mo is None:
# FIXME
yield ''
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we suppress the yield then? In fact, why are we using yield in this function at all?

Copy link
Owner Author

@jnikula jnikula Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the design (or lack thereof) is based on this loop:

def _process_docstring(app, lines, transform, options):
    if transform != app.config.hawkmoth_javadoc_transform:
        return

    lines[:] = [line for line in _convert(app=app, lines=lines)]

By having _convert() and anything it calls yield the stuff just works nicely, because the conversion of a single line may result in more than one line.

And rst being rst, it's better to emit the blank line if the conversion fails.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, my brain's fried right now tbh, but we only ever yield once per call of header(), right? Does yielding yield any gain in that case (pun intended)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, header() yields 1-4 lines, depending on the class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, though I don't think it makes a difference if we were to return in the cases where it yields only once. Anyway, the code is correct, and I get the argument of following a pattern 👍


direction = mo.group('direction')
name = mo.group('name')
Expand Down
Loading