|
42 | 42 | # @{section-name}: |
43 | 43 | # while trying to not match literal block starts like "example::" |
44 | 44 | # |
| 45 | +known_section_names = 'description|context|returns?|notes?|examples?' |
| 46 | +known_sections = KernRe(known_section_names, flags = re.I) |
45 | 47 | doc_sect = doc_com + \ |
46 | | - KernRe(r'\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$', |
47 | | - flags=re.I, cache=False) |
| 48 | + KernRe(r'\s*(\@[.\w]+|\@\.\.\.|' + known_section_names + r')\s*:([^:].*)?$', |
| 49 | + flags=re.I, cache=False) |
48 | 50 |
|
49 | 51 | doc_content = doc_com_body + KernRe(r'(.*)', cache=False) |
50 | 52 | doc_inline_start = KernRe(r'^\s*/\*\*\s*$', cache=False) |
@@ -115,7 +117,6 @@ def __init__(self, config, ln): |
115 | 117 | self.config = config |
116 | 118 |
|
117 | 119 | self._contents = [] |
118 | | - self.sectcheck = "" |
119 | 120 | self.prototype = "" |
120 | 121 |
|
121 | 122 | self.warnings = [] |
@@ -187,7 +188,6 @@ def dump_section(self, start_new=True): |
187 | 188 | self.parameterdescs[name] = contents |
188 | 189 | self.parameterdesc_start_lines[name] = self.new_start_line |
189 | 190 |
|
190 | | - self.sectcheck += name + " " |
191 | 191 | self.new_start_line = 0 |
192 | 192 |
|
193 | 193 | else: |
@@ -478,29 +478,20 @@ def create_parameter_list(self, ln, decl_type, args, |
478 | 478 | self.push_parameter(ln, decl_type, param, dtype, |
479 | 479 | arg, declaration_name) |
480 | 480 |
|
481 | | - def check_sections(self, ln, decl_name, decl_type, sectcheck): |
| 481 | + def check_sections(self, ln, decl_name, decl_type): |
482 | 482 | """ |
483 | 483 | Check for errors inside sections, emitting warnings if not found |
484 | 484 | parameters are described. |
485 | 485 | """ |
486 | | - |
487 | | - sects = sectcheck.split() |
488 | | - |
489 | | - for sx in range(len(sects)): # pylint: disable=C0200 |
490 | | - err = True |
491 | | - for param in self.entry.parameterlist: |
492 | | - if param == sects[sx]: |
493 | | - err = False |
494 | | - break |
495 | | - |
496 | | - if err: |
| 486 | + for section in self.entry.sections: |
| 487 | + if section not in self.entry.parameterlist and \ |
| 488 | + not known_sections.search(section): |
497 | 489 | if decl_type == 'function': |
498 | 490 | dname = f"{decl_type} parameter" |
499 | 491 | else: |
500 | 492 | dname = f"{decl_type} member" |
501 | | - |
502 | 493 | self.emit_msg(ln, |
503 | | - f"Excess {dname} '{sects[sx]}' description in '{decl_name}'") |
| 494 | + f"Excess {dname} '{section}' description in '{decl_name}'") |
504 | 495 |
|
505 | 496 | def check_return_section(self, ln, declaration_name, return_type): |
506 | 497 | """ |
@@ -754,7 +745,7 @@ def dump_struct(self, ln, proto): |
754 | 745 |
|
755 | 746 | self.create_parameter_list(ln, decl_type, members, ';', |
756 | 747 | declaration_name) |
757 | | - self.check_sections(ln, declaration_name, decl_type, self.entry.sectcheck) |
| 748 | + self.check_sections(ln, declaration_name, decl_type) |
758 | 749 |
|
759 | 750 | # Adjust declaration for better display |
760 | 751 | declaration = KernRe(r'([\{;])').sub(r'\1\n', declaration) |
@@ -1018,7 +1009,7 @@ def dump_function(self, ln, prototype): |
1018 | 1009 | f"expecting prototype for {self.entry.identifier}(). Prototype was for {declaration_name}() instead") |
1019 | 1010 | return |
1020 | 1011 |
|
1021 | | - self.check_sections(ln, declaration_name, "function", self.entry.sectcheck) |
| 1012 | + self.check_sections(ln, declaration_name, "function") |
1022 | 1013 |
|
1023 | 1014 | self.check_return_section(ln, declaration_name, return_type) |
1024 | 1015 |
|
|
0 commit comments