Skip to content

Commit 0ef6f97

Browse files
authored
fix assigning unpaired paren face to all unpared parens (#18)
1 parent 769b53d commit 0ef6f97

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/JuliaSyntaxHighlighting.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ function paren_type(k::Kind)
148148
end
149149

150150
mutable struct ParenDepthCounter
151-
paren::UInt
152-
bracket::UInt
153-
curly::UInt
151+
paren::Int
152+
bracket::Int
153+
curly::Int
154154
end
155155

156156
ParenDepthCounter() =
157-
ParenDepthCounter(zero(UInt), zero(UInt), zero(UInt))
157+
ParenDepthCounter(0, 0, 0)
158158

159159
struct GreenLineage{H}
160160
node::GreenNode{H}
@@ -346,7 +346,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
346346
setfield!(pdepths, ptype, depthref + depthchange)
347347
else
348348
depth0 = getfield(pdepths, ptype)
349-
setfield!(pdepths, ptype, depthref + depthchange)
349+
setfield!(pdepths, ptype, max(0, depthref + depthchange))
350350
depth0
351351
end
352352
if pdepth <= 0 && UNMATCHED_DELIMITERS_ENABLED[]

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ astr_sum1to8 = Base.AnnotatedString("sum(1:8)")
2727

2828
# Check for string indexing issues
2929
@test Base.annotations(highlight("")) |> first |> first == 1:3
30+
31+
# Test unpaired parentheses (issue #17)
32+
# Test consecutive unpaired closing parens and that depth counter resets properly
33+
reset_after_unpaired = highlight("(()))) ()")
34+
anns = Base.annotations(reset_after_unpaired)
35+
@test anns[5].value == :julia_unpaired_parentheses # First unpaired
36+
@test anns[6].value == :julia_unpaired_parentheses # Second unpaired
37+
@test anns[7].value == :julia_rainbow_paren_1 # Opening after reset
38+
@test anns[8].value == :julia_rainbow_paren_1 # Closing after reset

0 commit comments

Comments
 (0)