Skip to content

Commit 1b53359

Browse files
committed
Add docstrings for internal variables and funcs
1 parent 75e32b2 commit 1b53359

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/JuliaSyntaxHighlighting.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,59 @@ using StyledStrings: Face, addface!
66

77
public highlight, highlight!
88

9+
"""
10+
MAX_PAREN_HIGHLIGHT_DEPTH
11+
12+
The number of `julia_rainbow_{paren,bracket_curly}_{n}` faces
13+
from [`HIGHLIGHT_FACES`](@ref) that can be cycled through.
14+
"""
915
const MAX_PAREN_HIGHLIGHT_DEPTH = 6
16+
"""
17+
RAINBOW_DELIMITERS_ENABLED
18+
19+
Whether to use `julia_rainbow_{paren,bracket_curly}_{n}` faces for
20+
delimitors/parentheses (`()`, `[]`, `{}`) as opposed to just using
21+
`julia_parenthetical`.
22+
"""
1023
const RAINBOW_DELIMITERS_ENABLED = Ref(true)
24+
"""
25+
UNMATCHED_DELIMITERS_ENABLED
26+
27+
Whether to apply the `julia_unpaired_parenthetical` face to unpaired closing
28+
parenthesis (`)`, `]`, '}').
29+
"""
1130
const UNMATCHED_DELIMITERS_ENABLED = Ref(true)
31+
"""
32+
SINGLETON_IDENTIFIERS
1233
34+
Symbols that represent identifiers known to be instances of a singleton type,
35+
currently just `Nothing` and `Missing`.
36+
"""
1337
const SINGLETON_IDENTIFIERS = (:nothing, :missing)
1438

39+
"""
40+
BASE_TYPE_IDENTIFIERS
41+
42+
A set of type identifiers defined in `Base` or `Core`.
43+
"""
1544
const BASE_TYPE_IDENTIFIERS =
1645
Set([n for n in names(Base, imported=true) if getglobal(Base, n) isa Type])
1746
Set([n for n in names(Core, imported=true) if getglobal(Core, n) isa Type])
1847

48+
"""
49+
BUILTIN_FUNCTIONS
50+
51+
A set of identifiers that are defined in `Core` and a `Core.Builtin`.
52+
"""
1953
const BUILTIN_FUNCTIONS =
2054
Set([n for n in names(Core) if getglobal(Base, n) isa Core.Builtin])
2155

56+
"""
57+
HIGHLIGHT_FACES
58+
59+
A list of `name => Face(...)` pairs that define the faces in
60+
`JuliaSyntaxHighlighting`. These are registered during module initialisation.
61+
"""
2262
const HIGHLIGHT_FACES = [
2363
# Julia syntax highlighting faces
2464
:julia_macro => Face(foreground=:magenta),
@@ -69,6 +109,18 @@ const HIGHLIGHT_FACES = [
69109

70110
__init__() = foreach(addface!, HIGHLIGHT_FACES)
71111

112+
"""
113+
paren_type(k::Kind) -> (Int, Symbol)
114+
115+
Return a pair of values giving the change in nesting depth
116+
caused by the paren `k` (+1 or -1), as well as a symbol
117+
indicating the kind of parenthesis:
118+
- `(` and `)` are a `paren`
119+
- `[` and `]` are a `bracket`
120+
- `{` and `}` are a `curly`
121+
122+
Anything else is of type `none`, and produced a depth change of `0`.
123+
"""
72124
function paren_type(k::Kind)
73125
if k == K"("; 1, :paren
74126
elseif k == K")"; -1, :paren
@@ -101,13 +153,33 @@ struct HighlightContext{S <: AbstractString}
101153
pdepths::ParenDepthCounter
102154
end
103155

156+
"""
157+
_hl_annotations(content::AbstractString, ast::GreenNode) -> Vector{Tuple{UnitRange{Int}, Pair{Symbol, Any}}}
158+
159+
Generate a list of `(range, annot)` pairs for the given `content` and `ast`.
160+
161+
The `range` is a `UnitRange{Int}` that indexes into `ctx.content` and
162+
`annot` is a `Pair` of the form `:face => <face>`.
163+
164+
This is a small wrapper around [`_hl_annotations!`](@ref) for convenience.
165+
"""
104166
function _hl_annotations(content::AbstractString, ast::GreenNode)
105167
highlights = Vector{Tuple{UnitRange{Int}, Pair{Symbol, Any}}}()
106168
ctx = HighlightContext(content, 0, ast, ParenDepthCounter())
107169
_hl_annotations!(highlights, GreenLineage(ast, nothing), ctx)
108170
highlights
109171
end
110172

173+
"""
174+
_hl_annotations!(highlights::Vector{Tuple{UnitRange{Int}, Pair{Symbol, Any}}},
175+
lineage::GreenLineage, ctx::HighlightContext)
176+
177+
Populate `highlights` with `(range, annot)` pairs for the given `lineage` and `ctx`,
178+
where `lineage` is expected to be consistent with `ctx.offset` and `ctx.lnode`.
179+
180+
The `range` is a `UnitRange{Int}` that indexes into `ctx.content` and
181+
`annot` is a `Pair` of the form `:face => <face>`.
182+
"""
111183
function _hl_annotations!(highlights::Vector{Tuple{UnitRange{Int}, Pair{Symbol, Any}}},
112184
lineage::GreenLineage, ctx::HighlightContext)
113185
(; node, parent) = lineage

0 commit comments

Comments
 (0)