Skip to main content

scal_core/
highlight_specs.rs

1#![allow(missing_docs)]
2//! Internal functions to set up highlight specs for syntax highlighting using Tree-sitter.
3use crate::{Syntax, theme::HighlightSpec};
4#[must_use]
5pub fn all_specs() -> Vec<(Syntax, HighlightSpec)> {
6    vec![
7        (Syntax::Rust, rust_spec()),
8        (Syntax::Nix, nix_spec()),
9        (Syntax::JS, js_spec()),
10        (Syntax::Zig, zig_spec()),
11        (Syntax::Python, python_spec()),
12    ]
13}
14#[must_use]
15pub fn rust_spec() -> HighlightSpec {
16    HighlightSpec::new(
17        vec![
18            "attribute",
19            "comment",
20            "constant",
21            "constant.builtin",
22            "constructor",
23            "embedded",
24            "escape",
25            "function",
26            "function.builtin",
27            "function.macro",
28            "keyword",
29            "keyword.function",
30            "keyword.operator",
31            "keyword.return",
32            "label",
33            "lifetime",
34            "macro",
35            "method",
36            "module",
37            "namespace",
38            "number",
39            "operator",
40            "property",
41            "field",
42            "punctuation",
43            "punctuation.bracket",
44            "punctuation.delimiter",
45            "punctuation.special",
46            "string",
47            "string.special",
48            "type",
49            "type.builtin",
50            "variable",
51            "variable.builtin",
52            "variable.parameter",
53            "self",
54        ],
55        vec![
56            12, // attribute
57            3,  // comment
58            8,  // constant          (was 11 — dark orange for enum variants like TypeWriter)
59            8,  // constant.builtin
60            9,  // constructor       (was 14 — light orange like types)
61            5,  // embedded
62            10, // escape
63            13, // function
64            13, // function.builtin
65            8,  // function.macro      (was 13 — red)
66            14, // keyword           (was 8 — purple)
67            14, // keyword.function
68            14, // keyword.operator
69            14, // keyword.return
70            12, // label
71            14, // lifetime          (was 8 — purple)
72            8,  // macro               (was 13 — red)
73            13, // method
74            10, // module            (was 14 — light orange/almost yellow)
75            10, // namespace         (was 14 — light orange/almost yellow)
76            9,  // number            (dark orange)
77            15, // operator
78            5,  // property
79            5,  // field
80            15, // punctuation
81            5,  // punctuation.bracket
82            15, // punctuation.delimiter
83            15, // punctuation.special
84            11, // string            (was 10 — green)
85            11, // string.special
86            10, // type              (was 14 — light orange/almost yellow)
87            10, // type.builtin      (was 14 — light orange/almost yellow)
88            8,  // variable            (was 5 — red for let bindings)
89            5,  // variable.builtin
90            5,  // variable.parameter  (kept gray for fn params like `n`)
91            5,  // self
92        ],
93    )
94}
95
96#[must_use]
97pub fn nix_spec() -> HighlightSpec {
98    HighlightSpec::new(
99        vec![
100            "comment",
101            "keyword",
102            "function",
103            "builtin",
104            "string",
105            "number",
106            "attribute",
107            "variable",
108            "operator",
109            "punctuation",
110            "path",
111            "boolean",
112            "null",
113        ],
114        vec![
115            3,  // comment
116            8,  // keyword
117            13, // function
118            11, // builtin
119            10, // string
120            9,  // number
121            6,  // attribute
122            5,  // variable
123            7,  // operator
124            4,  // punctuation
125            6,  // path
126            11, // boolean
127            5,  // null
128        ],
129    )
130}
131#[must_use]
132pub fn python_spec() -> HighlightSpec {
133    HighlightSpec::new(
134        vec![
135            "comment",
136            "keyword",
137            "function",
138            "builtin",
139            "type",
140            "string",
141            "number",
142            "constant",
143            "variable",
144            "attribute",
145            "operator",
146            "punctuation",
147            "decorator",
148            "exception",
149            "boolean",
150            "none",
151        ],
152        vec![
153            3,  // comment
154            8,  // keyword
155            13, // function
156            13, // builtin
157            14, // type
158            10, // string
159            9,  // number
160            11, // constant
161            5,  // variable
162            6,  // attribute
163            7,  // operator
164            4,  // punctuation
165            12, // decorator
166            8,  // exception
167            11, // boolean
168            5,  // none
169        ],
170    )
171}
172#[must_use]
173pub fn js_spec() -> HighlightSpec {
174    HighlightSpec::new(
175        vec![
176            "comment",
177            "keyword",
178            "function",
179            "method",
180            "class",
181            "string",
182            "number",
183            "constant",
184            "variable",
185            "property",
186            "operator",
187            "punctuation",
188            "tag",
189            "attribute",
190            "boolean",
191            "null",
192            "regex",
193        ],
194        vec![
195            3,  // comment
196            8,  // keyword
197            13, // function
198            13, // method
199            14, // class (mapped to type-ish color slot)
200            10, // string
201            9,  // number
202            11, // constant
203            5,  // variable
204            6,  // property
205            7,  // operator
206            4,  // punctuation
207            12, // tag (jsx/html-like)
208            6,  // attribute
209            11, // boolean
210            5,  // null
211            10, // regex
212        ],
213    )
214}
215#[must_use]
216pub fn zig_spec() -> HighlightSpec {
217    HighlightSpec::new(
218        vec![
219            "comment",
220            "keyword",
221            "function",
222            "type",
223            "string",
224            "number",
225            "constant",
226            "variable",
227            "field",
228            "operator",
229            "punctuation",
230            "builtin",
231            "boolean",
232            "null",
233            "error",
234        ],
235        vec![
236            3,  // comment
237            8,  // keyword
238            13, // function
239            14, // type
240            10, // string
241            9,  // number
242            11, // constant
243            5,  // variable
244            6,  // field
245            7,  // operator
246            4,  // punctuation
247            11, // builtin
248            11, // boolean
249            5,  // null
250            8,  // error
251        ],
252    )
253}