@@ -6,19 +6,59 @@ using StyledStrings: Face, addface!
6
6
7
7
public highlight, highlight!
8
8
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
+ """
9
15
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
+ """
10
23
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
+ """
11
30
const UNMATCHED_DELIMITERS_ENABLED = Ref (true )
31
+ """
32
+ SINGLETON_IDENTIFIERS
12
33
34
+ Symbols that represent identifiers known to be instances of a singleton type,
35
+ currently just `Nothing` and `Missing`.
36
+ """
13
37
const SINGLETON_IDENTIFIERS = (:nothing , :missing )
14
38
39
+ """
40
+ BASE_TYPE_IDENTIFIERS
41
+
42
+ A set of type identifiers defined in `Base` or `Core`.
43
+ """
15
44
const BASE_TYPE_IDENTIFIERS =
16
45
Set ([n for n in names (Base, imported= true ) if getglobal (Base, n) isa Type]) ∪
17
46
Set ([n for n in names (Core, imported= true ) if getglobal (Core, n) isa Type])
18
47
48
+ """
49
+ BUILTIN_FUNCTIONS
50
+
51
+ A set of identifiers that are defined in `Core` and a `Core.Builtin`.
52
+ """
19
53
const BUILTIN_FUNCTIONS =
20
54
Set ([n for n in names (Core) if getglobal (Base, n) isa Core. Builtin])
21
55
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
+ """
22
62
const HIGHLIGHT_FACES = [
23
63
# Julia syntax highlighting faces
24
64
:julia_macro => Face (foreground= :magenta ),
@@ -69,6 +109,18 @@ const HIGHLIGHT_FACES = [
69
109
70
110
__init__ () = foreach (addface!, HIGHLIGHT_FACES)
71
111
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
+ """
72
124
function paren_type (k:: Kind )
73
125
if k == K " (" ; 1 , :paren
74
126
elseif k == K " )" ; - 1 , :paren
@@ -101,13 +153,33 @@ struct HighlightContext{S <: AbstractString}
101
153
pdepths:: ParenDepthCounter
102
154
end
103
155
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
+ """
104
166
function _hl_annotations (content:: AbstractString , ast:: GreenNode )
105
167
highlights = Vector {Tuple{UnitRange{Int}, Pair{Symbol, Any}}} ()
106
168
ctx = HighlightContext (content, 0 , ast, ParenDepthCounter ())
107
169
_hl_annotations! (highlights, GreenLineage (ast, nothing ), ctx)
108
170
highlights
109
171
end
110
172
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
+ """
111
183
function _hl_annotations! (highlights:: Vector{Tuple{UnitRange{Int}, Pair{Symbol, Any}}} ,
112
184
lineage:: GreenLineage , ctx:: HighlightContext )
113
185
(; node, parent) = lineage
0 commit comments