emacs.d/lisp/glauce-mode.el

69 lines
2.1 KiB
EmacsLisp

(require 'rx)
(defvar glauce-mode-hook nil)
(add-to-list 'auto-mode-alist '("\\.glc\\'" . glauce-mode))
(defconst glauce-mode-comment1-re
(rx (group "//" (0+ not-newline))))
(defconst glauce-mode-comment2-re
(rx (group "/\*" (0+ anything) "\*/")))
(defconst glauce-mode-type-re
(rx (group (in "A-Z") (0+ (in "A-Za-z0-9_")))))
(defconst glauce-mode-param-re
(rx (group (in "a-z") (0+ (in "A-Za-z0-9_")))))
(defconst glauce-mode-string-re
(rx (group "\""
(0+ (or (not (any ?\\ ?\"))
(and "\\" (in "\"\\/bfnrt"))
(and "\\u" (repeat 4 (in "0-9a-fA-F")))))
"\"")))
(defconst glauce-mode-number-re
(rx (group
(or (and (in "1-9") (0+ (in "0-9"))) "0")
(\? (and "." (1+ (in "0-9"))))
(\? (in "eE") (\? (in "+-")) (1+ (in "0-9"))))))
(defconst glauce-mode-keyword-re
(rx (group (or "true" "false" "null"
"package" "import" "assert" "with"
"subsetOf" "properSubsetOf"
"supersetOf" "properSupersetOf"
"disjointFrom" "intersects"))))
(defconst glauce-font-lock-keywords-1
(list
(list glauce-mode-string-re 1 font-lock-string-face)
(list glauce-mode-keyword-re 1 font-lock-keyword-face)
(list glauce-mode-type-re 1 font-lock-type-face)
(list glauce-mode-param-re 1 font-lock-variable-name-face)
(list glauce-mode-number-re 1 font-lock-constant-face))
"Level one font lock.")
(defvar glauce-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?/ ". 124b" table)
(modify-syntax-entry ?* ". 23b" table)
table)
"Syntax table in use in `glauce-mode' buffers.")
(defun glauce-mode ()
"Major mode for editing Glauce files"
(interactive)
(kill-all-local-variables)
(set-syntax-table glauce-mode-syntax-table)
(set (make-local-variable 'font-lock-defaults) '(glauce-font-lock-keywords-1 nil nil))
(setq major-mode 'glauce-mode)
(make-local-variable 'comment-start)
(setq comment-start "//")
(setq mode-name "Glauce")
(run-hooks 'glauce-mode-hook))
(provide 'glauce-mode)
;;; glauce-mode.el ends here