-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclafer-mode.el
88 lines (73 loc) · 2.87 KB
/
clafer-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
;; define several class of keywords
(defvar clafer-keywords
'("abstract" "else" "in" "no" "opt" "xor" "all" "enum" "lone" "not" "or" "disj" "extends" "mux" "one" "some")
"Clafer keywords.")
(defvar clafer-types
'("integer" "string")
"Clafer types.")
(defvar clafer-operators
'("->" ":")
"Clafer Operators.")
(defvar clafer-cardinalities
'("?" "+" "*")
"Clafer Cardinalities.")
(defvar clafer-constraints-operators
'("<" ">" ">=" "<=" "<:" ":>" "=>" "+" "++" "~" "!=" "*" "#" "`" "in" "nin")
"Clafer Constraints Operators.")
;; create the regex string for each class of keywords
(defvar clafer-keywords-regexp (regexp-opt clafer-keywords 'words))
(defvar clafer-types-regexp (regexp-opt clafer-types 'words))
(defvar clafer-operators-regexp (regexp-opt clafer-operators 'words))
(defvar clafer-cardinalities-regexp (regexp-opt clafer-cardinalities 'words))
(defvar clafer-constraints-operators-regexp (regexp-opt clafer-constraints-operators 'words))
;; clear memory
(setq clafer-keywords nil)
(setq clafer-types nil)
(setq clafer-operators nil)
(setq clafer-cardinalities nil)
(setq clafer-constraints-operators nil)
;; create the list for font-lock.
;; each class of keyword is given a particular face
(setq clafer-font-lock-keywords
`(
(,clafer-types-regexp . font-lock-type-face)
(,clafer-operators-regexp . font-lock-constant-face)
(,clafer-cardinalities-regexp . font-lock-constant-face)
(,clafer-constraints-operators-regexp . font-lock-function-name-face)
(,clafer-keywords-regexp . font-lock-keyword-face)
;; note: order above matters. “clafer-keywords-regexp” goes last because
;; otherwise the keyword “state” in the function “state_entry”
;; would be highlighted.
))
;; define the mode
(define-derived-mode clafer-mode fundamental-mode
"clafer mode"
"Major mode for editing Clafer"
;; ...
;; code for syntax highlighting
(setq font-lock-defaults '((clafer-font-lock-keywords)))
;; clear memory
(setq clafer-keywords-regexp nil)
(setq clafer-types-regexp nil)
(setq clafer-operators-regexp nil)
(setq clafer-cardinalities-regexp nil)
(setq clafer-constraints-operators-regexp nil)
;; ...
)
;; the command to comment/uncomment text
;; (defun clafer-comment-dwim (arg)
;; "Comment or uncomment current line or region in a smart way.
;; For detail, see `comment-dwim'."
;; (interactive "*P")
;; (require 'newcomment)
;; (let ((deactivate-mark nil) (comment-start "--") (comment-end ""))
;; (comment-dwim arg)))
;; define the major mode.
;; (define-derived-mode clafer-mode fundamental-mode
;; "clafer-mode is a major mode for editing language clafer."
;; modify the keymap
;; (define-key clafer-mode-map [remap comment-dwim] 'clafer-comment-dwim)
;; perl style comment: “# ...”
;; (modify-syntax-entry ?- "< b" clafer-mode-syntax-table)
;; (modify-syntax-entry ?\n "> b" clafer-mode-syntax-table)
;; )