Skip to content

Commit 6e30d15

Browse files
committed
Refactor argument formatting with recursion and quote removal
Signed-off-by: kwakubiney <[email protected]>
1 parent adacf48 commit 6e30d15

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

compiler/annotations_utils/util_parsing.py

-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ def parse_arg_list_to_command_invocation(
6666
command, flags_options_operands
6767
) -> CommandInvocationInitial:
6868
cmd_name = format_arg_chars(command)
69-
#strip quotes from command where necessary
70-
#quoted commands are interpreted as non-parallelizable
71-
cmd_name = cmd_name.strip().strip('"').strip("'")
7269
json_data = get_json_data(cmd_name)
7370
set_of_all_flags: Set[str] = get_set_of_all_flags(json_data)
7471
dict_flag_to_primary_repr: dict[str, str] = get_dict_flag_to_primary_repr(json_data)

compiler/shell_ast/ast_util.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,23 @@ def __init__(self, text):
4444
def check_if_ast_is_supported(construct, arguments, **kwargs):
4545
return
4646

47-
48-
def format_args(args):
49-
formatted_args = [format_arg_chars(arg_chars) for arg_chars in args]
50-
return formatted_args
51-
52-
5347
def format_arg_chars(arg_chars):
54-
chars = [format_arg_char(arg_char) for arg_char in arg_chars]
55-
return "".join(chars)
48+
return traverse_and_format(arg_chars)
49+
50+
def traverse_and_format(arg_char):
51+
if isinstance(arg_char, list):
52+
return "".join(traverse_and_format(c) for c in arg_char)
53+
elif isinstance(arg_char, QArgChar):
54+
return remove_quotes_from_quoted_content(arg_char.format())
55+
elif isinstance(arg_char, (CArgChar, EArgChar)):
56+
return format_arg_char(arg_char)
57+
else:
58+
# Fallback: not sure what the fallback for non recognized characters should be?
59+
return format_arg_char(arg_char)
60+
61+
def remove_quotes_from_quoted_content(arg_char):
62+
formatted_content = traverse_and_format(arg_char)
63+
return formatted_content.strip('"').strip("'")
5664

5765

5866
def format_arg_char(arg_char: ArgChar) -> str:

0 commit comments

Comments
 (0)