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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/raku-mode 1fb8435db1 028/253: Highlight variables


From: ELPA Syncer
Subject: [nongnu] elpa/raku-mode 1fb8435db1 028/253: Highlight variables
Date: Sat, 29 Jan 2022 08:28:36 -0500 (EST)

branch: elpa/raku-mode
commit 1fb8435db1cdeb54bc7fc867b4d8e614cfb49847
Author: Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
Commit: Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>

    Highlight variables
---
 perl6-font-lock.el      | 36 ++++++++++++++++++++++++++++++++----
 test/perl6-mode-test.el |  9 +++++++++
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/perl6-font-lock.el b/perl6-font-lock.el
index 7bdd193fa7..1d50daf7d2 100644
--- a/perl6-font-lock.el
+++ b/perl6-font-lock.el
@@ -81,6 +81,26 @@
   "Face for pragmas in Perl 6."
   :group 'perl6)
 
+(defface perl6-sigil
+  '((t :inherit font-lock-variable-name-face))
+  "Face for variable sigils in Perl 6."
+  :group 'perl6)
+
+(defface perl6-twigil
+  '((t :inherit font-lock-type-face))
+  "Face for variable twigils in Perl 6."
+  :group 'perl6)
+
+(defface perl6-var-package
+  '((t :inherit font-lock-variable-name-face))
+  "Face for variable names in Perl 6."
+  :group 'perl6)
+
+(defface perl6-var-name
+  '((t :inherit font-lock-variable-name-face))
+  "Face for variable names in Perl 6."
+  :group 'perl6)
+
 (eval-when-compile
   (require 'rx)
 
@@ -142,9 +162,8 @@
                             "KitchenSink" "Role" "Int" "Rat" "Buf" "UInt"
                             "Abstraction" "Numeric" "Real" "Nil"
                             "Mu")))
-      (identifier . ,(rx (and (any "A-Za-z")
-                              (1+ (or (any "A-Za-z0-9")
-                                      (and (any "-'") (any "A-Za-z")))))))))
+      (identifier . ,(rx (any "A-Za-z") (0+ (any "A-Za-z0-9"))
+                         (0+ (any "-'") (any "A-Za-z") (0+ (any 
"A-Za-z0-9")))))))
   (defmacro perl6-rx (&rest sexps)
     "Specialized `rx' variant for perl6-mode."
     (let ((rx-constituents (append perl6-rx-constituents rx-constituents)))
@@ -264,7 +283,7 @@ Takes arguments START and END which delimit the region to 
propertize."
     (funcall
      (syntax-propertize-rules
       ;; [-'] between identifiers are symbol chars
-      ((rx (any "A-Za-z") (group (any "-'")) (any "A-Za-z"))
+      ((rx (any "A-Za-z0-9") (group (any "-'")) (any "A-Za-z"))
        (1 "_"))
       ;; same for "::" around identifiers
       ((rx (or (and "::" symbol-start)
@@ -292,6 +311,15 @@ Takes STATE, the parse state."
 
 (defvar perl6-font-lock-keywords
   `(
+    (,(perl6-rx (group (1+ (char "@$%&")))
+                (group (opt (char ".^*?=!~")))
+                (group (opt (or (and "::" (0+ (and identifier "::")))
+                                (1+ identifier "::"))))
+                (group identifier symbol-end))
+     (1 'perl6-sigil)
+     (2 'perl6-twigil)
+     (3 'perl6-var-package)
+     (4 'perl6-var-name))
     (,(perl6-rx (group (any ".^")) (group identifier symbol-end))
      (1 'perl6-operator)
      (2 'perl6-identifier))
diff --git a/test/perl6-mode-test.el b/test/perl6-mode-test.el
index 3cb52014cd..e04abd02fa 100644
--- a/test/perl6-mode-test.el
+++ b/test/perl6-mode-test.el
@@ -105,6 +105,15 @@ bar #`<foo> baz"
   (perl6-test-with-temp-buffer "BEGIN {"
     (should (eq (perl6-test-face-at 1) 'perl6-phaser))))
 
+(ert-deftest perl5-font-lock-keywords/variable ()
+  :tags '(fontification syntax-table)
+  (perl6-test-with-temp-buffer "$::foo @!bar"
+    (should (eq (perl6-test-face-at 3) 'perl6-var-package))
+    (should (eq (perl6-test-face-at 4) 'perl6-var-name))
+    (should (eq (perl6-test-face-at 8) 'perl6-sigil))
+    (should (eq (perl6-test-face-at 9) 'perl6-twigil))
+    (should (eq (perl6-test-face-at 10) 'perl6-var-name))))
+
 (provide 'perl6-mode-test)
 
 ;; Local Variables:



reply via email to

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