Removed AbbrvKW and added dependency on v0.3

This commit is contained in:
Giorgio Calderone 2017-08-28 19:40:38 +02:00
parent f33dc83692
commit 9e9f9c0d95
4 changed files with 6 additions and 153 deletions

View File

@ -13,13 +13,13 @@ Julia. Its main features are:
- fast data transmission to gnuplot through system pipes (no temporary - fast data transmission to gnuplot through system pipes (no temporary
files involved); files involved);
- support for running multiple gnuplot process simulatneously; - handles multiple gnuplot process simultaneously;
- support for multiplots; - support for multiplots;
- save sessions into gnuplot scripts; - save sessions into gnuplot scripts;
- extremely concise syntax (see examples below), makes it ideal for - extremely concise syntax (see examples below) makes it ideal for
interactive data exploration; interactive data exploration;
- very easy to use: if you know gnuplot you're ready to go. - very easy to use: if you know gnuplot you're ready to go.

View File

@ -1,2 +1,3 @@
julia 0.6 julia 0.6
StatsBase AbbrvKW 0.3.0

View File

@ -1,8 +1,9 @@
module Gnuplot module Gnuplot
using AbbrvKW
include("GnuplotInternals.jl") include("GnuplotInternals.jl")
importall .p_ importall .p_
import .p_.@AbbrvKW
###################################################################### ######################################################################
# Get/set options # Get/set options

View File

@ -7,155 +7,6 @@ importall Gnuplot
const P_ = Gnuplot const P_ = Gnuplot
import StatsBase.countmap
function findAbbrv(symLong::Vector{Symbol})
if length(symLong) == 0
return symLong
end
out = Dict()
for sym in symLong
out[sym] = Vector{Symbol}()
end
symAbbr = deepcopy(symLong)
symStr = convert.(String, symLong)
kwCount = length(symLong)
# Max length of string representation of keywords
maxLen = maximum(length.(symStr))
# Identify all abbreviations
for len in 1:maxLen
for i in 1:kwCount
s = symStr[i]
if length(s) >= len
s = s[1:len]
push!(symLong, symLong[i])
push!(symAbbr, convert(Symbol, s))
push!(symStr , s)
end
end
end
symStr = nothing # no longer needed
# Identify unique abbreviations
abbrCount = 0
for (sym, count) in countmap(symAbbr)
if count == 1
i = find(symAbbr .== sym)
@assert length(i) == 1
i = i[1]
if symLong[i] != symAbbr[i]
push!(out[symLong[i]], symAbbr[i])
abbrCount += 1
end
end
end
for (key, val) in out
sort!(out[key])
end
return (out, abbrCount)
end
macro AbbrvKW(func)
@assert func.head == :function "Not a function"
if length(func.args[1].args) <= 1
# Empty parameter list"
return esc(func)
end
if (typeof(func.args[1].args[2]) != Expr) ||
(func.args[1].args[2].head != :parameters)
# No keywords given
return esc(func)
end
sym = Vector{Symbol}() # Symbol, long version
typ = Dict() # Data type
splat = Symbol()
splatFound = false
for k in func.args[1].args[2].args
@assert typeof(k) == Expr "Expr expected"
@assert k.head in (:kw, :(...)) "Expected :kw or :..., got $(k.head)"
#dump(k)
if k.head == :kw
@assert typeof(k.args[1]) in (Expr, Symbol) "Expected Expr or Symbol"
if typeof(k.args[1]) == Symbol
push!(sym, k.args[1])
typ[sym[end]] = :Any
elseif typeof(k.args[1]) == Expr
@assert k.args[1].head == :(::) "Expected :(::), got $(k.args[1].head)"
push!(sym, k.args[1].args[1])
typ[sym[end]] = k.args[1].args[2]
end
elseif k.head == :(...)
splat = k.args[1]
splatFound = true
end
end
# Find abbreviations
(abbr, count) = findAbbrv(sym)
if count == 0
# No abbreviations found
return esc(func)
end
# Add a splat variable if not present
if !splatFound
splat = :_abbrvkw_
a = :($splat...)
a = a.args[1]
push!(func.args[1].args[2].args, a)
a = nothing
end
# Build output Expr
expr = Expr(:block)
push!(expr.args, :(_ii_ = 1))
push!(expr.args, Expr(:while, :(_ii_ <= length($splat)), Expr(:block)))
for (sym, tup) in abbr
length(tup) > 0 || continue
tup = tuple(tup...)
push!(expr.args[end].args[end].args,
:(
if $(splat)[_ii_][1] in $tup
typeassert($(splat)[_ii_][2], $(typ[sym]))
$(sym) = $(splat)[_ii_][2]
deleteat!($splat, _ii_)
continue
end
))
end
push!(expr.args[end].args[end].args, :(_ii_ += 1))
push!(expr.args, :(_ii_ = nothing))
if !splatFound
push!(expr.args, :(if length($splat) !=0 ;
error("Unrecognized keyword abbreviation(s): " * string($splat))
end))
push!(expr.args, :($splat = nothing))
end
@assert length(func.args) == 2 "Function Expr has " * string(length(func.args)) * " args"
@assert func.args[2].head == :block "Function block is not a block, but " * string(func.args[2].head)
prepend!(func.args[2].args, [expr])
#@show func
return esc(func)
end
###################################################################### ######################################################################
# Structure definitions # Structure definitions
###################################################################### ######################################################################