add new stuff

This commit is contained in:
zongor 2025-05-03 16:36:15 -04:00
parent 6a3cdeca00
commit c46f0e07a7
1 changed files with 64 additions and 50 deletions

View File

@ -1,55 +1,69 @@
;;; ztl-mode.el --- Major mode for ZTL programs ;;; 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
'("char" "str" "integer" "int" "real"
"logical" "bool" "error" "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-constant-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 ;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ztl\\'" . ztl-mode)) (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) (provide 'ztl-mode)
;; End of ztl-mode.el