Skip to content

Commit

Permalink
fix print behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxd3 committed Mar 19, 2024
1 parent b710e8b commit 056f142
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/varname.jl
Expand Up @@ -27,7 +27,7 @@ julia> vn = VarName{:x}(Accessors.IndexLens((Colon(), 1)) ⨟ Accessors.IndexLen
x[:, 1][2]
julia> getoptic(vn)
(@o _[:, 1][2])
(@o _[Colon(), 1][2])
julia> @varname x[:, 1][1+1]
x[:, 1][2]
Expand Down Expand Up @@ -155,18 +155,19 @@ end

function Base.show(io::IO, vn::VarName{sym,T}) where {sym,T}
print(io, getsym(vn))
_print_application(io, getoptic(vn))
_show_optic(io, getoptic(vn))
end

function _print_application(io::IO, optic)
# modified from https://github.com/JuliaObjects/Accessors.jl/blob/01528a81fdf17c07436e1f3d99119d3f635e4c26/src/sugar.jl#L502
function _show_optic(io::IO, optic)
opts = Accessors.deopcompose(optic)
inner = Iterators.takewhile(x -> applicable(_shortstring, "", x), opts)
outer = Iterators.dropwhile(x -> applicable(_shortstring, "", x), opts)
if !isempty(outer)
show(io, opcompose(outer...))
print(io, "")

Check warning on line 168 in src/varname.jl

View check run for this annotation

Codecov / codecov/patch

src/varname.jl#L167-L168

Added lines #L167 - L168 were not covered by tests
end
shortstr = reduce(Accessors._shortstring, inner; init="")
shortstr = reduce(_shortstring, inner; init="")
print(io, shortstr)
end

Expand Down Expand Up @@ -556,10 +557,10 @@ julia> getoptic(@varname(x[1]))
(@o _[1])
julia> getoptic(@varname(x[:, 1]))
(@o _[:, 1])
(@o _[Colon(), 1])
julia> getoptic(@varname(x[:, 1][2]))
(@o _[:, 1][2])
(@o _[Colon(), 1][2])
julia> getoptic(@varname(x[1,2][1+5][45][3]))
(@o _[1, 2][6][45][3])
Expand Down

0 comments on commit 056f142

Please sign in to comment.