Skip to content

Commit fbfb306

Browse files
committed
Add StepRange support
1 parent 3fe838c commit fbfb306

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/varname.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ end
868868
# -----------------------------------------
869869

870870
index_to_dict(i::Integer) = Dict(:type => "integer", :value => i)
871-
index_to_dict(r::UnitRange) = Dict(:type => "unitrange", :first => first(r), :last => last(r))
871+
index_to_dict(r::UnitRange) = Dict(:type => "unitrange", :start => r.start, :stop => r.stop)
872+
index_to_dict(r::StepRange) = Dict(:type => "steprange", :start => r.start, :stop => r.stop, :step => r.step)
872873
index_to_dict(::Colon) = Dict(:type => "colon")
873874
index_to_dict(s::ConcretizedSlice{T,Base.OneTo{I}}) where {T,I} = Dict(:type => "concretized_slice", :oneto => s.range.stop)
874875
index_to_dict(::ConcretizedSlice{T,R}) where {T,R} = error("ConcretizedSlice with range type $(R) not supported")
@@ -880,7 +881,9 @@ function dict_to_index(dict)
880881
if dict[:type] == "integer"
881882
return dict[:value]
882883
elseif dict[:type] == "unitrange"
883-
return dict[:first]:dict[:last]
884+
return dict[:start]:dict[:stop]
885+
elseif dict[:type] == "steprange"
886+
return dict[:start]:dict[:step]:dict[:stop]
884887
elseif dict[:type] == "colon"
885888
return Colon()
886889
elseif dict[:type] == "concretized_slice"
@@ -892,7 +895,6 @@ function dict_to_index(dict)
892895
end
893896
end
894897

895-
896898
optic_to_dict(::typeof(identity)) = Dict(:type => "identity")
897899
optic_to_dict(::PropertyLens{sym}) where {sym} = Dict(:type => "property", :field => String(sym))
898900
optic_to_dict(i::IndexLens) = Dict(:type => "index", :indices => index_to_dict(i.indices))

test/varname.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ end
150150
@varname(x[1]),
151151
@varname(var"x[1]"),
152152
@varname(x[1:10]),
153+
@varname(x[1:3:10]),
153154
@varname(x[1, 2]),
154155
@varname(x[1, 2:5]),
155156
@varname(x[:]),

0 commit comments

Comments
 (0)