Skip to content

Commit 2182de2

Browse files
authored
Warn about nesting and dangling skip in updown.py
The updown processor should warn when skip begin/end are garbled
1 parent d1ab6e0 commit 2182de2

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

torchchat/utils/scripts/updown.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import re
1111

12+
skip_nesting_level = 0
1213

1314
###############################################################################################
1415
###
@@ -115,7 +116,7 @@ def updown_process_line(
115116
return
116117
if len(options) > 1:
117118
output(
118-
"echo 'cross product of options not yet supported anot line {line} of {filename}'\nexit 1",
119+
"echo 'cross product of options not yet supported in line {line} of {filename}'\nexit 1",
119120
suppress_list=None,
120121
replace_list=None,
121122
)
@@ -137,7 +138,8 @@ def updown_process_line(
137138
def process_command(
138139
line, lineno, filename, predicate_list, replace_list, suppress_list, create_sections
139140
) -> bool:
140-
141+
142+
global skip_nesting_level
141143
command = r"^\[\s*(\w+)\s+(\w+)\s*\]\s*:\s*(.*)"
142144
match = re.search(command, line)
143145

@@ -168,12 +170,25 @@ def process_command(
168170
)
169171
elif keyword == "skip":
170172
if trailing_command == "begin":
173+
skip_nesting_level += 1
174+
if skip_nesting_level > 1:
175+
output(
176+
"echo 'nested skips are discouraged in line {lineno} of {filename} and may be prohibited in the future'",
177+
replace_list=replace_list,
178+
suppress_list=suppress_list,
179+
)
171180
output(
172181
"if false; then",
173182
replace_list=replace_list,
174183
suppress_list=suppress_list,
175184
)
176185
elif trailing_command == "end":
186+
if skip_nesting_level < 0:
187+
output(
188+
"echo 'skip end without matching skip begin in line {lineno} of {filename}'\nexit 1;",
189+
replace_list=replace_list,
190+
suppress_list=suppress_list,
191+
)
177192
output(
178193
"fi",
179194
replace_list=replace_list,
@@ -187,6 +202,12 @@ def process_command(
187202
)
188203
exit(1)
189204
elif keyword == "end":
205+
if skip_nesting_level > 0:
206+
output(
207+
"echo 'skip begin without matching skip end in line {lineno} of {filename}'\nexit 1;",
208+
replace_list=replace_list,
209+
suppress_list=suppress_list,
210+
)
190211
if create_sections:
191212
output(
192213
"echo '::endgroup::'",
@@ -303,7 +324,7 @@ def updown_processor(
303324
)
304325

305326
output(
306-
"echo 'reached end of file without exit command'\nexit 1;",
327+
"echo 'reached end of file without `end` command'\nexit 1;",
307328
suppress_list=None,
308329
replace_list=None,
309330
)

0 commit comments

Comments
 (0)