update
This commit is contained in:
		
							parent
							
								
									55e62a7975
								
							
						
					
					
						commit
						7dacca3f5d
					
				
							
								
								
									
										101
									
								
								ztl-mode.el
								
								
								
								
							
							
						
						
									
										101
									
								
								ztl-mode.el
								
								
								
								
							|  | @ -1,74 +1,51 @@ | ||||||
| ;;; 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 | (defvar ztl-constants | ||||||
|   "Hook for Zongor's Transpiler Language mode.") |   '("true" "false")) | ||||||
| 
 | 
 | ||||||
| (defconst ztl-file-extensions '(".ztl") | (defvar ztl-keywords | ||||||
|   "List of file extensions for Zongor's Transpiler Language.") |   '("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")) | ||||||
| 
 | 
 | ||||||
| (defconst ztl-keywords | (defvar ztl-keywords2 | ||||||
|   '("fn" "to" "in" "is" "as" "use" "set" "if" "else" "for" "loop" "while" |   '("char" "str" "f16" "f32" "f64" "f128")) | ||||||
|     "push" "pop" "return" "const" "type" "this" "do" "end" "then" "result" |  | ||||||
|     "function" "eq" "ne" "mod" "not" "and" "or" "xor" "band" "bor" "bxor" |  | ||||||
|     "srl" "sll") |  | ||||||
|   "List of Zongor's Transpiler Language keywords.") |  | ||||||
| 
 | 
 | ||||||
| (defconst ztl-keywords-2 | (defvar ztl-operators | ||||||
|   '("char" "str" "f16" "f32" "f64" "f128") |   '(";")) | ||||||
|   "List of Zongor's Transpiler Language secondary keywords.") |  | ||||||
| 
 | 
 | ||||||
| (defconst ztl-literals | (defvar ztl-functions | ||||||
|   '("true" "false") |   '("fn" "to" "in" "is" "as" "use" "set" "if" "else" "for" "loop" "while" "push" "pop" "return" "const" "type" "this" | ||||||
|   "List of Zongor's Transpiler Language literals.") |     "eq" "ne" "mod" "not" "and" "or" "xor" "band" "bor" "bxor" "srl" "sll")) | ||||||
| 
 | 
 | ||||||
| ;;;###autoload | (defvar ztl-font-lock-defaults | ||||||
| (define-derived-mode ztl-mode prog-mode "ZTL" |   `((("\\<\\(!!.*?!!\\)\\>" . font-lock-comment-face) ; Block comments | ||||||
|   "Major mode for editing Zongor's Transpiler Language (ZTL)." |      ("!!.*" . 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 | ||||||
|  |      )) | ||||||
| 
 | 
 | ||||||
|   ;; File extension | (define-derived-mode ztl-mode fundamental-mode "ZTL" | ||||||
|   (setq auto-mode-alist |   "Major mode for editing ZTL files." | ||||||
|         (cons (cons ztl-file-extensions 'ztl-mode) auto-mode-alist)) |   (setq font-lock-defaults ztl-font-lock-defaults) | ||||||
| 
 |  | ||||||
|   ;; Comments |  | ||||||
|   (setq comment-start "!") |   (setq comment-start "!") | ||||||
|   (setq comment-end "") |   (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)) | ||||||
| 
 | 
 | ||||||
|   ;; Font Lock | (provide 'ztl-mode)   | ||||||
|   (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 |  | ||||||
|   `( |  | ||||||
|     ;; Comments |  | ||||||
|     ("^!.*" . font-lock-comment-face) |  | ||||||
|     ("!!.*!!" . font-lock-comment-face) |  | ||||||
| 
 |  | ||||||
|     ;; Strings |  | ||||||
|     ("\\(\"\\([^\\\\\"]\\\\?.*?\\)\"\\|'\\([^\\\\']\\\\?.*?\\)'\\)" 1 font-lock-string-face) |  | ||||||
| 
 |  | ||||||
|     ;; Operators |  | ||||||
|     (";" . font-lock-delimiter-face) |  | ||||||
| 
 |  | ||||||
|     ;; Keywords |  | ||||||
|     ,@(mapcar (lambda (kw) `(,kw . font-lock-keyword-face)) ztl-keywords) |  | ||||||
| 
 |  | ||||||
|     ;; Secondary keywords |  | ||||||
|     ,@(mapcar (lambda (kw) `(,kw . font-lock-keyword-face)) ztl-keywords-2) |  | ||||||
| 
 |  | ||||||
|     ;; Literals |  | ||||||
|     ,@(mapcar (lambda (lit) `(,lit . font-lock-builtin-face)) ztl-literals) |  | ||||||
| 
 |  | ||||||
|     ;; Function definitions |  | ||||||
|     ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s*(\\)" 1 font-lock-function-name-face))) |  | ||||||
| 
 |  | ||||||
| ;; Example usage in .emacs or init.el: |  | ||||||
| ;; (add-to-list 'auto-mode-alist '("\\.ztl$" . ztl-mode)) |  | ||||||
| 
 |  | ||||||
| (provide 'ztl-mode) |  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue