forked from dfinity/motoko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotoko-mode.el
176 lines (171 loc) · 4.64 KB
/
motoko-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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
;; Motoko major mode for Emacs
;; initially based on Swift Mode.
(setq motoko-font-lock-keywords
(let* (
;; define several category of keywords
;; these are each taken from either Motoko's `lexer.mll' or `prelude.ml' files.
(x-types
'("Any"
"None"
"Shared"
"Null"
"Bool"
"Nat"
"Int"
"Int8"
"Int16"
"Int32"
"Int64"
"Nat8"
"Nat16"
"Nat32"
"Nat64"
"Float"
"Char"
"Text"))
(x-constants
'("null"
"true"
"false"
))
(x-keywords
'("actor"
"and"
"async"
"async*"
"assert"
"await"
"await*"
"break"
"case"
"catch"
"class"
"continue"
"do"
"debug"
"debug_show"
"else"
"flexible"
"for"
"from_candid"
"func"
"if"
"in"
"ignore"
"import"
"module"
"not"
"object"
"or"
"label"
"let"
"loop"
"private"
"public"
"query"
"return"
"shared"
"stable"
"switch"
"system"
"try"
"throw"
"to_candid"
"with"
"type"
"var"
"while"
"prim"
"invariant"
"old"
"implies"
))
;; Braces introduce blocks; it's nice to make them stand
;; out more than ordinary symbols
(x-braces
'( "{"
"}"))
(x-symbols
'( "("
")"
"["
"]"
;"{"
;"}"
";"
","
":"
"<:"
;"\\."
;"\\?"
"="
"<"
">"
;"\\+"
"-"
;"\\*"
"/"
"%"
"**"
"&"
"|"
;"\\^"
"<<"
">>"
"<<>"
"<>>"
"#"
"=="
"!="
">="
"<="
":="
"+="
"-="
"*="
"/="
"%="
"**="
"&="
"|="
"^="
"<<="
">>="
"<<>="
"<>>="
"#="
))
;; xxx These still don't work:
(x-symbols-more
'( "\\."
"\\?"
"\\+"
"\\-"
"\\*"
"\\^"
))
;; generate regex string for each category of keywords
(x-types-regexp (regexp-opt x-types 'words))
(x-constant-regexp (regexp-opt x-constants 'words))
(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-braces-regexp (regexp-opt x-braces))
(x-symbols-regexp (regexp-opt x-symbols))
(x-symbols-more-regexp (regexp-opt x-symbols-more))
)
;;
`(
(,x-types-regexp . font-lock-type-face)
(,x-constant-regexp . font-lock-constant-face)
(,x-keywords-regexp . font-lock-keyword-face)
(,x-braces-regexp . font-lock-keyword-face)
(,x-symbols-regexp . font-lock-builtin-face)
(,x-symbols-more-regexp . font-lock-builtin-face)
)))
(define-derived-mode motoko-mode
swift-mode "Motoko"
"Major mode for Motoko"
(setq font-lock-defaults '((motoko-font-lock-keywords)))
)
(add-to-list 'auto-mode-alist '("\\.mo\\'" . motoko-mode))
;; add the mode to the `features' list
(provide 'motoko-mode)