Skip to content

Commit

Permalink
Merge pull request #102 from mega-dean/highlight-namespaced-types
Browse files Browse the repository at this point in the history
add `.` to `zig-re-identifier` to highlight namespaced types
  • Loading branch information
joachimschmidt557 authored Mar 25, 2024
2 parents b6f5375 + 1870363 commit 5be43db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ INIT_PACKAGES="(progn \
(package-install pkg))) \
)"

"${EMACS}" --eval "${INIT_PACKAGES}" --batch -l zig-mode.el -l tests.el -f ert-run-tests-batch-and-exit
"${EMACS}" --eval "${INIT_PACKAGES}" --batch -l zig-mode.el -l test/zig-tests.el -f ert-run-tests-batch-and-exit
20 changes: 20 additions & 0 deletions test/zig-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ const python =
("void" font-lock-type-face)
)))

(ert-deftest test-font-lock-parameters-with-periods ()
(zig-test-font-lock
"fn doSomething(arg: thing.with.periods) void {}"
'(("fn" font-lock-keyword-face)
("doSomething" font-lock-function-name-face)
("arg" font-lock-variable-name-face)
("thing.with.periods" font-lock-type-face)
("void" font-lock-type-face)
)))

(ert-deftest test-font-lock-struct-type-with-periods ()
(zig-test-font-lock
"const S = struct { field: thing.with.periods }; "
'(("const" font-lock-keyword-face)
("S" font-lock-variable-name-face)
("struct" font-lock-keyword-face)
("field" font-lock-variable-name-face)
("thing.with.periods" font-lock-type-face)
)))

;; Test all permutations of '?', '*', '[]', '* const', and '[] const' for 3 of those in a row
;; For example, ??[]Bar or [][]const *Bar
(ert-deftest test-font-lock-parameters-optionals-pointers-and-arrays ()
Expand Down
3 changes: 2 additions & 1 deletion zig-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ If given a SOURCE, execute the CMD on it."
(concat "\\(?:" zig-re-optional "\\|" zig-re-pointer "\\|" zig-re-array "\\)*"))

(defconst zig-re-identifier "[[:word:]_][[:word:]_[:digit:]]*")
(defconst zig-re-type "[[:word:]_.][[:word:]_.[:digit:]]*")
(defconst zig-re-type-annotation
(concat (zig-re-grab zig-re-identifier)
"[[:space:]]*:[[:space:]]*"
zig-re-optionals-pointers-arrays
(zig-re-grab zig-re-identifier)))
(zig-re-grab zig-re-type)))

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

0 comments on commit 5be43db

Please sign in to comment.