Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 53d4939

Browse files
committed
highlight all int types
1 parent a0ab963 commit 53d4939

File tree

2 files changed

+67
-52
lines changed

2 files changed

+67
-52
lines changed

test/zig-tests.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ const python =
164164
("void" font-lock-type-face)))))
165165
(zig-test-font-lock test-string expected))))
166166

167+
(ert-deftest test-font-lock-int-types ()
168+
(zig-test-font-lock
169+
"const Types = .{ u0, i7, u33, i123, u55555 };"
170+
'(("const" font-lock-keyword-face)
171+
("Types" font-lock-variable-name-face)
172+
("u0" font-lock-type-face)
173+
("i7" font-lock-type-face)
174+
("u33" font-lock-type-face)
175+
("i123" font-lock-type-face)
176+
("u55555" font-lock-type-face))))
177+
167178
;;===========================================================================;;
168179
;; Indentation tests
169180

zig-mode.el

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -163,55 +163,6 @@ If given a SOURCE, execute the CMD on it."
163163

164164
table))
165165

166-
(defconst zig-keywords
167-
'(;; Storage
168-
"const" "var" "extern" "packed" "export" "pub" "noalias" "inline"
169-
"noinline" "comptime" "callconv" "volatile" "allowzero"
170-
"align" "linksection" "threadlocal" "addrspace"
171-
172-
;; Structure
173-
"struct" "enum" "union" "error" "opaque"
174-
175-
;; Statement
176-
"break" "return" "continue" "asm" "defer" "errdefer" "unreachable"
177-
"try" "catch" "async" "nosuspend" "await" "suspend" "resume"
178-
179-
;; Conditional
180-
"if" "else" "switch" "and" "or" "orelse"
181-
182-
;; Repeat
183-
"while" "for"
184-
185-
;; Other keywords
186-
"fn" "usingnamespace" "test"))
187-
188-
(defconst zig-types
189-
'(;; Integer types
190-
"i2" "u2" "i3" "u3" "i4" "u4" "i5" "u5" "i6" "u6" "i7" "u7" "i8" "u8"
191-
"i16" "u16" "i29" "u29" "i32" "u32" "i64" "u64" "i128" "u128"
192-
"isize" "usize"
193-
194-
;; Floating types
195-
"f16" "f32" "f64" "f80" "f128"
196-
197-
;; C types
198-
"c_char" "c_short" "c_ushort" "c_int" "c_uint" "c_long" "c_ulong"
199-
"c_longlong" "c_ulonglong" "c_longdouble"
200-
201-
;; Comptime types
202-
"comptime_int" "comptime_float"
203-
204-
;; Other types
205-
"bool" "void" "noreturn" "type" "error" "anyerror" "anyframe" "anytype"
206-
"anyopaque"))
207-
208-
(defconst zig-constants
209-
'(;; Boolean
210-
"true" "false"
211-
212-
;; Other constants
213-
"null" "undefined"))
214-
215166
(defconst zig-electric-indent-chars
216167
'(?\; ?\, ?\) ?\] ?\}))
217168

@@ -225,9 +176,62 @@ If given a SOURCE, execute the CMD on it."
225176
(,(concat "@" zig-re-identifier) . font-lock-builtin-face)
226177

227178
;; Keywords, constants and types
228-
(,(regexp-opt zig-keywords 'symbols) . font-lock-keyword-face)
229-
(,(regexp-opt zig-constants 'symbols) . font-lock-constant-face)
230-
(,(regexp-opt zig-types 'symbols) . font-lock-type-face)
179+
(,(rx symbol-start
180+
(|
181+
;; Storage
182+
"const" "var" "extern" "packed" "export" "pub" "noalias" "inline"
183+
"noinline" "comptime" "callconv" "volatile" "allowzero"
184+
"align" "linksection" "threadlocal" "addrspace"
185+
186+
;; Structure
187+
"struct" "enum" "union" "error" "opaque"
188+
189+
;; Statement
190+
"break" "return" "continue" "asm" "defer" "errdefer" "unreachable"
191+
"try" "catch" "async" "nosuspend" "await" "suspend" "resume"
192+
193+
;; Conditional
194+
"if" "else" "switch" "and" "or" "orelse"
195+
196+
;; Repeat
197+
"while" "for"
198+
199+
;; Other keywords
200+
"fn" "usingnamespace" "test")
201+
symbol-end)
202+
. font-lock-keyword-face)
203+
204+
(,(rx symbol-start
205+
(|
206+
;; Boolean
207+
"true" "false"
208+
209+
;; Other constants
210+
"null" "undefined")
211+
symbol-end)
212+
. font-lock-constant-face)
213+
214+
(,(rx symbol-start
215+
(|
216+
;; Integer types
217+
(: (any ?i ?u) (| ?0 (: (any (?1 . ?9)) (* digit))))
218+
"isize" "usize"
219+
220+
;; Floating types
221+
"f16" "f32" "f64" "f80" "f128"
222+
223+
;; C types
224+
"c_char" "c_short" "c_ushort" "c_int" "c_uint" "c_long" "c_ulong"
225+
"c_longlong" "c_ulonglong" "c_longdouble"
226+
227+
;; Comptime types
228+
"comptime_int" "comptime_float"
229+
230+
;; Other types
231+
"bool" "void" "noreturn" "type" "anyerror" "anyframe" "anytype"
232+
"anyopaque")
233+
symbol-end)
234+
. font-lock-type-face)
231235

232236
;; Type annotations (both variable and type)
233237
(,zig-re-type-annotation 1 font-lock-variable-name-face)

0 commit comments

Comments
 (0)