-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaiken-mode.el
120 lines (100 loc) · 2.69 KB
/
aiken-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
;;; aiken-mode.el --- Major mode for Aiken -*- lexical-binding: t -*-
;; Copyright © 2023 Sebastian Nagel <[email protected]>
;; Author: Sebastian Nagel <[email protected]>
;; URL: https://github.com/aiken-lang/aiken-mode
;; Keywords: languages aiken
;; Version: 1.0.2
;; Package-Requires: ((emacs "26.1"))
;; SPDX-License-Identifier: MPL-2.0
;; This file is NOT part of GNU Emacs.
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;; Commentary:
;; Provides syntax highlighting for the Aiken smart contract language.
;;; Code:
;; Aiken syntax
(defvar aiken-keywords
'("if"
"else"
"when"
"is"
"fn"
"use"
"let"
"pub"
"type"
"opaque"
"const"
"todo"
"error"
"expect"
"test"
"trace"
"fail"
"validator"
"and"
"or"))
(defvar aiken-operators
'(
"="
"->"
".."
"|>"
">="
"<="
">"
"<"
"!="
"=="
"&&"
"||"
"!"
"+"
"-"
"/"
"*"
"%"
"?"))
(defvar aiken-font-lock-keywords
(append
`(
;; Keywords
(,(regexp-opt aiken-keywords 'symbols) . font-lock-keyword-face)
;; CamelCase is a type
("[[:upper:]][[:word:]]*" . font-lock-type-face)
;; Operators
(,(regexp-opt aiken-operators nil) . font-lock-builtin-face))
;; Identifiers after keywords
(mapcar (lambda (x)
(list (concat (car x) "[^(]\\(\\w*\\)")
1 ;; apply face ot first match group
(cdr x)))
'(("const" . font-lock-type-face)
("type" . font-lock-type-face)
("use" . font-lock-constant-face)
("fn" . font-lock-function-name-face)))))
;; Mode definitions
;;;###autoload
(define-derived-mode aiken-mode prog-mode "Aiken"
"Major mode for Aiken code."
:group 'aiken-mode
(setq-local indent-tabs-mode nil)
;; Syntax highlighting via font-lock
(setq-local font-lock-defaults '(aiken-font-lock-keywords))
;; Syntax: make _ part of words
(modify-syntax-entry ?_ "w" aiken-mode-syntax-table)
;; Comment syntax
(modify-syntax-entry ?/ ". 124b" aiken-mode-syntax-table)
(modify-syntax-entry ?\n "> b" aiken-mode-syntax-table)
(modify-syntax-entry ?\^m "> b" aiken-mode-syntax-table)
;; Comment settings
(setq-local comment-start "// ")
(setq-local comment-end "")
(setq-local comment-start-skip "//+ *")
(setq-local comment-use-syntax t)
(setq-local comment-auto-fill-only-comments t))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ak\\'" . aiken-mode))
(provide 'aiken-mode)
;;; aiken-mode.el ends here