2
2
3
3
# # shell-like command parsing ##
4
4
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 "\\ "
8
8
r = RevString (s)
9
9
i = start (r)
10
10
c_old = nothing
@@ -22,7 +22,7 @@ function shell_parse(raw::AbstractString, interp::Bool)
22
22
s = s[1 : end - i+ 1 ]
23
23
24
24
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)
26
26
27
27
in_single_quotes = false
28
28
in_double_quotes = false
@@ -57,7 +57,7 @@ function shell_parse(raw::AbstractString, interp::Bool)
57
57
end
58
58
j = k
59
59
end
60
- elseif interp && ! in_single_quotes && c == ' $'
60
+ elseif interpolate && ! in_single_quotes && c == ' $'
61
61
update_arg (s[i: j- 1 ]); i = k; j = k
62
62
if done (s,k)
63
63
error (" \$ right before end of command" )
@@ -103,18 +103,15 @@ function shell_parse(raw::AbstractString, interp::Bool)
103
103
update_arg (s[i: end ])
104
104
append_arg ()
105
105
106
- if ! interp
107
- return (args,last_parse)
108
- end
106
+ interpolate || return args, last_parse
109
107
110
108
# construct an expression
111
109
ex = Expr (:tuple )
112
110
for arg in args
113
111
push! (ex. args, Expr (:tuple , arg... ))
114
112
end
115
- ( ex,last_parse)
113
+ return ex, last_parse
116
114
end
117
- shell_parse (s:: AbstractString ) = shell_parse (s,true )
118
115
119
116
function shell_split (s:: AbstractString )
120
117
parsed = shell_parse (s,false )[1 ]
0 commit comments