aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-10-21 17:30:31 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2015-10-21 18:41:51 +0300
commite217607915ae4d3a486a4b4e0fafeb34b8247d0f (patch)
tree5f943b0fbbfd29773d1fb1235e7817c3ae665f19
downloadvcl-mode-e217607915ae4d3a486a4b4e0fafeb34b8247d0f.tar.gz
vcl-mode-e217607915ae4d3a486a4b4e0fafeb34b8247d0f.tar.bz2
Initial commit
-rw-r--r--vcl-mode.el376
1 files changed, 376 insertions, 0 deletions
diff --git a/vcl-mode.el b/vcl-mode.el
new file mode 100644
index 0000000..c6ea5e1
--- /dev/null
+++ b/vcl-mode.el
@@ -0,0 +1,376 @@
1;;; vcl-mode.el --- major mode for editing VCL sources
2
3;; Authors: 2015 Sergey Poznyakoff
4;; Version: 0.1
5;; Keywords: Varnish, VCL
6
7;; Copyright (C) 2015 Sergey Poznyakoff
8
9;; This program is free software; you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation; either version 3 of the License, or
12;; (at your option) any later version.
13
14;; This program is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22;; Installation:
23;; You may wish to use precompiled version of the mode. To create it
24;; run:
25;; emacs -batch -f batch-byte-compile vcl-mode.el
26;; Install the file vcl-mode.elc (and, optionally, vcl-mode.el) to
27;; any directory in your Emacs load-path.
28
29;; Customization:
30;; To your .emacs or site-start.el add:
31;; (autoload 'vcl-mode "vcl-mode")
32
33(require 'cc-langs)
34
35(defvar vcl-mode-map ()
36 "Keymap used in vcl-mode buffers.")
37(if vcl-mode-map
38 nil
39 (setq vcl-mode-map (c-make-inherited-keymap)))
40
41(defvar vcl-mode-syntax-table
42 (let ((st (make-syntax-table)))
43 (modify-syntax-entry ?\n "> b" st)
44 (modify-syntax-entry ?\r "> " st)
45 (modify-syntax-entry ?\f "> " st)
46; (modify-syntax-entry ?\# "<" st)
47 (modify-syntax-entry ?/ ". 124b" st)
48 (modify-syntax-entry ?* ". 23" st)
49 (modify-syntax-entry ?+ "." st)
50 (modify-syntax-entry ?- "." st)
51 (modify-syntax-entry ?~ "." st)
52 (modify-syntax-entry ?= "." st)
53 (modify-syntax-entry ?% "." st)
54 (modify-syntax-entry ?< "." st)
55 (modify-syntax-entry ?> "." st)
56 (modify-syntax-entry ?& "." st)
57 (modify-syntax-entry ?| "." st)
58 (modify-syntax-entry ?_ "_" st)
59 (modify-syntax-entry ?\' "." st)
60 (modify-syntax-entry ?\" "." st)
61 (modify-syntax-entry ?{ "." st)
62 (modify-syntax-entry ?} "." st)
63 st)
64 "Syntax table in use in VCL Mode buffers.")
65
66(defvar vcl-mode-abbrev-table nil
67 "Abbreviation table used in vcl-mode buffers.")
68(c-define-abbrev-table 'vcl-mode-abbrev-table
69 '(("else" "else" c-electric-continued-statement 0)
70 ("while" "while" c-electric-continued-statement 0)))
71
72;; Font locking
73(defconst vcl-font-lock-keywords-1
74 (eval-when-compile
75 (list
76 ;; Version declaration
77 '("^[ \t]*\\(vcl\\)\\>[ \t]*\\([[:digit:]]+\\.[[:digit:]]+\\)"
78 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
79 ;; Built-ins
80 (cons
81 (concat "\\<"
82 (regexp-opt
83 '("vcl_init"
84 "vcl_recv"
85 "vcl_pipe"
86 "vcl_pass"
87 "vcl_hash"
88 "vcl_hit"
89 "vcl_miss"
90 "vcl_fetch"
91 "vcl_deliver"
92 "vcl_error"
93 "vcl_fini"
94 "vcl_synth"
95 "vcl_backend_fetch"
96 "vcl_backend_response"
97 "vcl_backend_error") t)
98 "\\>")
99 'font-lock-builtin-face)
100 ;; Keywords
101 (cons
102 (concat "\\<"
103 (regexp-opt
104 '("sub"
105 "import"
106 "include"
107 "backend"))
108 "\\>")
109 'font-lock-keyword-face)
110 ))
111 "Subdued level highlighting for VCL buffers.")
112
113(defconst vcl-font-lock-keywords-2
114 (append vcl-font-lock-keywords-1
115 (eval-when-compile
116 (list
117 ;; Keywords
118 (cons
119 (concat "\\<"
120 (regexp-opt
121 '("acl"
122 "if"
123 "else"
124 "return"
125 "call"
126 "set"
127 "remove"
128 "unset"
129 "director"
130 "probe") t)
131 "\\>")
132 'font-lock-keyword-face)
133 ;; Return values
134 (cons
135 (concat "\\<"
136 (regexp-opt
137 '("error"
138 "fetch"
139 "hash"
140 "hit_for_pass"
141 "lookup"
142 "ok"
143 "pass"
144 "pipe"
145 "deliver"
146 "restart"
147 "true"
148 "false") t)
149 "\\>")
150 'font-lock-constant-face)
151 ;; Functions
152 (cons
153 (concat "\\<"
154 (regexp-opt
155 '("ban"
156 "call"
157 "hash_data"
158 "new"
159 "synth"
160 "synthetic"
161 "regsub"
162 "regsuball") t)
163 "\\>")
164 'font-lock-function-name-face)
165
166 ;; Objects and variables
167 ;; See https://www.varnish-cache.org/docs/4.0/reference/vcl.html#variables
168 (list (concat "\\<"
169 (regexp-opt
170 '("req"
171 "resp"
172 "bereq"
173 "beresp"
174 "obj") t)
175 "\\.\\(http\\)\\(\\.\\([a-zA-Z_-][a-zA-Z_0-9-]*\\)\\)?")
176 '(1 font-lock-builtin-face)
177 '(2 font-lock-builtin-face)
178 '(4 font-lock-string-face nil t))
179 (list (concat "\\<\\(bereq\\)\\."
180 (regexp-opt
181 '("backend"
182 "between_bytes_timeout"
183 "connect_timeout"
184 "first_byte_timeout"
185 "method"
186 "proto"
187 "retries"
188 "uncacheable"
189 "url"
190 "xid") t))
191 '(1 font-lock-builtin-face)
192 '(2 font-lock-builtin-face))
193 (list (concat "\\<\\(beresp\\)\\.\\(backend\\)\\."
194 (regexp-opt
195 '("name"
196 "ip") t))
197 '(1 font-lock-builtin-face)
198 '(2 font-lock-builtin-face)
199 '(3 font-lock-builtin-face))
200 (list (concat "\\<\\(beresp\\)\\."
201 (regexp-opt
202 '("do_esi"
203 "do_gunzip"
204 "do_gzip"
205 "do_stream"
206 "grace"
207 "keep"
208 "proto"
209 "reason"
210 "status"
211 "storage_hint"
212 "ttl"
213 "uncacheable") t))
214 '(1 font-lock-builtin-face)
215 '(2 font-lock-builtin-face))
216 (list (concat "\\<\\(client\\)\\."
217 (regexp-opt
218 '("identity"
219 "ip") t))
220 '(1 font-lock-builtin-face)
221 '(2 font-lock-builtin-face))
222 (list (concat "\\<\\(obj\\)\\."
223 (regexp-opt
224 '("grace"
225 "hits"
226 "keep"
227 "proto"
228 "reason"
229 "status"
230 "ttl"
231 "uncacheable") t))
232 '(1 font-lock-builtin-face)
233 '(2 font-lock-builtin-face))
234 (list (concat "\\<\\(req\\)\\."
235 (regexp-opt
236 '("backend_hint"
237 "can_gzip"
238 "esi"
239 "esi_level"
240 "hash_always_miss"
241 "hash_ignore_busy"