[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/zig-mode 0babe7e 103/104: Merge pull request #59 from eric
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/zig-mode 0babe7e 103/104: Merge pull request #59 from eric-p-hutchins/params-with-optionals-pointers-and-arrays-oh-my |
Date: |
Sun, 29 Aug 2021 11:37:11 -0400 (EDT) |
branch: elpa/zig-mode
commit 0babe7ec524f59d57c01e2fc66294d1afa01f5eb
Merge: 8ad244b 3e3c0d5
Author: Joachim Schmidt <joachim.schmidt557@outlook.com>
Commit: GitHub <noreply@github.com>
Merge pull request #59 from
eric-p-hutchins/params-with-optionals-pointers-and-arrays-oh-my
Fix font-lock of parameters with optional, pointer or array types
---
tests.el | 41 +++++++++++++++++++++++++++++++++++++++++
zig-mode.el | 8 ++++++++
2 files changed, 49 insertions(+)
diff --git a/tests.el b/tests.el
index 83171f2..e0ef563 100644
--- a/tests.el
+++ b/tests.el
@@ -101,6 +101,47 @@ const python =
("\\\\def main():\n" zig-multiline-string-face)
("\\\\ print(\"Hello, world!\")\n" zig-multiline-string-face))))
+(ert-deftest test-font-lock-parameters-pointers-and-arrays ()
+ (zig-test-font-lock
+ "fn doSomething(thingPtr: *Thing, string: []const u8, maybeFoo: ?Foo) void
{}"
+ '(("fn" font-lock-keyword-face)
+ ("doSomething" font-lock-function-name-face)
+ ("thingPtr" font-lock-variable-name-face)
+ ("Thing" font-lock-type-face)
+ ("string" font-lock-variable-name-face)
+ ("const" font-lock-keyword-face)
+ ("u8" font-lock-type-face)
+ ("maybeFoo" font-lock-variable-name-face)
+ ("Foo" font-lock-type-face)
+ ("void" 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 ()
+ (dotimes (i (* 5 5 5))
+ (let* ((int-to-opt-ptr-array (lambda (x)
+ (pcase x (0 "?") (1 "*") (2 "[]") (3
"*const ") (4 "[]const "))))
+ (first-symbol-int (/ i (* 5 5)))
+ (second-symbol-int (/ (% i (* 5 5)) 5))
+ (third-symbol-int (% i 5))
+ (first-symbol-const (>= first-symbol-int 3))
+ (second-symbol-const (>= second-symbol-int 3))
+ (third-symbol-const (>= third-symbol-int 3))
+ (first-symbol (funcall int-to-opt-ptr-array first-symbol-int))
+ (second-symbol (funcall int-to-opt-ptr-array second-symbol-int))
+ (third-symbol (funcall int-to-opt-ptr-array third-symbol-int))
+ (test-string (concat "fn foo(bar: " first-symbol second-symbol
third-symbol "Bar) void {}"))
+ (expected (append '(("fn" font-lock-keyword-face)
+ ("foo" font-lock-function-name-face)
+ ("bar" font-lock-variable-name-face))
+ (if first-symbol-const '(("const"
font-lock-keyword-face)) nil)
+ (if second-symbol-const '(("const"
font-lock-keyword-face)) nil)
+ (if third-symbol-const '(("const"
font-lock-keyword-face)) nil)
+ '(("Bar" font-lock-type-face)
+ ("void" font-lock-type-face)))))
+ (zig-test-font-lock test-string expected))))
+
;;===========================================================================;;
;; Indentation tests
diff --git a/zig-mode.el b/zig-mode.el
index 2698162..efd703f 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -156,10 +156,18 @@ If given a SOURCE, execute the CMD on it."
"Construct a group regular expression for INNER."
(concat "\\(" inner "\\)"))
+(defconst zig-re-optional "\\(?:[[:space:]]*\\?[[:space:]]*\\)")
+(defconst zig-re-pointer
"\\(?:[[:space:]]*\\*\\(?:const[[:space:]]*\\)?[[:space:]]*\\)")
+(defconst zig-re-array
"\\(?:[[:space:]]*\\[[^]]*\\]\\(?:const[[:space:]]*\\)?[[:space:]]*\\)")
+
+(defconst zig-re-optionals-pointers-arrays
+ (concat "\\(?:" zig-re-optional "\\|" zig-re-pointer "\\|" zig-re-array
"\\)*"))
+
(defconst zig-re-identifier "[[: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)))
(defun zig-re-definition (dtype)
- [nongnu] elpa/zig-mode 8e0e610 086/104: Use (read-only-mode) instead of (toggle-read-only), (continued)
- [nongnu] elpa/zig-mode 8e0e610 086/104: Use (read-only-mode) instead of (toggle-read-only), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 12fe3c9 001/104: Initial commit, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 7c6323c 021/104: orelse, f16, comptime_int, comptime_float, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 3778fb5 030/104: Make indentation more nuanced (and add more tests for it), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9dc36e1 046/104: move defgroup and defcustom to the beginning of the code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 4eafa60 050/104: colorize compilation buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 107a67b 060/104: Runs `revert-buffer` after formatting on save., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode b4ae21a 061/104: Merge pull request #26 from Saikyun/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 6309295 069/104: Hide the *zig-fmt* window when formatting succeeds again, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 1e75c04 100/104: Remove irrelevant comment, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 0babe7e 103/104: Merge pull request #59 from eric-p-hutchins/params-with-optionals-pointers-and-arrays-oh-my,
ELPA Syncer <=
- [nongnu] elpa/zig-mode 2d0eb23 097/104: Merge pull request #55 from arqv/optim-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 232bfff 010/104: Merge pull request #2 from syohex/fix-package, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode fead48b 002/104: Initial revision., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c961a6d 005/104: noreturn., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 5b3b772 011/104: Removed hook., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode fb8d52f 017/104: License., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 4f281e4 020/104: Changed repository location, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c5315ff 026/104: Apply font-lock-doc-face to doc comments (for issue #5), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c2deea8 037/104: Merge pull request #14 from mgxm/imenu, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 52e3e20 004/104: README., ELPA Syncer, 2021/08/29