@@ -4618,7 +4618,7 @@ def parse(self, block: Block) -> None:
4618
4618
fail (f'Tab characters are illegal in the Clinic DSL: { line !r} ' ,
4619
4619
line_number = block_start )
4620
4620
try :
4621
- function = self .handle_line (function , line )
4621
+ function = self .handle_line (function = function , line = line )
4622
4622
except ClinicError as exc :
4623
4623
exc .lineno = line_number
4624
4624
raise
@@ -4631,7 +4631,16 @@ def parse(self, block: Block) -> None:
4631
4631
fail ("'preserve' only works for blocks that don't produce any output!" )
4632
4632
block .output = self .saved_output
4633
4633
4634
- def handle_line (self , function : Function | None , line : str ) -> Function | None :
4634
+ def handle_line (
4635
+ self ,
4636
+ / ,
4637
+ * ,
4638
+ function : Function | None ,
4639
+ line : str ,
4640
+ new_state : DSLParserState | None = None
4641
+ ) -> Function | None :
4642
+ if new_state :
4643
+ self .state = new_state
4635
4644
match function :
4636
4645
case None :
4637
4646
match self .state :
@@ -4697,10 +4706,13 @@ def handle_dsl_start(self, line: str) -> Function | None:
4697
4706
fail (str (e ))
4698
4707
return None
4699
4708
4700
- self .state = DSLParserState .MODULENAME_NAME
4701
- return self .handle_modulename_name (line )
4709
+ return self .handle_line (
4710
+ function = None ,
4711
+ line = line ,
4712
+ new_state = DSLParserState .MODULENAME_NAME
4713
+ )
4702
4714
4703
- def handle_modulename_name (self , line : str ) -> Function | None :
4715
+ def handle_modulename_name (self , line : str ) -> Function :
4704
4716
# looking for declaration, which establishes the leftmost column
4705
4717
# line should be
4706
4718
# modulename.fnname [as c_basename] [-> return annotation]
@@ -4898,13 +4910,16 @@ def handle_parameters_start(self, function: Function, line: str) -> Function:
4898
4910
if self .valid_line (line ):
4899
4911
# if this line is not indented, we have no parameters
4900
4912
if not self .indent .infer (line ):
4901
- self .state = DSLParserState .FUNCTION_DOCSTRING
4902
- self .handle_function_docstring (function = function , line = line )
4913
+ self .handle_line (
4914
+ function = function ,
4915
+ line = line ,
4916
+ new_state = DSLParserState .FUNCTION_DOCSTRING
4917
+ )
4903
4918
else :
4904
4919
self .parameter_continuation = ''
4905
- self .state = DSLParserState . PARAMETER
4906
- self . handle_parameter ( function = function , line = line )
4907
-
4920
+ self .handle_line (
4921
+ function = function , line = line , new_state = DSLParserState . PARAMETER
4922
+ )
4908
4923
return function
4909
4924
4910
4925
def to_required (self , function : Function ) -> None :
@@ -4928,13 +4943,19 @@ def handle_parameter(self, function: Function, line: str) -> Function:
4928
4943
indent = self .indent .infer (line )
4929
4944
if indent == - 1 :
4930
4945
# we outdented, must be to definition column
4931
- self .state = DSLParserState .FUNCTION_DOCSTRING
4932
- return self .handle_function_docstring (function = function , line = line )
4946
+ self .handle_line (
4947
+ function = function , line = line , new_state = DSLParserState .FUNCTION_DOCSTRING
4948
+ )
4949
+ return function
4933
4950
4934
4951
if indent == 1 :
4935
4952
# we indented, must be to new parameter docstring column
4936
- self .state = DSLParserState .PARAMETER_DOCSTRING_START
4937
- return self .handle_parameter_docstring_start (function = function , line = line )
4953
+ self .handle_line (
4954
+ function = function ,
4955
+ line = line ,
4956
+ new_state = DSLParserState .PARAMETER_DOCSTRING_START
4957
+ )
4958
+ return function
4938
4959
4939
4960
line = line .rstrip ()
4940
4961
if line .endswith ('\\ ' ):
@@ -5330,8 +5351,10 @@ def handle_parameter_docstring_start(
5330
5351
assert self .indent .margin is not None , "self.margin.infer() has not yet been called to set the margin"
5331
5352
self .parameter_docstring_indent = len (self .indent .margin )
5332
5353
assert self .indent .depth == 3
5333
- self .state = DSLParserState .PARAMETER_DOCSTRING
5334
- return self .handle_parameter_docstring (function = function , line = line )
5354
+ self .handle_line (
5355
+ function = function , line = line , new_state = DSLParserState .PARAMETER_DOCSTRING
5356
+ )
5357
+ return function
5335
5358
5336
5359
def docstring_append (self , obj : Function | Parameter , line : str ) -> None :
5337
5360
"""Add a rstripped line to the current docstring."""
@@ -5362,11 +5385,15 @@ def handle_parameter_docstring(
5362
5385
assert self .indent .depth < 3
5363
5386
if self .indent .depth == 2 :
5364
5387
# back to a parameter
5365
- self .state = DSLParserState .PARAMETER
5366
- return self .handle_parameter (function = function , line = line )
5367
- assert self .indent .depth == 1
5368
- self .state = DSLParserState .FUNCTION_DOCSTRING
5369
- return self .handle_function_docstring (function = function , line = line )
5388
+ self .handle_line (
5389
+ function = function , line = line , new_state = DSLParserState .PARAMETER
5390
+ )
5391
+ else :
5392
+ assert self .indent .depth == 1
5393
+ self .handle_line (
5394
+ function = function , line = line , new_state = DSLParserState .FUNCTION_DOCSTRING
5395
+ )
5396
+ return function
5370
5397
5371
5398
assert function .parameters
5372
5399
last_param = next (reversed (function .parameters .values ()))
0 commit comments