@@ -2889,11 +2889,8 @@ class StringMerger(CustomSplitMapMixin, StringTransformer):
2889
2889
"""StringTransformer that merges strings together.
2890
2890
2891
2891
Requirements:
2892
- (A) The line contains adjacent strings such that at most one substring
2893
- has inline comments AND none of those inline comments are pragmas AND
2894
- the set of all substring prefixes is either of length 1 or equal to
2895
- {"", "f"} AND none of the substrings are raw strings (i.e. are prefixed
2896
- with 'r').
2892
+ (A) The line contains adjacent strings such that ALL of the validation checks
2893
+ listed in StringMerger.__validate_msg(...)'s docstring pass.
2897
2894
OR
2898
2895
(B) The line contains a string which uses line continuation backslashes.
2899
2896
@@ -3142,6 +3139,7 @@ def __validate_msg(line: Line, string_idx: int) -> TResult[None]:
3142
3139
* Ok(None), if ALL validation checks (listed below) pass.
3143
3140
OR
3144
3141
* Err(CannotTransform), if any of the following are true:
3142
+ - The target string group does not contain ANY stand-alone comments.
3145
3143
- The target string is not in a string group (i.e. it has no
3146
3144
adjacent strings).
3147
3145
- The string group has more than one inline comment.
@@ -3150,6 +3148,26 @@ def __validate_msg(line: Line, string_idx: int) -> TResult[None]:
3150
3148
length greater than one and is not equal to {"", "f"}.
3151
3149
- The string group consists of raw strings.
3152
3150
"""
3151
+ # We first check for "inner" stand-alone comments (i.e. stand-alone
3152
+ # comments that have a string leaf before them AND after them).
3153
+ for inc in [1 , - 1 ]:
3154
+ i = string_idx
3155
+ found_sa_comment = False
3156
+ is_valid_index = is_valid_index_factory (line .leaves )
3157
+ while is_valid_index (i ) and line .leaves [i ].type in [
3158
+ token .STRING ,
3159
+ STANDALONE_COMMENT ,
3160
+ ]:
3161
+ if line .leaves [i ].type == STANDALONE_COMMENT :
3162
+ found_sa_comment = True
3163
+ elif found_sa_comment :
3164
+ return TErr (
3165
+ "StringMerger does NOT merge string groups which contain "
3166
+ "stand-alone comments."
3167
+ )
3168
+
3169
+ i += inc
3170
+
3153
3171
num_of_inline_string_comments = 0
3154
3172
set_of_prefixes = set ()
3155
3173
num_of_strings = 0
0 commit comments