@@ -500,7 +500,11 @@ def build_scope_parser(fypp=True, mod=True, subr=True):
500
500
501
501
## F90_CONSTANTS_TYPES_RE = re.compile(r"\b" + F90_NUMBER_ALL_RE + "_(" + "|".join([a + r"\b" for a in (
502
502
F90_CONSTANTS_TYPES_RE = re .compile (
503
- r"(" + F90_NUMBER_ALL_RE + ")*_(" + "|" .join ((
503
+ # Zaikun's modification 3 >>
504
+ # Avoid greedy regex, which is very slow for long numbers.
505
+ #r"(" + F90_NUMBER_ALL_RE + ")*_(" + "|".join((
506
+ r"(" + F90_NUMBER_ALL_RE + ")_(" + "|" .join ((
507
+ # << Zaikun's modification
504
508
## F2003 iso_fortran_env constants.
505
509
## F2003 iso_c_binding constants.
506
510
"c_int" , "c_short" , "c_long" , "c_long_long" , "c_signed_char" ,
@@ -1071,19 +1075,20 @@ def format_single_fline(f_line, whitespace, whitespace_dict, linebreak_pos,
1071
1075
'print' : 6 , # 6: print / read statements
1072
1076
'type' : 7 , # 7: select type components
1073
1077
'intrinsics' : 8 , # 8: intrinsics
1074
- 'decl' : 9 # 9: declarations
1078
+ 'decl' : 9 , # 9: declarations
1079
+ 'use_only' : 10
1075
1080
}
1076
1081
1077
1082
if whitespace == 0 :
1078
- spacey = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
1083
+ spacey = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
1079
1084
elif whitespace == 1 :
1080
- spacey = [1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 ]
1085
+ spacey = [1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 , 1 ]
1081
1086
elif whitespace == 2 :
1082
- spacey = [1 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 1 ]
1087
+ spacey = [1 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 1 , 1 ]
1083
1088
elif whitespace == 3 :
1084
- spacey = [1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 ]
1089
+ spacey = [1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 ]
1085
1090
elif whitespace == 4 :
1086
- spacey = [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
1091
+ spacey = [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
1087
1092
else :
1088
1093
raise NotImplementedError ("unknown value for whitespace" )
1089
1094
@@ -1342,8 +1347,8 @@ def add_whitespace_context(line, spacey):
1342
1347
1343
1348
# format ':' for labels and use only statements
1344
1349
if USE_RE .search (line ):
1345
- line = re .sub (r'(only)\s*:\s*' , r'\g<1>:' + ' ' *
1346
- spacey [ 0 ], line , flags = RE_FLAGS )
1350
+ line = re .sub (r'(only)\s*:\s*' , r'\g<1>' + ' ' * spacey [ 10 ] + ' :' + ' ' * spacey [ 0 ], line , flags = RE_FLAGS )
1351
+
1347
1352
1348
1353
return line
1349
1354
@@ -2018,6 +2023,8 @@ def get_arg_parser(args):
2018
2023
help = "boolean, en-/disable whitespace for select type components" )
2019
2024
parser .add_argument ("--whitespace-intrinsics" , type = str2bool , nargs = "?" , default = "None" , const = True ,
2020
2025
help = "boolean, en-/disable whitespace for intrinsics like if/write/close" )
2026
+ parser .add_argument ("--whitespace-use-only" , type = str2bool , nargs = "?" , default = "None" , const = True ,
2027
+ help = "boolean, en-/disable whitespace for the colon after `use MODULE, only`" )
2021
2028
parser .add_argument ("--strict-indent" , action = 'store_true' , default = False , help = "strictly impose indentation even for nested loops" )
2022
2029
parser .add_argument ("--enable-decl" , action = "store_true" , default = False , help = "enable whitespace formatting of declarations ('::' operator)." )
2023
2030
parser .add_argument ("--disable-indent" , action = 'store_true' , default = False , help = "don't impose indentation" )
@@ -2087,6 +2094,7 @@ def build_ws_dict(args):
2087
2094
ws_dict ['print' ] = args .whitespace_print
2088
2095
ws_dict ['type' ] = args .whitespace_type
2089
2096
ws_dict ['intrinsics' ] = args .whitespace_intrinsics
2097
+ ws_dict ['use_only' ] = args .whitespace_use_only
2090
2098
return ws_dict
2091
2099
2092
2100
# support legacy input:
0 commit comments