From 80f73df28b03ca0da489f6024bf71b36a5416347 Mon Sep 17 00:00:00 2001 From: Matthew Hammer Date: Fri, 8 Mar 2019 11:06:22 -0700 Subject: [PATCH 1/4] initial ActorScript mode for emacs --- emacs/actorscript-mode.el | 131 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 emacs/actorscript-mode.el diff --git a/emacs/actorscript-mode.el b/emacs/actorscript-mode.el new file mode 100644 index 00000000000..beee398754c --- /dev/null +++ b/emacs/actorscript-mode.el @@ -0,0 +1,131 @@ +;; ActorScript major mode for Emacs +;; initially based on Swift Mode. + +(setq actorscript-font-lock-keywords + (let* ( + ;; define several category of keywords + ;; these are each taken from either ActorScript's `lexer.mll' or `prelude.ml' files. + (x-types + '("Any" + "None" + "Shared" + "Null" + "Bool" + "Nat" + "Int" + "Word8" + "Word16" + "Word32" + "Word64" + "Float" + "Char" + "Text")) + (x-constants + '("null" + "true" + "false" + )) + (x-keywords + '("actor" + "and" + "async" + "assert" + "await" + "break" + "case" + "class" + "continue" + "label" + "else" + "for" + "func" + "if" + "in" + "new" + "not" + "object" + "or" + "let" + "loop" + "private" + "return" + "shared" + "switch" + "type" + "var" + "while" + "prim" )) + (x-symbols + '( ;"(" + ;")" + ;"[" + ;"]" + ;"{" + ;"}" + ;";" + ;"," + ":" + "<:" + ;"." + "?" + "=" + "<" + ">" + ;"+" + "-" + "*" + "/" + "%" + "**" + "&" + ;"|" + ;"^" + "<<" + ">>" + "<<>" + "<>>" + "#" + "==" + "!=" + ">=" + "<=" + ":=" + "+=" + "-=" + "*=" + "/=" + "%=" + "**=" + "&=" + "|=" + "^=" + "<<=" + ">>=" + "<<>=" + "<>>=" + "#=" + )) + ;; generate regex string for each category of keywords + (x-types-regexp (regexp-opt x-types 'words)) + (x-constant-regexp (regexp-opt x-constants 'words)) + (x-keywords-regexp (regexp-opt x-keywords 'words)) + (x-symbols-regexp (regexp-opt x-symbols 'words)) + ) + ;; + `( + (,x-types-regexp . font-lock-type-face) + (,x-constant-regexp . font-lock-constant-face) + (,x-keywords-regexp . font-lock-keyword-face) + (,x-symbols-regexp . font-lock-keyword-face) + ))) + +(define-derived-mode actorscript-mode + swift-mode "ActorScript" + "Major mode for ActorScript, aka 'CanisterScript'." + (setq font-lock-defaults '((actorscript-font-lock-keywords))) + ) + +(add-to-list 'auto-mode-alist '("\\.as\\'" . actorscript-mode)) + +;; add the mode to the `features' list +(provide 'actorscript-mode) From d4c763626b8b8dddc73f184ff589c180eb973757 Mon Sep 17 00:00:00 2001 From: Matthew Hammer Date: Fri, 8 Mar 2019 11:18:59 -0700 Subject: [PATCH 2/4] module keyword --- emacs/actorscript-mode.el | 1 + 1 file changed, 1 insertion(+) diff --git a/emacs/actorscript-mode.el b/emacs/actorscript-mode.el index beee398754c..3fd8824683d 100644 --- a/emacs/actorscript-mode.el +++ b/emacs/actorscript-mode.el @@ -41,6 +41,7 @@ "func" "if" "in" + "module" "new" "not" "object" From ee4b495d3721c282d7f9fb71924567faee6c4b76 Mon Sep 17 00:00:00 2001 From: Matthew Hammer Date: Fri, 8 Mar 2019 11:49:27 -0700 Subject: [PATCH 3/4] fix font-lock for (most) symbols; special regex symbols still broken --- emacs/actorscript-mode.el | 43 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/emacs/actorscript-mode.el b/emacs/actorscript-mode.el index 3fd8824683d..5bd83e5f4ca 100644 --- a/emacs/actorscript-mode.el +++ b/emacs/actorscript-mode.el @@ -57,30 +57,30 @@ "while" "prim" )) (x-symbols - '( ;"(" - ;")" - ;"[" - ;"]" - ;"{" - ;"}" - ;";" - ;"," + '( "(" + ")" + "[" + "]" + "{" + "}" + ";" + "," ":" "<:" - ;"." - "?" + ;"\\." + ;"\\?" "=" "<" ">" - ;"+" + ;"\\+" "-" - "*" + ;"\\*" "/" "%" "**" "&" - ;"|" - ;"^" + "|" + ;"\\^" "<<" ">>" "<<>" @@ -106,18 +106,29 @@ "<>>=" "#=" )) + ;; xxx These still don't work: + (x-symbols-more + '( "\\." + "\\?" + "\\+" + "\\-" + "\\*" + "\\^" + )) ;; generate regex string for each category of keywords (x-types-regexp (regexp-opt x-types 'words)) (x-constant-regexp (regexp-opt x-constants 'words)) (x-keywords-regexp (regexp-opt x-keywords 'words)) - (x-symbols-regexp (regexp-opt x-symbols 'words)) + (x-symbols-regexp (regexp-opt x-symbols)) + (x-symbols-more-regexp (regexp-opt x-symbols-more)) ) ;; `( (,x-types-regexp . font-lock-type-face) (,x-constant-regexp . font-lock-constant-face) (,x-keywords-regexp . font-lock-keyword-face) - (,x-symbols-regexp . font-lock-keyword-face) + (,x-symbols-regexp . font-lock-builtin-face) + (,x-symbols-more-regexp . font-lock-builtin-face) ))) (define-derived-mode actorscript-mode From 189463d1bcfbfcd7542c4e7be127bd43de3d0c65 Mon Sep 17 00:00:00 2001 From: Matthew Hammer Date: Fri, 8 Mar 2019 11:56:41 -0700 Subject: [PATCH 4/4] bright braces --- emacs/actorscript-mode.el | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/emacs/actorscript-mode.el b/emacs/actorscript-mode.el index 5bd83e5f4ca..39ded3f1ab3 100644 --- a/emacs/actorscript-mode.el +++ b/emacs/actorscript-mode.el @@ -55,14 +55,20 @@ "type" "var" "while" - "prim" )) + "prim" + )) + ;; Braces introduce blocks; it's nice to make them stand + ;; out more than ordinary symbols + (x-braces + '( "{" + "}")) (x-symbols '( "(" ")" "[" "]" - "{" - "}" + ;"{" + ;"}" ";" "," ":" @@ -119,6 +125,7 @@ (x-types-regexp (regexp-opt x-types 'words)) (x-constant-regexp (regexp-opt x-constants 'words)) (x-keywords-regexp (regexp-opt x-keywords 'words)) + (x-braces-regexp (regexp-opt x-braces)) (x-symbols-regexp (regexp-opt x-symbols)) (x-symbols-more-regexp (regexp-opt x-symbols-more)) ) @@ -127,6 +134,7 @@ (,x-types-regexp . font-lock-type-face) (,x-constant-regexp . font-lock-constant-face) (,x-keywords-regexp . font-lock-keyword-face) + (,x-braces-regexp . font-lock-keyword-face) (,x-symbols-regexp . font-lock-builtin-face) (,x-symbols-more-regexp . font-lock-builtin-face) )))