Skip to content

Conversation

@KristofferC
Copy link
Member

@KristofferC KristofferC commented Oct 15, 2025

Fixes #17

(underflow bad) :P.

julia> Base.annotations(JuliaSyntaxHighlighting.highlight("(())))"))
6-element Vector{@NamedTuple{region::UnitRange{Int64}, label::Symbol, value}}:
 @NamedTuple{region::UnitRange{Int64}, label::Symbol, value}((1:1, :face, :julia_rainbow_paren_1))
 @NamedTuple{region::UnitRange{Int64}, label::Symbol, value}((2:2, :face, :julia_rainbow_paren_2))
 @NamedTuple{region::UnitRange{Int64}, label::Symbol, value}((3:3, :face, :julia_rainbow_paren_2))
 @NamedTuple{region::UnitRange{Int64}, label::Symbol, value}((4:4, :face, :julia_rainbow_paren_1))
 @NamedTuple{region::UnitRange{Int64}, label::Symbol, value}((5:5, :face, :julia_unpaired_parentheses)) <----
 @NamedTuple{region::UnitRange{Int64}, label::Symbol, value}((6:6, :face, :julia_unpaired_parentheses)) <-----

@tecosaur
Copy link
Member

Thanks for the catch + fix. I do wonder if this is the right approach, though? I chose UInt because negative values don't really have a useful meaning. Changing to Int stops the underflow, but also means that the number of unpaired closing parens changes the highlighting of all parens past that point.

I don't think this is the behaviour we want. Rather, I think we want to detect underflow and apply the unpaired paren face, but clamp the minimum value at 0 (in which case Int/UInt makes no difference).

@KristofferC
Copy link
Member Author

KristofferC commented Oct 15, 2025

Yeah, having a clamp makes sense (I added that + test). The issue with UInt is that if you accidentally underflow, you cannot detect the erroneous value (and it instead becomes a bogus valid value), and we don't care about the 2x extra space here.

@KristofferC KristofferC merged commit 0ef6f97 into main Oct 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make all unpaired closing paren have the error paren face

2 participants