ztl-mode/ztl-mode.el

52 lines
2.3 KiB
EmacsLisp

;;; Zongor's Transpiler Language (ZTL) mode for Emacs
;; Author: Zongor
;; Version: 0.0.1
(defvar ztl-constants
'("true" "false"))
(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-keywords2
'("char" "str" "f16" "f32" "f64" "f128"))
(defvar ztl-operators
'(";"))
(defvar ztl-functions
'("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-font-lock-defaults
`((("\\<\\(!!.*?!!\\)\\>" . font-lock-comment-face) ; Block comments
("!!.*" . font-lock-comment-face) ; Line comments
("\\<\\(!.*\\)" . font-lock-comment-face) ; Line comments
("\\<\\([A-Z][%w_]*\\)\\>" . font-lock-keyword2-face) ; Keywords2
("\\<\\([viu][%d_]+\\)\\>" . font-lock-keyword2-face) ; Keywords2
("\\<\\([9][%w_]*\\)\\>" . font-lock-keyword2-face) ; Keywords2
("\\<\\([A-Z][%w_]*\\)\\>" . font-lock-keyword2-face) ; Keywords2
("\\<\\(-?%.?%d+f?\\)\\>" . font-lock-constant-face) ; Numbers
("\\<\\(fn\\)\\>\\s-*\\(\\([%a_][%w_]*\\)\\s*%(" . (1 font-lock-keyword-face) (2 font-lock-function-name-face)) ; Function definitions
(,(regexp-opt ztl-keywords 'words) . font-lock-keyword-face) ; Keywords
(,(regexp-opt ztl-keywords2 'words) . font-lock-builtin-face) ; Keywords2
(,(regexp-opt ztl-constants 'words) . font-lock-constant-face) ; Constants
(,(regexp-opt ztl-operators 'words) . font-lock-builtin-face) ; Operators
("\"\\([^\"]*\\)\"" . font-lock-string-face) ; Strings
("'\\([^']*\\)'" . font-lock-string-face) ; Strings
))
(define-derived-mode ztl-mode fundamental-mode "ZTL"
"Major mode for editing ZTL files."
(setq font-lock-defaults ztl-font-lock-defaults)
(setq comment-start "!")
(setq comment-end "")
(modify-syntax-entry ?! "<" ztl-mode-syntax-table)
(modify-syntax-entry ?\n ">" ztl-mode-syntax-table)
(modify-syntax-entry ?\" "\"" ztl-mode-syntax-table)
(modify-syntax-entry ?\' "\"" ztl-mode-syntax-table)
(modify-syntax-entry ?\\ "\\" ztl-mode-syntax-table))
(provide 'ztl-mode)