1717
1818function shell_parse (str:: AbstractString , interpolate:: Bool = true ;
1919 special:: AbstractString = " " )
20- s:: SubString = SubString (str, firstindex (str))
20+ s = SubString (str, firstindex (str))
2121 s = rstrip_shell (lstrip (s))
2222
2323 # N.B.: This is used by REPLCompletions
@@ -33,23 +33,25 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
3333 st = Iterators. Stateful (pairs (s))
3434
3535 function update_arg (x)
36- if ! isa (x,AbstractString) || ! isempty (x)
37- push! (arg, x)
36+ let arg = arg
37+ if ! isa (x,AbstractString) || ! isempty (x)
38+ push! (arg, x)
39+ end
3840 end
3941 end
40- function consume_upto (j)
42+ function consume_upto (s, i, j)
4143 update_arg (s[i: prevind (s, j)])
42- i = something (peek (st), (lastindex (s)+ 1 ,' \0 ' ))[1 ]
44+ something (peek (st), (lastindex (s)+ 1 ,' \0 ' ))[1 ]
4345 end
4446 function append_arg ()
4547 if isempty (arg); arg = Any[" " ,]; end
4648 push! (args, arg)
4749 arg = []
4850 end
4951
50- for (j, c) in st
52+ for (j:: Int , c) in st
5153 if ! in_single_quotes && ! in_double_quotes && isspace (c)
52- consume_upto (j)
54+ i = consume_upto (s, i, j)
5355 append_arg ()
5456 while ! isempty (st)
5557 # We've made sure above that we don't end in whitespace,
@@ -59,7 +61,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
5961 popfirst! (st)
6062 end
6163 elseif interpolate && ! in_single_quotes && c == ' $'
62- consume_upto (j)
64+ i = consume_upto (s, i, j)
6365 isempty (st) && error (" \$ right before end of command" )
6466 stpos, c = popfirst! (st)
6567 isspace (c) && error (" space not allowed right after \$ " )
@@ -79,21 +81,21 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
7981 else
8082 if ! in_double_quotes && c == ' \' '
8183 in_single_quotes = ! in_single_quotes
82- consume_upto (j)
84+ i = consume_upto (s, i, j)
8385 elseif ! in_single_quotes && c == ' "'
8486 in_double_quotes = ! in_double_quotes
85- consume_upto (j)
87+ i = consume_upto (s, i, j)
8688 elseif c == ' \\ '
8789 if in_double_quotes
8890 isempty (st) && error (" unterminated double quote" )
8991 k, c′ = peek (st)
9092 if c′ == ' "' || c′ == ' $' || c′ == ' \\ '
91- consume_upto (j)
93+ i = consume_upto (s, i, j)
9294 _ = popfirst! (st)
9395 end
9496 elseif ! in_single_quotes
9597 isempty (st) && error (" dangling backslash" )
96- consume_upto (j)
98+ i = consume_upto (s, i, j)
9799 _ = popfirst! (st)
98100 end
99101 elseif ! in_single_quotes && ! in_double_quotes && c in special
0 commit comments