Tag nullable arguments in main header. Fixes #309

Nullable arguments will be added to the `introspect` datastructures in a future change.

PiperOrigin-RevId: 789350522
Change-Id: I0bfd12fab5121f94b937264570f907593b63cf64
This commit is contained in:
Yuval Tassa
2025-07-31 08:38:01 -07:00
committed by Copybara-Service
parent ee63b82e1c
commit 32c7d3f085
6 changed files with 203 additions and 11 deletions
+16 -1
View File
@@ -37,6 +37,9 @@ _STRUCT_END_REGEX_2 = re.compile(r'^}\s+(?P<token>mj\w+);')
# Precompiled regex for matching a C enum ending.
_ENUM_END_REGEX = re.compile(r'^}\s+(?P<token>mj\w+);')
# Precompiled regex for matching a C type with a nullable annotation.
_NULLABLE_REGEX = re.compile(r'(?P<leading_space>\s*)Nullable:\s*(?P<args>.*)')
@dataclasses.dataclass
class ApiDefinition:
@@ -120,7 +123,19 @@ def read(lines: List[str]) -> Dict[str, ApiDefinition]:
s.end()
continue
elif line.startswith('//'):
s.doc = f'{s.doc}{line[3:]}'
if len(line) > 3 and line[3].isupper():
s.doc += '\n'
comment = line[3:]
match = re.match(_NULLABLE_REGEX, comment)
if match:
groups = match.groupdict()
args = [
f'``{arg.strip()}``'
for arg in groups['args'].split(',')
if arg.strip()
]
comment = f'{groups["leading_space"]}*Nullable:* {", ".join(args)}'
s.doc = f'{s.doc}{comment}'
else:
s.end()
if s.state == 'FUNCTION':