rename
This commit is contained in:
		
							parent
							
								
									4a27058423
								
							
						
					
					
						commit
						0ed18154f2
					
				| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
#+OPTIONS: toc:nil
 | 
					#+OPTIONS: toc:nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* ztl-mode
 | 
					* zre-mode
 | 
				
			||||||
:PROPERTIES:
 | 
					:PROPERTIES:
 | 
				
			||||||
:CUSTOM_ID: ztl-mode
 | 
					:CUSTOM_ID: zre-mode
 | 
				
			||||||
:END:
 | 
					:END:
 | 
				
			||||||
ZTL mode for Emacs
 | 
					ZRE mode for Emacs
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,85 @@
 | 
				
			||||||
 | 
					;;; zre-mode.el --- Major mode for editing Zre code -*- lexical-binding: t; -*-
 | 
				
			||||||
 | 
					;;
 | 
				
			||||||
 | 
					;; Licensed under the GPLv3 License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defvar zre-keywords
 | 
				
			||||||
 | 
					  '("fn" "to" "in" "is" "as" "use" "if" "else"
 | 
				
			||||||
 | 
					    "for" "try" "catch" "while" "do" "exit"
 | 
				
			||||||
 | 
					    "return" "const" "type" "this" "yield"
 | 
				
			||||||
 | 
					    "break" "mod" "not" "and" "or" "print" "let")
 | 
				
			||||||
 | 
					  "Keywords in Zre.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defvar zre-types
 | 
				
			||||||
 | 
					  '("byte" "str" "real" "bool" 
 | 
				
			||||||
 | 
					    "int" "nat" "f32" "f64" 
 | 
				
			||||||
 | 
					    "u8" "u16" "u32" "u64" 
 | 
				
			||||||
 | 
					    "i8" "i16" "i32" "i64")
 | 
				
			||||||
 | 
					  "Types in Zre.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defvar zre-constants
 | 
				
			||||||
 | 
					  '("true" "false" "nil")
 | 
				
			||||||
 | 
					  "Constants in Zre.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defvar zre-font-lock-keywords
 | 
				
			||||||
 | 
					  `(
 | 
				
			||||||
 | 
					    ;; Keywords
 | 
				
			||||||
 | 
					    (,(regexp-opt zre-keywords 'words) . font-lock-keyword-face)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Types
 | 
				
			||||||
 | 
					    (,(regexp-opt zre-types 'words) . font-lock-type-face)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Constants
 | 
				
			||||||
 | 
					    (,(regexp-opt zre-constants 'words) . font-lock-constant-face)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Structs: CamelCase identifiers
 | 
				
			||||||
 | 
					    ("\\b[A-Z][a-zA-Z0-9_]*\\b" . font-lock-type-face)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Function definitions: "fn name(...)"
 | 
				
			||||||
 | 
					    ("\\_<fn\\>\\s-+\\(\\w+\\)(" (1 font-lock-function-name-face))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Function calls: "name(...)"
 | 
				
			||||||
 | 
					    ("\\_<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s-*(" (1 font-lock-function-name-face))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Floating point numbers
 | 
				
			||||||
 | 
					    ("\\b-?[0-9]+\\.[0-9]+\\b" . font-lock-constant-face)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Integers
 | 
				
			||||||
 | 
					    ("\\b-?[0-9]+\\b" . font-lock-constant-face)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Strings with double quotes
 | 
				
			||||||
 | 
					    ("\"[^\"\n]*\"" . font-lock-string-face)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ;; Strings with backticks
 | 
				
			||||||
 | 
					    ("`[^`]*`" . font-lock-string-face))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "Font lock keywords for Zre mode.")
 | 
				
			||||||
 | 
					(defvar zre-mode-syntax-table
 | 
				
			||||||
 | 
					  (let ((st (make-syntax-table)))
 | 
				
			||||||
 | 
					    ;; C++-style comments
 | 
				
			||||||
 | 
					    (modify-syntax-entry ?/ ". 14b" st)
 | 
				
			||||||
 | 
					    ;; C-style comments
 | 
				
			||||||
 | 
					    (modify-syntax-entry ?* ". 23" st)
 | 
				
			||||||
 | 
					    ;; Strings
 | 
				
			||||||
 | 
					    (modify-syntax-entry ?\" "\"" st)
 | 
				
			||||||
 | 
					    (modify-syntax-entry ?` "\"" st)
 | 
				
			||||||
 | 
					    st)
 | 
				
			||||||
 | 
					  "Syntax table for Zre mode.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define-derived-mode zre-mode prog-mode "Zre"
 | 
				
			||||||
 | 
					  "Major mode for editing Zre code."
 | 
				
			||||||
 | 
					  :syntax-table zre-mode-syntax-table
 | 
				
			||||||
 | 
					  (setq-local font-lock-defaults '(zre-font-lock-keywords))
 | 
				
			||||||
 | 
					  (setq-local comment-start "// ")
 | 
				
			||||||
 | 
					  (setq-local comment-end "")
 | 
				
			||||||
 | 
					  (setq-local parse-sexp-ignore-comments t)
 | 
				
			||||||
 | 
					  (setq-local indent-line-function 'c-indent-line)
 | 
				
			||||||
 | 
					  (setq-local syntax-propertize-function
 | 
				
			||||||
 | 
					              (syntax-propertize-rules
 | 
				
			||||||
 | 
					               ;; Line comments starting with //
 | 
				
			||||||
 | 
					               ("\\(//\\)\\(?:[^\n]*\\)" (1 "<")))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;;;###autoload
 | 
				
			||||||
 | 
					(add-to-list 'auto-mode-alist '("\\.zre\\'" . zre-mode))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(provide 'zre-mode)
 | 
				
			||||||
 | 
					;;; zre-mode.el ends here
 | 
				
			||||||
							
								
								
									
										118
									
								
								ztl-mode.el
								
								
								
								
							
							
						
						
									
										118
									
								
								ztl-mode.el
								
								
								
								
							| 
						 | 
					@ -1,118 +0,0 @@
 | 
				
			||||||
;;; ztl-mode.el --- Major mode for editing Ztl code -*- lexical-binding: t; -*-
 | 
					 | 
				
			||||||
;;
 | 
					 | 
				
			||||||
;; Licensed under the GPLv3 License.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defvar ztl-keywords
 | 
					 | 
				
			||||||
  '("fn" "to" "in" "is" "as" "use" "set" "if" "else"
 | 
					 | 
				
			||||||
    "for" "loop" "concurrent" "while" "do" "exits" "exit"
 | 
					 | 
				
			||||||
    "return" "const" "type" "this" "panic" "yield"
 | 
					 | 
				
			||||||
    "break" "mod" "not" "and" "or" "print" "let")
 | 
					 | 
				
			||||||
  "Keywords in Ztl.")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defvar ztl-types
 | 
					 | 
				
			||||||
  '("byte" "str" "real" "bool" "err" "any")
 | 
					 | 
				
			||||||
  "Types in Ztl.")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defvar ztl-constants
 | 
					 | 
				
			||||||
  '("true" "false" "nil")
 | 
					 | 
				
			||||||
  "Constants in Ztl.")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defvar ztl-font-lock-keywords
 | 
					 | 
				
			||||||
  `(
 | 
					 | 
				
			||||||
    ;; Keywords
 | 
					 | 
				
			||||||
    (,(regexp-opt ztl-keywords 'words) . font-lock-keyword-face)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Types
 | 
					 | 
				
			||||||
    (,(regexp-opt ztl-types 'words) . font-lock-type-face)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Constants
 | 
					 | 
				
			||||||
    (,(regexp-opt ztl-constants 'words) . font-lock-constant-face)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Structs: CamelCase identifiers
 | 
					 | 
				
			||||||
    ("\\b[A-Z][a-zA-Z0-9_]*\\b" . font-lock-type-face)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Function definitions: "fn name(...)"
 | 
					 | 
				
			||||||
    ("\\_<fn\\>\\s-+\\(\\w+\\)(" (1 font-lock-function-name-face))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Function calls: "name(...)"
 | 
					 | 
				
			||||||
    ("\\_<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s-*(" (1 font-lock-function-name-face))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Floating point numbers
 | 
					 | 
				
			||||||
    ("\\b-?[0-9]+\\.[0-9]+\\b" . font-lock-constant-face)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Integers
 | 
					 | 
				
			||||||
    ("\\b-?[0-9]+\\b" . font-lock-constant-face)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Strings with double quotes
 | 
					 | 
				
			||||||
    ("\"[^\"\n]*\"" . font-lock-string-face)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ;; Strings with backticks
 | 
					 | 
				
			||||||
    ("`[^`]*`" . font-lock-string-face))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  "Font lock keywords for Ztl mode.")
 | 
					 | 
				
			||||||
(defvar ztl-mode-syntax-table
 | 
					 | 
				
			||||||
  (let ((st (make-syntax-table)))
 | 
					 | 
				
			||||||
    ;; C++-style comments
 | 
					 | 
				
			||||||
    (modify-syntax-entry ?/ ". 14b" st)
 | 
					 | 
				
			||||||
    ;; C-style comments
 | 
					 | 
				
			||||||
    (modify-syntax-entry ?* ". 23" st)
 | 
					 | 
				
			||||||
    ;; Strings
 | 
					 | 
				
			||||||
    (modify-syntax-entry ?\" "\"" st)
 | 
					 | 
				
			||||||
    (modify-syntax-entry ?` "\"" st)
 | 
					 | 
				
			||||||
    st)
 | 
					 | 
				
			||||||
  "Syntax table for Ztl mode.")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defun ztl-indent-line ()
 | 
					 | 
				
			||||||
  "Indent current line as Ztl code."
 | 
					 | 
				
			||||||
  (interactive)
 | 
					 | 
				
			||||||
  (let ((indent (calculate-ztl-indent)))
 | 
					 | 
				
			||||||
    (if (null indent)
 | 
					 | 
				
			||||||
        (setq indent 0))
 | 
					 | 
				
			||||||
    (indent-line-to indent)))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(defun calculate-ztl-indent ()
 | 
					 | 
				
			||||||
  "Calculate the proper indentation for the current line."
 | 
					 | 
				
			||||||
  (save-excursion
 | 
					 | 
				
			||||||
    (beginning-of-line)
 | 
					 | 
				
			||||||
    (let ((pos (point-marker))
 | 
					 | 
				
			||||||
          (indent 0))
 | 
					 | 
				
			||||||
      (skip-chars-forward " \t")
 | 
					 | 
				
			||||||
      (if (looking-at "\\s)\\|\\s(")
 | 
					 | 
				
			||||||
          (setq indent 0)
 | 
					 | 
				
			||||||
        (condition-case nil
 | 
					 | 
				
			||||||
            (progn
 | 
					 | 
				
			||||||
              (backward-up-list 1)
 | 
					 | 
				
			||||||
              (while (and (> (point) (point-min))
 | 
					 | 
				
			||||||
                          (progn
 | 
					 | 
				
			||||||
                            (forward-line -1)
 | 
					 | 
				
			||||||
                            (skip-chars-forward " \t")
 | 
					 | 
				
			||||||
                            (or (looking-at "\\s<") ; comment
 | 
					 | 
				
			||||||
                                (looking-at "\\s\"") ; string
 | 
					 | 
				
			||||||
                                (looking-at "\\s$")))) ; skip to previous line
 | 
					 | 
				
			||||||
                nil)
 | 
					 | 
				
			||||||
              (setq indent (current-indentation))
 | 
					 | 
				
			||||||
              (forward-line 0)
 | 
					 | 
				
			||||||
              (skip-chars-forward " \t")
 | 
					 | 
				
			||||||
              (if (looking-at "\\s(") ; opening brace
 | 
					 | 
				
			||||||
                  (setq indent (+ indent tab-width))))
 | 
					 | 
				
			||||||
          (error nil)))
 | 
					 | 
				
			||||||
      indent)))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(define-derived-mode ztl-mode prog-mode "Ztl"
 | 
					 | 
				
			||||||
  "Major mode for editing Ztl code."
 | 
					 | 
				
			||||||
  :syntax-table ztl-mode-syntax-table
 | 
					 | 
				
			||||||
  (setq-local font-lock-defaults '(ztl-font-lock-keywords))
 | 
					 | 
				
			||||||
  (setq-local comment-start "// ")
 | 
					 | 
				
			||||||
  (setq-local comment-end "")
 | 
					 | 
				
			||||||
  (setq-local parse-sexp-ignore-comments t)
 | 
					 | 
				
			||||||
  (setq-local indent-line-function 'ztl-indent-line)
 | 
					 | 
				
			||||||
  (setq-local syntax-propertize-function
 | 
					 | 
				
			||||||
              (syntax-propertize-rules
 | 
					 | 
				
			||||||
               ;; Line comments starting with //
 | 
					 | 
				
			||||||
               ("\\(//\\)\\(?:[^\n]*\\)" (1 "<")))))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
;;;###autoload
 | 
					 | 
				
			||||||
(add-to-list 'auto-mode-alist '("\\.ztl\\'" . ztl-mode))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(provide 'ztl-mode)
 | 
					 | 
				
			||||||
;;; ztl-mode.el ends here
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue