Created
April 27, 2026 09:35
-
-
Save isoraqathedh/0963307aac2fcb24825763994419a248 to your computer and use it in GitHub Desktop.
Numbat mode (no tree-sitter)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;;; numbat-mode.el --- Major mode (non-tree-sitter) for modifying numbat source code | |
| ;;; Currently this just provides basic syntax highlihgting. | |
| ;;; Hooks are provided here to allow users to add extra functionality later, | |
| ;;; and those may be rolled in at a later time. | |
| ;;; Code: | |
| ;; allow users to have hooks with this mode | |
| (defvar numbat-mode-hook nil "Hook run after `numbat-mode'.") | |
| (defvar numbat-command "numbat" "Command to execute numbat") | |
| (defvar numbat-mode-map | |
| (let ((map (make-sparse-keymap))) | |
| ;; ... | |
| map) | |
| "Keymap for `unison-mode'.") | |
| (defvar numbat-keywords-regexp | |
| (regexp-opt '("dimension" "unit" "if" "then" "else" "struct" "use" "to" "per" "let" "where" "and") 'words)) | |
| (defvar numbat-dimensions-regexp "\\(?:[:=+-*/]\\|dimension\\)[[:blank:]]*\\([A-Z][[:word:]]*\\)") | |
| (defvar numbat-dimensions-regexp-alternate "\\(?:->\\|[+-*/]\\)[[:blank:]]*\\([A-Z][[:word:]]*\\)[[:blank:]]*[=+-*/^]") | |
| (defvar numbat-vardef-regexp "\\(?:let\\|where\\|and\\)[[:blank:]]+\\([[:word:]]+\\)[[:blank:]]*[:=]") | |
| (defvar numbat-function-regexp "\\(fn\\)[[:blank:]]+\\([[:word:]]+\\)(.*)") | |
| (defvar numbat-builtins-regexp | |
| (regexp-opt '("assert" "print" "assert_eq" "type" "NaN" "inf") 'words)) | |
| (defvar numbat-annotation-regexp "@[[:word:]]+") | |
| (defvar numbat-font-lock-keywords | |
| `(("^[ \t]*\\(#.*\\)$" . font-lock-comment-face) | |
| (,numbat-function-regexp (1 font-lock-keyword-face) (2 font-lock-function-name-face)) | |
| (,numbat-builtins-regexp . font-lock-builtin-face) | |
| (,numbat-keywords-regexp . font-lock-keyword-face) | |
| (,numbat-vardef-regexp (1 font-lock-variable-name-face)) | |
| (,numbat-dimensions-regexp (1 font-lock-type-face)) | |
| (,numbat-dimensions-regexp-alternate (1 font-lock-type-face)) | |
| (,numbat-annotation-regexp . font-lock-type-face))) | |
| (defvar numbat-mode-syntax-table | |
| (let ((st (make-syntax-table))) | |
| (modify-syntax-entry ?_ "w" st) ; word constituent | |
| st) | |
| "Syntax table for numbat-mode") | |
| ;;;###autoload | |
| (define-derived-mode numbat-mode prog-mode "Numbat" | |
| "Major mode for font-locking numbat files" | |
| :syntax-table numbat-mode-syntax-table | |
| (set (make-local-variable 'font-lock-defaults) ; font lock | |
| '(numbat-font-lock-keywords)) | |
| ;; comment syntax for `newcomment.el' | |
| (set (make-local-variable 'comment-start) "# ") | |
| (set (make-local-variable 'comment-end) "") | |
| (set (make-local-variable 'comment-start-skip) "#+\\s-*") | |
| (run-hooks 'numbat-mode-hook)) ; run user hooks last. | |
| (provide 'numbat-mode) | |
| ;;; numbat-mode.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment