;;; ztl-mode.el --- Major mode for ZTL programs ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ztl\\'" . ztl-mode)) (defconst ztl-mode-syntax-table (let ((syn-table (make-syntax-table))) syn-table)) (defvar ztl-keywords '("fn" "to" "in" "is" "as" "use" "set" "if" "else" "for" "loop" "while" "push" "pop" "return" "const" "type" "this" "eq" "ne" "mod" "not" "and" "or" "xor" "band" "bor" "bxor" "srl" "sll")) (defvar ztl-types '("char" "str" "i8" "i16" "i32" "i64" "i128" "f8" "f16" "f32" "f64" "f128" "9p" "9pmsg")) (defvar ztl-font-lock-keywords `( ;; Comments ("!.*$" 0 font-lock-comment-face) ("!!\\(.*?\\)!!" 0 font-lock-comment-face) ;; Keywords (,(concat "\\<" (regexp-opt ztl-keywords) "\\>") 0 font-lock-keyword-face) ;; Types (,(concat "\\<" (regexp-opt ztl-types) "\\>") 0 font-lock-type-face) ;; Constants ("\\_<\\(true\\|false\\)\\>" 1 font-lock-constant-face) ;; Structs (PascalCased) ("\\_<\\([A-Z][a-zA-Z0-9_]+\\)\\>" 1 font-lock-type-face) ;; Function definitions ("\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\([ \t\n\r]*\\)(" 1 font-lock-function-name-face) ("\\b[0-9]+\\b" 1 font-lock-number-face) )) (define-derived-mode ztl-mode prog-mode "ZTL" "Major mode for ZTL programming." :syntax-table ztl-mode-syntax-table (setq font-lock-multiline t) (setq-local comment-start "!! ") (setq-local comment-end "!!") (setq-local comment-start-skip "!!+\\s-*") (set (make-local-variable 'font-lock-defaults) '(ztl-font-lock-keywords))) (provide 'ztl-mode)