@@ -38,7 +38,7 @@ def expand_name(line: str, char_pos: int) -> str:
38
38
return ""
39
39
40
40
41
- def detect_fixed_format (file_lines : list [str ], preproc : bool = False ) -> bool :
41
+ def detect_fixed_format (file_lines : list [str ]) -> bool :
42
42
"""Detect fixed/free format by looking for characters in label columns
43
43
and variable declarations before column 6. Treat intersection format
44
44
files as free format.
@@ -47,9 +47,6 @@ def detect_fixed_format(file_lines: list[str], preproc: bool = False) -> bool:
47
47
----------
48
48
file_lines : list[str]
49
49
List of consecutive file lines
50
- preproc : bool
51
- If true, preprocessor directives (lines starting with '#') will be
52
- ignored
53
50
54
51
Returns
55
52
-------
@@ -72,13 +69,29 @@ def detect_fixed_format(file_lines: list[str], preproc: bool = False) -> bool:
72
69
>>> detect_fixed_format(['trailing line & ! comment'])
73
70
False
74
71
75
- But preprocessor lines might be ignored
76
- >>> detect_fixed_format(['#if defined(A) && !defined(B)'], preproc=True)
72
+ But preprocessor lines will be ignored
73
+ >>> detect_fixed_format(
74
+ ... ['#if defined(A) && !defined(B)', 'C Fixed format', '#endif'])
77
75
True
76
+
77
+ >>> detect_fixed_format(
78
+ ... ['#if defined(A) && !defined(B)', ' free format', '#endif'])
79
+ False
80
+
81
+ And preprocessor line-continuation is taken into account
82
+ >>> detect_fixed_format(
83
+ ... ['#if defined(A) \\ \\ ', ' && !defined(B)', 'C Fixed format', '#endif'])
84
+ True
85
+
86
+ >>> detect_fixed_format(
87
+ ... ['#if defined(A) \\ \\ ', '&& \\ \\ ', '!defined(B)', ' free format', '#endif'])
88
+ False
78
89
"""
90
+ pp_continue = False
79
91
for line in file_lines :
80
92
# Ignore preprocessor lines
81
- if preproc and line .startswith ("#" ):
93
+ if line .startswith ("#" ) or pp_continue :
94
+ pp_continue = line .rstrip ().endswith ("\\ " )
82
95
continue
83
96
if FRegex .FREE_FORMAT_TEST .match (line ):
84
97
return False
0 commit comments