-
Notifications
You must be signed in to change notification settings - Fork 0
/
rivescript.el
133 lines (101 loc) · 4.6 KB
/
rivescript.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
;;; rivescript.el --- major mode for composing rivescript files
;; Copyright (C) 2018 José Alfredo Romero Latouche.
;; Author: José Alfredo Romero L. <escherdragon@gmail.com>
;; Created: 23 Mar 2018
;; Version: 1.0
;; Keywords: chatbot, rivescript, scripting, syntax
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free Software
;; Foundation, either version 3 of the License, or (at your option) any later
;; version.
;;
;; This program is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more de-
;; tails.
;; You should have received a copy of the GNU General Public License along with
;; this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This is a major mode to add syntax highlighting to rivescript code.
;; Rivescript is a very simple, line-oriented mark-up language for scripting
;; chatbots. For more details, visit: https://www.rivescript.com
;;; Installation:
;; Put this file somewhere in your load-path, and then add the following line
;; to your .emacs file:
;; (require 'rivescript)
;; Then you can manually enable the mode with M-x rivescript-mode, or you can
;; associate it with a file extension:
;; (add-to-list 'auto-mode-alist '("\\.rive\\'" . rivescript-mode))
;; Enjoy ;-)
;;; Code:
(setq rivescript-highlights '(("." . font-lock-builtin-face)))
(defface rivescript-arrow-face
'((t :inherit font-lock-comment-face :background "light yellow" :weight bold))
"Face for the RiveScript arrow (=>)"
:group 'rivescript-mode)
(defface rivescript-block-face
'((t :inherit font-lock-function-name-face :weight bold))
"Face for the names of the different topics"
:group 'rivescript-mode)
(defface rivescript-call-face
'((t :inherit font-lock-constant-face))
"Face for logic execution tags: <call>, <add>, <uppercase>, etc"
:group 'rivescript-mode)
(defface rivescript-comment-face
'((t :inherit font-lock-comment-face))
"Face for in-line comments"
:group 'rivescript-mode)
(defface rivescript-control-flow-face
'((t :inherit font-lock-warning-face))
"Face for tags that affect the flow of the script: {topic}, {weight}, etc"
:group 'rivescript-mode)
(defface rivescript-definition-face
'((t :inherit font-lock-warning-face))
"Face for definitions (!)"
:group 'rivescript-mode)
(defface rivescript-previous-face
'((t :foreground "dark orange"))
"Face for previous responses (%)"
:group 'rivescript-mode)
(defface rivescript-reply-face
'((t :inherit font-lock-type-face))
"Face for default replies (-), conditionals (*) and continuations (^)"
:group 'rivescript-mode)
(defface rivescript-space-face
'((t :inherit font-lock-type-face :weight bold))
"Face for the white-space tags: \n, \s"
:group 'rivescript-mode)
(defface rivescript-trigger-face
'((t :inherit font-lock-keyword-face))
"Face for triggers (+) and redirections (@)"
:group 'rivescript-mode)
(defface rivescript-variable-face
'((t :inherit font-lock-variable-name-face))
"Face for variable manipulation tags: <get>, <set>, <bot>, <star>, etc"
:group 'rivescript-mode)
(define-derived-mode rivescript-mode fundamental-mode "rivescript"
"Major mode for composing rivescript files"
(setq font-lock-defaults '(rivescript-highlights)))
(font-lock-add-keywords
'rivescript-mode
'(
("^[\s\t]*[+@].*" 0 'rivescript-trigger-face t)
("^[\s\t]*%.*" 0 'rivescript-previous-face t)
("^[\s\t]*[-^*].*" 0 'rivescript-reply-face t)
("^>\s\\(?:begin\\|topic\s[a-zA-Z0-9_]+.*\\|object\s[a-zA-Z0-9_]+\s[a-zA-Z0-9_]+.*\\)$" 0 'rivescript-block-face t)
("^<\s\\(?:begin\\|topic$\\|object\\)$" 0 'rivescript-block-face t)
("<call>.*?</call>" 0 'rivescript-call-face t)
("\\(?:{@[^}]*}\\|<@>\\|{@}\\)" 0 'rivescript-trigger-face t)
("<\\(?:add\\|sub\\|mult\\|div\\)\s+.*?>" 0 'rivescript-call-face t)
("<\\(?:[gs]et\\|bot\\)\s+.*?>" 0 'rivescript-variable-face t)
("<\\(?:\\(?:bot\\)?star\\|input\\|reply\\|env\\)[0-9]*?>" 0 'rivescript-variable-face t)
("<id>\\|<person>\\|<formal>\\|<sentence>\\|<uppercase>\\|<lowercase>" 0 'rivescript-call-face t)
("//.*" 0 'rivescript-comment-face t)
("{\\(?:topic\\|weight\\|random\\)=.+?}" 0 'rivescript-control-flow-face t)
("{/?random}\\|{ok}" 0 'rivescript-control-flow-face t)
("\\\\[sn]" 0 'rivescript-space-face t)
("\\_<=>\\_>" 0 'rivescript-arrow-face t)
("^\s*!.*" 0 'rivescript-definition-face t)
))
(provide 'rivescript)