Drop duplicated using clause

This commit is contained in:
Giorgio Calderone 2020-04-16 13:23:15 +02:00
parent 530bde6bc8
commit b8e03fa477

View File

@ -646,6 +646,12 @@ function DatasetBin(cols::Vararg{AbstractVector, N}) where N
end end
end end
close(io) close(io)
#=
The following is needed to cope with the following case:
x = randn(10001)
@gp x x x "w p lc pal"
=#
source *= " using " * join(1:N, ":") * " " source *= " using " * join(1:N, ":") * " "
return DatasetBin(Val(:inner), path, source) return DatasetBin(Val(:inner), path, source)
end end
@ -1112,6 +1118,25 @@ end
function driver(_args...; is3d=false) function driver(_args...; is3d=false)
function dropDuplicatedUsing(source, spec)
# Ensure there is no duplicated `using` clause
m0 = match(r"(.*) using 1", source)
if !isnothing(m0)
for r in [r"u +[\d,\(]",
r"us +[\d,\(]",
r"usi +[\d,\(]",
r"usin +[\d,\(]",
r"using +[\d,\(]"]
m = match(r, spec)
if !isnothing(m)
source = string(m0.captures[1])
break
end
end
end
return source
end
if length(_args) == 0 if length(_args) == 0
gp = getsession() gp = getsession()
execall(gp) execall(gp)
@ -1152,7 +1177,8 @@ function driver(_args...; is3d=false)
if !isa(elem.data, DatasetEmpty) if !isa(elem.data, DatasetEmpty)
for spec in elem.plot for spec in elem.plot
if isa(elem.data, DatasetBin) if isa(elem.data, DatasetBin)
add_plot(gp, elem.data.source * " " * spec) source = dropDuplicatedUsing(elem.data.source, spec)
add_plot(gp, source * " " * spec)
else else
add_plot(gp, elem.name * " " * spec) add_plot(gp, elem.name * " " * spec)
end end
@ -1161,7 +1187,8 @@ function driver(_args...; is3d=false)
for spec in elem.plot for spec in elem.plot
for (name, data) in gp.datas for (name, data) in gp.datas
if isa(data, DatasetBin) if isa(data, DatasetBin)
spec = replace(spec, name => data.source) source = dropDuplicatedUsing(elem.data.source, spec)
spec = replace(spec, name => source)
end end
end end
add_plot(gp, spec) add_plot(gp, spec)
@ -1303,11 +1330,11 @@ The `@gp` macro, and its companion `@gsp` for 3D plots, allows to send data and
- `ylog=true` => `set logscale y`; - `ylog=true` => `set logscale y`;
- `zlog=true` => `set logscale z`. - `zlog=true` => `set logscale z`.
- `cblog=true` => `set logscale cb`; - `cblog=true` => `set logscale cb`;
- `margins=... => `set margins ...`; - `margins=...` => `set margins ...`;
- `lmargin=... => `set lmargin ...`; - `lmargin=...` => `set lmargin ...`;
- `rmargin=... => `set rmargin ...`; - `rmargin=...` => `set rmargin ...`;
- `bmargin=... => `set bmargin ...`; - `bmargin=...` => `set bmargin ...`;
- `tmargin=... => `set tmargin ...`; - `tmargin=...` => `set tmargin ...`;
All Keyword names can be abbreviated as long as the resulting name is unambiguous. E.g. you can use `xr=[1,10]` in place of `xrange=[1,10]`. All Keyword names can be abbreviated as long as the resulting name is unambiguous. E.g. you can use `xr=[1,10]` in place of `xrange=[1,10]`.