ztl-mode/ztl-mode.el

65 lines
2.0 KiB
EmacsLisp

;;; Zongor's Transpiler Language (ZTL) mode for Emacs
;; Author: Zongor
;; Version: 0.0.1
;; Zongor's Transpiler Language (ZTL) mode for Emacs
;; Author: [Your Name]
;; Version: 1.0
(defconst ztl-mode-syntax-table
(let ((table (make-syntax-table)))
;; Comments start with '!' and end at the end of the line
(modify-syntax-entry ?! "<" table)
(modify-syntax-entry ?\n ">" table)
;; Strings can be enclosed in single or double quotes
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?\' "\"" table)
;; Operators
(modify-syntax-entry ?+ "." table)
(modify-syntax-entry ?- "." table)
(modify-syntax-entry ?* "." table)
(modify-syntax-entry ?/ "." table)
(modify-syntax-entry ?= "." table)
;; Brackets and parentheses
(modify-syntax-entry ?\( "()" table)
(modify-syntax-entry ?\) ")(" table)
(modify-syntax-entry ?\[ "[]" table)
(modify-syntax-entry ?\] "][" table)
;; Whitespace
(modify-syntax-entry ?\t " " table)
table))
(defconst ztl-font-lock-keywords
`(
;; Keywords
,(rx symbol-word
(or "fn" "to" "in" "is" "as" "use" "set" "if" "else" "for" "loop"
"while" "push" "pop" "return" "const" "type" "this" "do" "end"
"then" "result" "function" "eq" "ne" "mod" "not" "and" "or"
"xor" "band" "bor" "bxor" "srl" "sll" "char" "str" "f16" "f32"
"f64" "f128")
symbol-end)
;; Literals
,(rx (or "true" "false") symbol-end)
;; Function definitions
(,(rx symbol-start (one-or-more word-char) symbol-end whitespace (zero-or-more " ")) . font-lock-function-name-face))
)
(define-derived-mode ztl-mode prog-mode "ZTL"
"Major mode for editing Zongor's Transpiler Language (ZTL)."
;; Set the syntax table
(set-syntax-table ztl-mode-syntax-table)
;; Enable font lock
(font-lock-add-keywords 'ztl-mode ztl-font-lock-keywords))
;; Add to auto-mode-alist if needed
;;(add-to-list 'auto-mode-alist '("\\.ztl\\'" . ztl-mode))
(provide 'ztl-mode)