Skip to content

Commit

Permalink
gh-104050: Argument Clinic: Annotate nested function parser_body() in…
Browse files Browse the repository at this point in the history
… the CLanguage class (#106699)
  • Loading branch information
erlend-aasland authored Jul 12, 2023
1 parent 8aa4bea commit 2d43bee
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,22 +898,24 @@ def output_templates(self, f):
# parser_body_fields remembers the fields passed in to the
# previous call to parser_body. this is used for an awful hack.
parser_body_fields = ()
def parser_body(prototype, *fields, declarations=''):
def parser_body(
prototype: str,
*fields: str,
declarations: str = ''
) -> str:
nonlocal parser_body_fields
add, output = text_accumulator()
add(prototype)
parser_body_fields = fields

fields = list(fields)
fields.insert(0, normalize_snippet("""
preamble = normalize_snippet("""
{{
{return_value_declaration}
{parser_declarations}
{declarations}
{initializers}
""") + "\n")
# just imagine--your code is here in the middle
fields.append(normalize_snippet("""
""") + "\n"
finale = normalize_snippet("""
{modifications}
{return_value} = {c_basename}_impl({impl_arguments});
{return_conversion}
Expand All @@ -923,8 +925,8 @@ def parser_body(prototype, *fields, declarations=''):
{cleanup}
return return_value;
}}
"""))
for field in fields:
""")
for field in preamble, *fields, finale:
add('\n')
add(field)
return linear_format(output(), parser_declarations=declarations)
Expand Down

0 comments on commit 2d43bee

Please sign in to comment.