branch: elpa/zig-mode commit 53d4939a2893d802d6f036274acb35a7d527acd8 Author: Jacob Young <jacob...@users.noreply.github.com> Commit: Jacob Young <jacob...@users.noreply.github.com>
highlight all int types --- test/zig-tests.el | 11 ++++++ zig-mode.el | 108 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 67 insertions(+), 52 deletions(-) diff --git a/test/zig-tests.el b/test/zig-tests.el index dab4bb2dd2..4ac3626a08 100644 --- a/test/zig-tests.el +++ b/test/zig-tests.el @@ -164,6 +164,17 @@ const python = ("void" font-lock-type-face))))) (zig-test-font-lock test-string expected)))) +(ert-deftest test-font-lock-int-types () + (zig-test-font-lock + "const Types = .{ u0, i7, u33, i123, u55555 };" + '(("const" font-lock-keyword-face) + ("Types" font-lock-variable-name-face) + ("u0" font-lock-type-face) + ("i7" font-lock-type-face) + ("u33" font-lock-type-face) + ("i123" font-lock-type-face) + ("u55555" font-lock-type-face)))) + ;;===========================================================================;; ;; Indentation tests diff --git a/zig-mode.el b/zig-mode.el index 6742917736..f2b8831d06 100644 --- a/zig-mode.el +++ b/zig-mode.el @@ -163,55 +163,6 @@ If given a SOURCE, execute the CMD on it." table)) -(defconst zig-keywords - '(;; Storage - "const" "var" "extern" "packed" "export" "pub" "noalias" "inline" - "noinline" "comptime" "callconv" "volatile" "allowzero" - "align" "linksection" "threadlocal" "addrspace" - - ;; Structure - "struct" "enum" "union" "error" "opaque" - - ;; Statement - "break" "return" "continue" "asm" "defer" "errdefer" "unreachable" - "try" "catch" "async" "nosuspend" "await" "suspend" "resume" - - ;; Conditional - "if" "else" "switch" "and" "or" "orelse" - - ;; Repeat - "while" "for" - - ;; Other keywords - "fn" "usingnamespace" "test")) - -(defconst zig-types - '(;; Integer types - "i2" "u2" "i3" "u3" "i4" "u4" "i5" "u5" "i6" "u6" "i7" "u7" "i8" "u8" - "i16" "u16" "i29" "u29" "i32" "u32" "i64" "u64" "i128" "u128" - "isize" "usize" - - ;; Floating types - "f16" "f32" "f64" "f80" "f128" - - ;; C types - "c_char" "c_short" "c_ushort" "c_int" "c_uint" "c_long" "c_ulong" - "c_longlong" "c_ulonglong" "c_longdouble" - - ;; Comptime types - "comptime_int" "comptime_float" - - ;; Other types - "bool" "void" "noreturn" "type" "error" "anyerror" "anyframe" "anytype" - "anyopaque")) - -(defconst zig-constants - '(;; Boolean - "true" "false" - - ;; Other constants - "null" "undefined")) - (defconst zig-electric-indent-chars '(?\; ?\, ?\) ?\] ?\})) @@ -225,9 +176,62 @@ If given a SOURCE, execute the CMD on it." (,(concat "@" zig-re-identifier) . font-lock-builtin-face) ;; Keywords, constants and types - (,(regexp-opt zig-keywords 'symbols) . font-lock-keyword-face) - (,(regexp-opt zig-constants 'symbols) . font-lock-constant-face) - (,(regexp-opt zig-types 'symbols) . font-lock-type-face) + (,(rx symbol-start + (| + ;; Storage + "const" "var" "extern" "packed" "export" "pub" "noalias" "inline" + "noinline" "comptime" "callconv" "volatile" "allowzero" + "align" "linksection" "threadlocal" "addrspace" + + ;; Structure + "struct" "enum" "union" "error" "opaque" + + ;; Statement + "break" "return" "continue" "asm" "defer" "errdefer" "unreachable" + "try" "catch" "async" "nosuspend" "await" "suspend" "resume" + + ;; Conditional + "if" "else" "switch" "and" "or" "orelse" + + ;; Repeat + "while" "for" + + ;; Other keywords + "fn" "usingnamespace" "test") + symbol-end) + . font-lock-keyword-face) + + (,(rx symbol-start + (| + ;; Boolean + "true" "false" + + ;; Other constants + "null" "undefined") + symbol-end) + . font-lock-constant-face) + + (,(rx symbol-start + (| + ;; Integer types + (: (any ?i ?u) (| ?0 (: (any (?1 . ?9)) (* digit)))) + "isize" "usize" + + ;; Floating types + "f16" "f32" "f64" "f80" "f128" + + ;; C types + "c_char" "c_short" "c_ushort" "c_int" "c_uint" "c_long" "c_ulong" + "c_longlong" "c_ulonglong" "c_longdouble" + + ;; Comptime types + "comptime_int" "comptime_float" + + ;; Other types + "bool" "void" "noreturn" "type" "anyerror" "anyframe" "anytype" + "anyopaque") + symbol-end) + . font-lock-type-face) ;; Type annotations (both variable and type) (,zig-re-type-annotation 1 font-lock-variable-name-face)