Skip to content

Commit

Permalink
make shell_parse return the indexes of the last parsed thing, which is
Browse files Browse the repository at this point in the history
needed for completion
  • Loading branch information
JeffBezanson committed Sep 2, 2013
1 parent dc92be0 commit 4467885
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ function cmd_gen(parsed)
end

macro cmd(str)
:(cmd_gen($(shell_parse(str))))
:(cmd_gen($(shell_parse(str)[1])))
end

wait(x::Process) = if !process_exited(x); wait(x.exitnotify); end
Expand Down
12 changes: 7 additions & 5 deletions base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,9 @@ macro mstr(s...); triplequoted(s...); end
## shell-like command parsing ##

function shell_parse(raw::String, interp::Bool)

s = strip(raw)
isempty(s) && return interp ? Expr(:tuple,:()) : {}
last_parse = 0:-1
isempty(s) && return interp ? (Expr(:tuple,:()),last_parse) : ({},last_parse)

in_single_quotes = false
in_double_quotes = false
Expand Down Expand Up @@ -1086,7 +1086,9 @@ function shell_parse(raw::String, interp::Bool)
if isspace(s[k])
error("space not allowed right after \$")
end
stpos = j
ex, j = parse(s,j,false)
last_parse = stpos:j
update_arg(esc(ex)); i = j
else
if !in_double_quotes && c == '\''
Expand Down Expand Up @@ -1123,20 +1125,20 @@ function shell_parse(raw::String, interp::Bool)
append_arg()

if !interp
return args
return (args,last_parse)
end

# construct an expression
ex = Expr(:tuple)
for arg in args
push!(ex.args, Expr(:tuple, arg...))
end
ex
(ex,last_parse)
end
shell_parse(s::String) = shell_parse(s,true)

function shell_split(s::String)
parsed = shell_parse(s,false)
parsed = shell_parse(s,false)[1]
args = String[]
for arg in parsed
push!(args, string(arg...))
Expand Down

0 comments on commit 4467885

Please sign in to comment.