emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]