-
Notifications
You must be signed in to change notification settings - Fork 0
/
marshall-mode.el
66 lines (57 loc) · 2.19 KB
/
marshall-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(defconst
marshall-pretty-alist
'(("Forall" . ?∀)
("Exists" . ?∃)
("fun" . ?λ)
("->" . ?→)
("=>" . ?⇒)
("/\\" . ?∧)
("\\/" . ?∨)
("<>" . ?≠)
("real" . ?ℝ)
("prop" . ?Σ)
("True" . ?⊤)
("False" . ?⊥)
("bool" . ?𝔹)
("~" . ?¬))
"Prettify rules for Marshall.")
(setq marshall-highlights
(let* (
;; define several category of keywords
(x-keywords '("let" "default" "fun" "cut" "left" "right" "in" "Forall" "Exists" "int"))
(x-types '("real" "bool" "prop" "type"))
(x-constants '("True" "False" "inf"))
(x-events '())
(x-functions '())
;; generate regex string for each category of keywords
(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-types-regexp (regexp-opt x-types 'words))
(x-constants-regexp (regexp-opt x-constants 'words))
(x-events-regexp (regexp-opt x-events 'words))
(x-functions-regexp (regexp-opt x-functions 'words)))
`(
(,x-types-regexp . font-lock-type-face)
(,x-constants-regexp . font-lock-constant-face)
(,x-events-regexp . font-lock-builtin-face)
(,x-functions-regexp . font-lock-function-name-face)
(,x-keywords-regexp . font-lock-keyword-face)
;; note: order above matters, because once colored, that part won't change.
;; in general, put longer words first
)))
(defvar marshall-mode-syntax-table nil "Syntax table for `marshall-mode'.")
(setq marshall-mode-syntax-table
(let ( (synTable (make-syntax-table)))
;; Marshall style comment: “! …”
(modify-syntax-entry ?! "<" synTable)
(modify-syntax-entry ?\n ">" synTable)
(modify-syntax-entry ?_ "w" synTable)
synTable))
(define-derived-mode marshall-mode
prog-mode "Marshall"
"Major mode for Marshall."
(setq prettify-symbols-alist marshall-pretty-alist)
(setq font-lock-defaults '(marshall-highlights))
)
(add-hook 'marshall-mode-hook #'prettify-symbols-mode) ;;
(setq auto-mode-alist
(cons '("\\.asd" . marshall-mode) auto-mode-alist))