[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 07/20] qapi/parser: add semantic 'kind' parameter to QAPIDoc.
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 07/20] qapi/parser: add semantic 'kind' parameter to QAPIDoc.Section |
Date: |
Thu, 16 May 2024 08:18:10 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
John Snow <jsnow@redhat.com> writes:
> When iterating all_sections, this is helpful to be able to distinguish
> "members" from "features"; the only other way to do so is to
> cross-reference these sections against QAPIDoc.args or QAPIDoc.features,
> but if the desired end goal for QAPIDoc is to remove everything except
> all_sections, we need *something* accessible to distinguish them.
>
> To keep types simple, add this semantic parameter to the base Section
> and not just ArgSection; we can use this to filter out paragraphs and
> tagged sections, too.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> scripts/qapi/parser.py | 25 ++++++++++++++++---------
> 1 file changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
> index 161768b8b96..cf4cbca1c1f 100644
> --- a/scripts/qapi/parser.py
> +++ b/scripts/qapi/parser.py
> @@ -613,21 +613,27 @@ class QAPIDoc:
>
> class Section:
> # pylint: disable=too-few-public-methods
> - def __init__(self, info: QAPISourceInfo,
> - tag: Optional[str] = None):
> + def __init__(
> + self,
> + info: QAPISourceInfo,
> + tag: Optional[str] = None,
> + kind: str = 'paragraph',
> + ):
> # section source info, i.e. where it begins
> self.info = info
> # section tag, if any ('Returns', '@name', ...)
> self.tag = tag
> # section text without tag
> self.text = ''
> + # section type - {paragraph, feature, member, tagged}
> + self.kind = kind
Hmm. .kind is almost redundant with .tag.
Untagged section: .kind is 'paragraph', .tag is None
Member description: .kind is 'member', .tag matches @NAME
Feature description: .kind is 'feature', .tag matches @NAME
Tagged section: .kind is 'tagged', .tag matches
r'Returns|Errors|Since|Notes?|Examples?|TODO'
.kind can directly be derived from .tag except for member and feature
descriptions. And you want to tell these two apart in a straightforward
manner in later patches, as you explain in your commit message.
If .kind is 'member' or 'feature', then self must be an ArgSection.
Worth a comment? An assertion?
Some time back, I considered changing .tag for member and feature
descriptions to suitable strings, like your 'member' and 'feature', and
move the member / feature name into ArgSection. I didn't, because the
benefit wasn't worth the churn at the time. Perhaps it's worth it now.
Would it result in simpler code than your solution?
Terminology nit: the section you call 'paragraph' isn't actually a
paragraph: it could be several paragraphs. Best to call it 'untagged',
as in .ensure_untagged_section().
>
> def append_line(self, line: str) -> None:
> self.text += line + '\n'
>
> class ArgSection(Section):
> - def __init__(self, info: QAPISourceInfo, tag: str):
> - super().__init__(info, tag)
> + def __init__(self, info: QAPISourceInfo, tag: str, kind: str):
> + super().__init__(info, tag, kind)
> self.member: Optional['QAPISchemaMember'] = None
>
> def connect(self, member: 'QAPISchemaMember') -> None:
[...]
- Re: [PATCH 06/20] qapi/parser: fix comment parsing immediately following a doc block, (continued)
- [PATCH 09/20] qapi/parser: add undocumented stub members to all_sections, John Snow, 2024/05/14
- [PATCH 05/20] qapi/parser: adjust info location for doc body section, John Snow, 2024/05/14
- [PATCH 08/20] qapi/parser: differentiate intro and outro paragraphs, John Snow, 2024/05/14
- [PATCH 11/20] qapi/schema: add doc_visible property to QAPISchemaDefinition, John Snow, 2024/05/14
- [PATCH 13/20] docs/qapidoc: fix nested parsing under untagged sections, John Snow, 2024/05/14
- [PATCH 07/20] qapi/parser: add semantic 'kind' parameter to QAPIDoc.Section, John Snow, 2024/05/14
- Re: [PATCH 07/20] qapi/parser: add semantic 'kind' parameter to QAPIDoc.Section,
Markus Armbruster <=
- [PATCH 10/20] qapi/schema: add __iter__ method to QAPISchemaVariants, John Snow, 2024/05/14
- [PATCH 12/20] qapi/source: allow multi-line QAPISourceInfo advancing, John Snow, 2024/05/14
- [PATCH 15/20] qapi: remove developer factoring comments from QAPI doc blocks, John Snow, 2024/05/14
- [PATCH 16/20] qapi: rewrite StatsFilter comment, John Snow, 2024/05/14
- [PATCH 14/20] qapi: fix non-compliant JSON examples, John Snow, 2024/05/14
- [PATCH 17/20] qapi: rewrite BlockExportOptions doc block, John Snow, 2024/05/14
- [PATCH 18/20] qapi: ensure all errors sections are uniformly typset, John Snow, 2024/05/14
- [PATCH 19/20] qapi: convert "Note" sections to plain rST, John Snow, 2024/05/14
- [PATCH 20/20] qapi: convert "Example" sections to rST, John Snow, 2024/05/14