96 lines
2.9 KiB
EmacsLisp
96 lines
2.9 KiB
EmacsLisp
;;; zre-mode.el --- Major mode for editing Zre code -*- lexical-binding: t; -*-
|
|
;; Copyright (C) 2025 zongor
|
|
;;
|
|
;; This program is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
;;
|
|
;; This program is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
;;
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
;;;
|
|
|
|
(defvar zre-keywords
|
|
'("fn" "to" "in" "is" "as" "use" "if" "else" "default"
|
|
"for" "try" "catch" "while" "do" "exit" "switch"
|
|
"return" "const" "type" "this" "yield" "case"
|
|
"assert" "break" "mod" "not" "and" "or" "print" "let"
|
|
"band" "bor" "bxor" "srl" "sll")
|
|
"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)))
|
|
;; '/' starts a comment
|
|
(modify-syntax-entry ?! "<" st)
|
|
(modify-syntax-entry ?\n ">" 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))
|
|
|
|
;;;###autoload
|
|
(add-to-list 'auto-mode-alist '("\\.zre\\'" . zre-mode))
|
|
|
|
(provide 'zre-mode)
|
|
;;; zre-mode.el ends here
|