;;; ztl-mode.el --- Major mode for editing Ztl code -*- lexical-binding: t; -*- ;; ;; Licensed under the GPLv3 License. (require 'font-lock) (defvar ztl-keywords '("fn" "to" "in" "is" "as" "use" "set" "if" "else" "for" "loop" "concurrent" "while" "push" "pop" "return" "const" "type" "this" "eq" "ne" "do" "panic" "mod" "not" "and" "or" "xor" "band" "bor" "bxor" "srl" "sll" "let") "Keywords in Ztl.") (defvar ztl-types '("byte" "str" "int" "real" "logical" "bool" "err" "i8" "i16" "i32" "i64" "i128" "f8" "f16" "f32" "f64" "f128") "Types in Ztl.") (defvar ztl-constants '("true" "false" "nil") "Constants in Ztl.") (defvar ztl-font-lock-keywords (list ;; Constants (cons (regexp-opt ztl-constants 'words) font-lock-constant-face) ;; Keywords (cons (regexp-opt ztl-keywords 'words) font-lock-keyword-face) ;; Types (cons (regexp-opt ztl-types 'words) font-lock-type-face) ;; Structs (PascalCase) '("\\b[A-Z][A-Za-z0-9_]*\\b" . font-lock-type-face) ;; Numbers '("\\b\\([0-9]+\\(?:\\.[0-9]*\\)?\\)\\b" . font-lock-number-face) ;; Function calls '("\\b\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s-*(" (1 font-lock-function-name-face)) ) "Font lock definitions for Ztl.") (defvar ztl-syntax-table (let ((table (make-syntax-table))) ;; Comments: C and C++ style (modify-syntax-entry ?/ ". 14b" table) (modify-syntax-entry ?* ". 23" table) (modify-syntax-entry ?\n ">" table) ;; Strings (modify-syntax-entry ?\" "\"" table) (modify-syntax-entry ?\\ "\\" table) table) "Syntax table for `ztl-mode'.") (define-derived-mode ztl-mode prog-mode "ZTL" "Major mode for editing Ztl source files." :syntax-table ztl-syntax-table :group 'ztl (setq-local font-lock-defaults '(ztl-font-lock-keywords)) (setq-local comment-start "//") (setq-local comment-end "") (setq-local syntax-propertize-function (syntax-propertize-rules ;; Line comments starting with // ("\\(//\\)\\(?:[^\n]*\\)" (1 "<"))))) ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ztl\\'" . ztl-mode)) (provide 'ztl-mode) ;; End of ztl-mode.el