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

Commit 5be43db

Browse files
Merge pull request #102 from mega-dean/highlight-namespaced-types
add `.` to `zig-re-identifier` to highlight namespaced types
2 parents b6f5375 + 1870363 commit 5be43db

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ INIT_PACKAGES="(progn \
1919
(package-install pkg))) \
2020
)"
2121

22-
"${EMACS}" --eval "${INIT_PACKAGES}" --batch -l zig-mode.el -l tests.el -f ert-run-tests-batch-and-exit
22+
"${EMACS}" --eval "${INIT_PACKAGES}" --batch -l zig-mode.el -l test/zig-tests.el -f ert-run-tests-batch-and-exit

test/zig-tests.el

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ const python =
118118
("void" font-lock-type-face)
119119
)))
120120

121+
(ert-deftest test-font-lock-parameters-with-periods ()
122+
(zig-test-font-lock
123+
"fn doSomething(arg: thing.with.periods) void {}"
124+
'(("fn" font-lock-keyword-face)
125+
("doSomething" font-lock-function-name-face)
126+
("arg" font-lock-variable-name-face)
127+
("thing.with.periods" font-lock-type-face)
128+
("void" font-lock-type-face)
129+
)))
130+
131+
(ert-deftest test-font-lock-struct-type-with-periods ()
132+
(zig-test-font-lock
133+
"const S = struct { field: thing.with.periods }; "
134+
'(("const" font-lock-keyword-face)
135+
("S" font-lock-variable-name-face)
136+
("struct" font-lock-keyword-face)
137+
("field" font-lock-variable-name-face)
138+
("thing.with.periods" font-lock-type-face)
139+
)))
140+
121141
;; Test all permutations of '?', '*', '[]', '* const', and '[] const' for 3 of those in a row
122142
;; For example, ??[]Bar or [][]const *Bar
123143
(ert-deftest test-font-lock-parameters-optionals-pointers-and-arrays ()

zig-mode.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ If given a SOURCE, execute the CMD on it."
134134
(concat "\\(?:" zig-re-optional "\\|" zig-re-pointer "\\|" zig-re-array "\\)*"))
135135

136136
(defconst zig-re-identifier "[[:word:]_][[:word:]_[:digit:]]*")
137+
(defconst zig-re-type "[[:word:]_.][[:word:]_.[:digit:]]*")
137138
(defconst zig-re-type-annotation
138139
(concat (zig-re-grab zig-re-identifier)
139140
"[[:space:]]*:[[:space:]]*"
140141
zig-re-optionals-pointers-arrays
141-
(zig-re-grab zig-re-identifier)))
142+
(zig-re-grab zig-re-type)))
142143

143144
(defun zig-re-definition (dtype)
144145
"Construct a regular expression for definitions of type DTYPE."

0 commit comments

Comments
 (0)