Skip to content

Commit f1eedbc

Browse files
committed
fix assigning unpaired paren face to all unpared parens
1 parent e34cc37 commit f1eedbc

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}
@@ -345,7 +345,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
345345
setfield!(pdepths, ptype, depthref + depthchange)
346346
else
347347
depth0 = getfield(pdepths, ptype)
348-
setfield!(pdepths, ptype, depthref + depthchange)
348+
setfield!(pdepths, ptype, max(0, depthref + depthchange))
349349
depth0
350350
end
351351
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)