Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change annotations to use a NamedTuple #55741

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 122 additions & 103 deletions base/strings/annotated.jl

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,12 @@ function AnnotatedString(chars::AbstractVector{C}) where {C<:AbstractChar}
end
end
end
annots = Tuple{UnitRange{Int}, Pair{Symbol, Any}}[]
annots = RegionAnnotation[]
point = 1
for c in chars
if c isa AnnotatedChar
for annot in c.annotations
push!(annots, (point:point, annot))
push!(annots, (point:point, annot...))
end
end
point += ncodeunits(c)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
401bb32ca43a8460d6790ee80e695bb5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db2c732d3343f5a8770b3516cdd900587d497feab2259a937d354fac436ab3cb099b0401fb4e05817e75744fb9877ab69b1e4879d8a710b33b69c95b7e58d961

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f053c84279a8920f355f202e605842af
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b6f4c1d6c0dc73a520472746c96adff506e5405154e4b93d419e07b577b01804d2fc87d4a6cac48a136777579bebf8388c2c1e54f849b51e233138d482146b4f

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions doc/src/manual/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ to keep the string annotations.

```jldoctest
julia> str = Base.AnnotatedString("hello there",
[(1:5, :word => :greeting), (7:11, :label => 1)])
[(1:5, :word, :greeting), (7:11, :label, 1)])
"hello there"

julia> length(str)
Expand All @@ -1242,7 +1242,7 @@ julia> lpad(str, 14)
julia> typeof(lpad(str, 7))
Base.AnnotatedString{String}

julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face => :magenta)])
julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face, :magenta)])
" julia"

julia> Base.annotatedstring(str, str2)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/JuliaSyntaxHighlighting.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JULIASYNTAXHIGHLIGHTING_BRANCH = main
JULIASYNTAXHIGHLIGHTING_SHA1 = b89dd99db56700c47434df6106b6c6afd1c9ed01
JULIASYNTAXHIGHLIGHTING_SHA1 = 19bd57b89c648592155156049addf67e0638eab1
JULIASYNTAXHIGHLIGHTING_GIT_URL := https://github.com/julialang/JuliaSyntaxHighlighting.jl.git
JULIASYNTAXHIGHLIGHTING_TAR_URL = https://api.github.com/repos/julialang/JuliaSyntaxHighlighting.jl/tarball/$1
4 changes: 2 additions & 2 deletions stdlib/Markdown/src/render/terminal/formatting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function with_output_annotations(f::Function, io::AnnotIO, annots::Pair{Symbol,
start = position(aio) + 1
f(io)
stop = position(aio)
sortedindex = searchsortedlast(aio.annotations, (start:stop,), by=first)
sortedindex = searchsortedlast(aio.annotations, (region=start:stop,), by=a -> a.region)
for (i, annot) in enumerate(annots)
insert!(aio.annotations, sortedindex + i, (start:stop, annot))
insert!(aio.annotations, sortedindex + i, (start:stop, annot...))
end
end

Expand Down
2 changes: 1 addition & 1 deletion stdlib/StyledStrings.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
STYLEDSTRINGS_BRANCH = main
STYLEDSTRINGS_SHA1 = f6035eb97b516862b16e36cab2ecc6ea8adc3d7c
STYLEDSTRINGS_SHA1 = 056e843b2d428bb9735b03af0cff97e738ac7e14
STYLEDSTRINGS_GIT_URL := https://github.com/JuliaLang/StyledStrings.jl.git
STYLEDSTRINGS_TAR_URL = https://api.github.com/repos/JuliaLang/StyledStrings.jl/tarball/$1
180 changes: 91 additions & 89 deletions test/strings/annotated.jl

Large diffs are not rendered by default.