Skip to content

Commit 3b4491e

Browse files
shell_parse: some cosmetic clean ups
1 parent ab984a5 commit 3b4491e

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

base/shell.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## shell-like command parsing ##
44

5-
function shell_parse(raw::AbstractString, interp::Bool)
6-
s = lstrip(raw)
7-
#Strips the end but respects the space when the string endswith "\\ "
5+
function shell_parse(str::AbstractString, interpolate::Bool=true)
6+
s = lstrip(str)
7+
# strips the end but respects the space when the string ends with "\\ "
88
r = RevString(s)
99
i = start(r)
1010
c_old = nothing
@@ -22,7 +22,7 @@ function shell_parse(raw::AbstractString, interp::Bool)
2222
s = s[1:end-i+1]
2323

2424
last_parse = 0:-1
25-
isempty(s) && return interp ? (Expr(:tuple,:()),last_parse) : ([],last_parse)
25+
isempty(s) && return interpolate ? (Expr(:tuple,:()),last_parse) : ([],last_parse)
2626

2727
in_single_quotes = false
2828
in_double_quotes = false
@@ -57,7 +57,7 @@ function shell_parse(raw::AbstractString, interp::Bool)
5757
end
5858
j = k
5959
end
60-
elseif interp && !in_single_quotes && c == '$'
60+
elseif interpolate && !in_single_quotes && c == '$'
6161
update_arg(s[i:j-1]); i = k; j = k
6262
if done(s,k)
6363
error("\$ right before end of command")
@@ -103,18 +103,15 @@ function shell_parse(raw::AbstractString, interp::Bool)
103103
update_arg(s[i:end])
104104
append_arg()
105105

106-
if !interp
107-
return (args,last_parse)
108-
end
106+
interpolate || return args, last_parse
109107

110108
# construct an expression
111109
ex = Expr(:tuple)
112110
for arg in args
113111
push!(ex.args, Expr(:tuple, arg...))
114112
end
115-
(ex,last_parse)
113+
return ex, last_parse
116114
end
117-
shell_parse(s::AbstractString) = shell_parse(s,true)
118115

119116
function shell_split(s::AbstractString)
120117
parsed = shell_parse(s,false)[1]

0 commit comments

Comments
 (0)