-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentient-lang.el
74 lines (59 loc) · 3.04 KB
/
sentient-lang.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
67
68
69
70
71
72
73
74
;; Emacs font-lock mode for Sentient language
;; Roberto DeFeo (rdefeo@gmail.com) 2020
;; https://github.com/rdefeo/emacs-sentient
;; Provide a hook to allow custom code when mode is invoked
(defvar sentient-lang-mode-hook nil)
;; Bind the mode to .snt files
(add-to-list 'auto-mode-alist '("\\.snt" . sentient-lang-mode))
;; Define basic keywords, constants, and types
(defconst sentient-lang-mode-font-lock-keywords-1
(list
'("\\(expose\\|invariant\\|function[\\?!]?\\|return\\|buildArray\\)" . font-lock-function-name-face)
'("\\<function\\>" "\\(.*\\)(" nil nil (1 font-lock-variable-name-face))
'(";" . font-lock-builtin-face)
'("\\<\\(true\\|false\\)\\>" . font-lock-constant-face)
'("\\<int[0-9]*\\|\\<array[0-9]*" . font-lock-type-face)
'("[^a-z]\\([0-9]+\\)" . (1 font-lock-constant-face))
)
"Minimal highlighting expressions for Sentient Lang mode")
;; Define operators and built-in methods on integers and arrays
(defconst sentient-lang-mode-font-lock-keywords-2
(append sentient-lang-mode-font-lock-keywords-1
(list
;; operators
'("\\_<\\(==?\\|\\+\\|\\-\\|/\\|\\?\\|:\\|\\*\\|||?\\|&&?\\|\\!\\)\\_>" . font-lock-builtin-face)
'("\\.?\\(if\\)(" . (1 font-lock-keyword-face))
;; method used by all types
'("\\.self" . font-lock-keyword-face)
;; integer type methods
'("\\.\\(abs\\|between\\?\\|cube\\|divmod\\)" . (1 font-lock-keyword-face))
'("\\.\\(downto\\|even\\?\\|negative\\?\\|next\\)" . (1 font-lock-keyword-face))
'("\\.\\(odd\\?\\|positive\\?\\|pred\\|prev\\)" . (1 font-lock-keyword-face))
'("\\.\\(square\\|succ\\?\\|times\\|upto\\|zero\\?\\)" . (1 font-lock-keyword-face))
;; array type methods
'("\\.\\(fetch\\|all\\?\\|any\\?\\|bounds\\?\\)" . (1 font-lock-keyword-face))
'("\\.\\(collect\\|count\\|countBy\\|eachCombination\\|eachCons\\)" . (1 font-lock-keyword-face))
'("\\.\\(eachSlice\\|each\\|first\\|get\\)" . (1 font-lock-keyword-face))
'("\\.\\(include\\?\\|last\\|length\\|map\\|none\\?\\)" . (1 font-lock-keyword-face))
'("\\.\\(one\\?\\|push\\|reduce\\|reject\\|reverse\\|select\\)" . (1 font-lock-keyword-face))
'("\\.\\(size\\|sum\\|transpose\\|uniqBy\\?\\|uniq\\?\\)" . (1 font-lock-keyword-face))
))
"More highlighted expressions for Sentient Lang mode")
(defvar sentient-lang-mode-font-lock-keywords sentient-lang-mode-font-lock-keywords-2 "Default highlighing expressions for Senitent Lang mode")
;; Define comment style
(defvar sentient-lang-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?# "<" st)
(modify-syntax-entry ?\n ">" st)
st)
"Syntax table for sentient-lang-mode")
;; Defind the mode
(define-derived-mode sentient-lang-mode prog-mode "Sentient"
"Major mode for editing Sentient Language files"
(kill-all-local-variables)
(set-syntax-table sentient-lang-mode-syntax-table)
(setq-local font-lock-defaults '(sentient-lang-mode-font-lock-keywords))
(setq major-mode 'sentient-lang-mode)
(setq mode-name "Sentient")
(run-hooks 'sentient-lang-mode-hook))
(provide 'sentient-lang-mode)