[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/zig-mode 4232704 013/104: Rewritten from scratch for bette
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/zig-mode 4232704 013/104: Rewritten from scratch for better syntax highlighting. |
Date: |
Sun, 29 Aug 2021 11:36:54 -0400 (EDT) |
branch: elpa/zig-mode
commit 4232704cc73d32dc5889477d05b468fca4554679
Author: Andrea Orru <andreaorru1991@gmail.com>
Commit: Andrea Orru <andreaorru1991@gmail.com>
Rewritten from scratch for better syntax highlighting.
---
zig-mode.el | 165 ++++++++++++++++++++++++++++++++----------------------------
1 file changed, 87 insertions(+), 78 deletions(-)
diff --git a/zig-mode.el b/zig-mode.el
index a19c200..c8fb625 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -1,6 +1,6 @@
;;; zig-mode.el --- A major mode for the Zig programming language -*-
lexical-binding: t -*-
-;; Version: 0.0.1
+;; Version: 0.0.2
;; Author: Andrea Orru <andreaorru1991@gmail.com>, Andrew Kelley
<superjoe30@gmail.com>
;; Keywords: zig, languages
;; Package-Requires: ((emacs "24.0"))
@@ -13,100 +13,109 @@
(require 'cc-mode)
-(defvar zig--builtins
- '("@addWithOverflow"
- "@mulWithOverflow"
- "@shlWithOverflow"
- "@subWithOverflow"
- "@divExact"
-
- "@cDefine" "@cImport" "@cInclude" "@cUndef"
- "@setGlobalAlign" "@setGlobalLinkage" "@setGlobalSection"
- "@setDebugSafety"
-
- "@alignOf" "@sizeOf"
- "@typeName" "@typeOf"
- "@intType" "@isFloat" "@isInteger"
- "@maxValue" "@minValue"
- "@memberCount"
- "@canImplicitCast"
-
- "@alloca"
- "@memcpy" "@memset"
-
- "@compileError" "@compileLog" "@compileVar"
- "@errorName"
- "@panic"
-
- "@import" "@embedFile"
- "@clz"
- "@cmpxchg"
- "@ctz"
- "@fence"
- "@generatedCode"
- "@truncate"
- "@unreachable"))
-
-(defvar zig--keywords
- '("asm"
- "noalias"
- "unreachable"
- "use"
+(defun zig-re-word (inner)
+ "Construct a regular expression for the word INNER."
+ (concat "\\<" inner "\\>"))
+
+(defun zig-re-grab (inner)
+ "Construct a group regular expression for INNER."
+ (concat "\\(" inner "\\)"))
+
+(defconst zig-re-identifier "[[:word:]_][[:word:]_[:digit:]]*")
+(defconst zig-re-type-annotation
+ (concat (zig-re-grab zig-re-identifier)
+ "[[:space:]]*:[[:space:]]*"
+ (zig-re-grab zig-re-identifier)))
+
+(defun zig-re-definition (dtype)
+ "Construct a regular expression for definitions of type DTYPE."
+ (concat (zig-re-word dtype) "[[:space:]]+" (zig-re-grab zig-re-identifier)))
+
+(defconst zig-syntax-table
+ (let ((table (make-syntax-table)))
+
+ ;; Operators
+ (dolist (i '(?+ ?- ?* ?/ ?% ?& ?| ?= ?! ?< ?>))
+ (modify-syntax-entry i "." table))
+
+ ;; Strings
+ (modify-syntax-entry ?\' "\"" table)
+ (modify-syntax-entry ?\" "\"" table)
+ (modify-syntax-entry ?\\ "\\" table)
- "coldcc" "nakedcc"
- "export" "extern" "inline" "pub"
- "fn"
+ ;; Comments
+ (modify-syntax-entry ?/ ". 12" table)
+ (modify-syntax-entry ?\n ">" table)
- "enum" "struct" "union"
- "packed"
- "comptime"
- "const" "var"
+ table))
+
+(defconst zig-keywords
+ '("const" "var"
+ "export" "extern" "pub"
+
+ "noalias"
+ "inline" "comptime"
+ "nakedcc" "coldcc"
"volatile"
- "try"
- "defer"
+ "packed" "struct" "enum" "union"
+ "fn" "use" "test"
- "if" "else"
- "for" "while"
- "goto" "break" "continue"
- "or" "and"
- "switch"
- "return"))
+ "asm" "goto" "try"
+ "break" "return" "continue" "defer"
+ "unreachable"
-(defvar zig--constants
- '("null"
- "this"
- "true" "false"
- "undefined"))
+ "if" "else" "switch"
+ "and" "or"
-(defvar zig--types
- '("Unreachable"
- "error"
- "type"
+ "while" "for"))
- "bool"
- "c_int" "c_long" "c_long_double" "c_longlong" "c_short"
- "c_uint" "c_ulong" "c_ulonglong" "c_ushort"
+(defconst zig-types
+ '("void" "noreturn" "type" "error"
"i8" "i16" "i32" "i64" "isize"
"u8" "u16" "u32" "u64" "usize"
"f32" "f64"
+ "bool"
- "noreturn"
- "void"))
-
-(defvar zig--font-lock-keywords
- `((,(regexp-opt zig--keywords 'symbols) . font-lock-keyword-face)
- (,(regexp-opt zig--builtins ) . font-lock-builtin-face)
- (,(regexp-opt zig--constants 'symbols) . font-lock-constant-face)
- (,(regexp-opt zig--types 'symbols) . font-lock-type-face)))
-
+ "c_short" "c_int" "c_long" "c_longlong"
+ "c_ushort" "c_uint" "c_ulong" "c_ulonglong"
+ "c_long_double"))
+
+(defconst zig-constants
+ '("null" "undefined" "this"
+ "true" "false"))
+
+(defvar zig-font-lock-keywords
+ (append
+ `(
+ ;; Builtins (prefixed with @)
+ (,(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)
+
+ ;; Type annotations (both variable and type)
+ (,zig-re-type-annotation 1 font-lock-variable-name-face)
+ (,zig-re-type-annotation 2 font-lock-type-face)
+ )
+
+ ;; Definitions
+ (mapcar #'(lambda (x)
+ (list (zig-re-definition (car x))
+ 1 (cdr x)))
+ '(("const" . font-lock-variable-name-face)
+ ("var" . font-lock-variable-name-face)
+ ("fn" . font-lock-function-name-face)))))
;;;###autoload
(define-derived-mode zig-mode c-mode "Zig"
- "A major mode for the Zig programming language."
+ "A major mode for the zig programming language."
+ :syntax-table zig-syntax-table
(setq c-basic-offset 4)
- (setq font-lock-defaults '(zig--font-lock-keywords)))
+ (setq font-lock-defaults '(zig-font-lock-keywords)))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.zig\\'" . zig-mode))
- [nongnu] elpa/zig-mode 3cac32b 040/104: Drop #' since it's redundant, (continued)
- [nongnu] elpa/zig-mode 3cac32b 040/104: Drop #' since it's redundant, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ab655a9 043/104: Add Commentary, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 1552e0e 058/104: Merge pull request #20 from mgxm/feat/add_zig_cli_integration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9d5b439 052/104: replace stdcallcc and nakedcc with callconv, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 859a4dc 071/104: Use rx macro and add more possibilities for type annotations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode f28e0fa 067/104: var has been changed to anytype, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9ca6876 072/104: Quote arguments passed to zig via the compile function, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 87841c7 082/104: fix broken multiline string highlighting, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 0c23862 003/104: Aestethics., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c298f91 019/104: Updated to latest keywords, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 4232704 013/104: Rewritten from scratch for better syntax highlighting.,
ELPA Syncer <=
- [nongnu] elpa/zig-mode 87f4f16 038/104: Escape ) and ] to avoding breaking Emacs Lisp syntax table, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode a716bdd 041/104: Require Emacs v24.3 for setq-local, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ef59edd 042/104: Prefer Homepage to URL, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 77202ac 044/104: update syntax keywords, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode d885809 068/104: Merge pull request #30 from joachimschmidt557/var-anytype, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode a0dc7dc 063/104: Merge pull request #27 from joachimschmidt557/add-nosuspend, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 89385d7 088/104: Make read-only-mode deactivation/activation explicit, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 3e3c0d5 102/104: Fix font-lock of parameters with optional, pointer or array types, ELPA Syncer, 2021/08/29
- [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