This commit is contained in:
zongor 2025-04-19 20:32:58 -04:00
parent 55e62a7975
commit 245ffaed4b
1 changed files with 47 additions and 57 deletions

View File

@ -1,74 +1,64 @@
;;; ztl-mode.el --- Zongor's Transpiler Language (ZTL) mode for Emacs -*- lexical-binding: t; -*- ;;; Zongor's Transpiler Language (ZTL) mode for Emacs
;; Author: Zongor ;; Author: Zongor
;; Version: 0.0.1 ;; Version: 0.0.1
(defconst ztl-mode-hook nil ;; Zongor's Transpiler Language (ZTL) mode for Emacs
"Hook for Zongor's Transpiler Language mode.") ;; Author: [Your Name]
;; Version: 1.0
(defconst ztl-file-extensions '(".ztl") (defconst ztl-mode-syntax-table
"List of file extensions for Zongor's Transpiler Language.") (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)
(defconst ztl-keywords ;; Strings can be enclosed in single or double quotes
'("fn" "to" "in" "is" "as" "use" "set" "if" "else" "for" "loop" "while" (modify-syntax-entry ?\" "\"" table)
"push" "pop" "return" "const" "type" "this" "do" "end" "then" "result" (modify-syntax-entry ?\' "\"" table)
"function" "eq" "ne" "mod" "not" "and" "or" "xor" "band" "bor" "bxor"
"srl" "sll")
"List of Zongor's Transpiler Language keywords.")
(defconst ztl-keywords-2 ;; Operators
'("char" "str" "f16" "f32" "f64" "f128") (modify-syntax-entry ?+ "." table)
"List of Zongor's Transpiler Language secondary keywords.") (modify-syntax-entry ?- "." table)
(modify-syntax-entry ?* "." table)
(modify-syntax-entry ?/ "." table)
(modify-syntax-entry ?= "." table)
(defconst ztl-literals ;; Brackets and parentheses
'("true" "false") (modify-syntax-entry ?\( "()" table)
"List of Zongor's Transpiler Language literals.") (modify-syntax-entry ?\) ")(" table)
(modify-syntax-entry ?\[ "[]" table)
(modify-syntax-entry ?\] "][" table)
;;;###autoload ;; Whitespace
(define-derived-mode ztl-mode prog-mode "ZTL" (modify-syntax-entry ?\t " " table)
"Major mode for editing Zongor's Transpiler Language (ZTL)." table))
;; File extension
(setq auto-mode-alist
(cons (cons ztl-file-extensions 'ztl-mode) auto-mode-alist))
;; Comments
(setq comment-start "!")
(setq comment-end "")
;; Font Lock
(set (make-local-variable 'font-lock-defaults)
'((ztl-font-lock-keywords)))
;; Whitespace
(set (make-local-variable 'whitespace-line-column)
80)
(whitespace-mode 1))
(defconst ztl-font-lock-keywords (defconst ztl-font-lock-keywords
`( `(
;; Comments
("^!.*" . font-lock-comment-face)
("!!.*!!" . font-lock-comment-face)
;; Strings
("\\(\"\\([^\\\\\"]\\\\?.*?\\)\"\\|'\\([^\\\\']\\\\?.*?\\)'\\)" 1 font-lock-string-face)
;; Operators
(";" . font-lock-delimiter-face)
;; Keywords ;; Keywords
,@(mapcar (lambda (kw) `(,kw . font-lock-keyword-face)) ztl-keywords) ,(rx symbol-word
(or "fn" "to" "in" "is" "as" "use" "set" "if" "else" "for" "loop"
;; Secondary keywords "while" "push" "pop" "return" "const" "type" "this" "do" "end"
,@(mapcar (lambda (kw) `(,kw . font-lock-keyword-face)) ztl-keywords-2) "then" "result" "function" "eq" "ne" "mod" "not" "and" "or"
"xor" "band" "bor" "bxor" "srl" "sll" "char" "str" "f16" "f32"
"f64" "f128")
symbol-end)
;; Literals ;; Literals
,@(mapcar (lambda (lit) `(,lit . font-lock-builtin-face)) ztl-literals) ,(rx (or "true" "false") symbol-end)
;; Function definitions ;; Function definitions
("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s*(\\)" 1 font-lock-function-name-face))) (,(rx symbol-start (one-or-more word-char) symbol-end whitespace (zero-or-more " ")) . font-lock-function-name-face))
)
;; Example usage in .emacs or init.el: (define-derived-mode ztl-mode prog-mode "ZTL"
;; (add-to-list 'auto-mode-alist '("\\.ztl$" . ztl-mode)) "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) (provide 'ztl-mode)