summaryrefslogtreecommitdiffstats
path: root/genvim.txr
blob: 201d0beb3d90c725e281c70772755c97dfb6c3ba (plain)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
@(next "match.c")
@(skip)
static void dir_tables_init(void)
{
@(collect)
  sethash(@nil, @{txr-sym}_s,@(skip)
@(until)
}
@(end)
@(bind tl-orig-sym
       @(append-each* ((entry (package-alist))
                       (pkg [mapcar cdr entry]))
          (append-each ((sym (package-symbols pkg)))
            (when (or (boundp sym) (fboundp sym)
                      (mboundp sym) (special-operator-p sym)
                      (constantp sym) (ffi-type-operator-p sym)
                      (ffi-type-p sym))
              (list sym)))))
@(bind tl-sym
       @(append-each ((sym tl-orig-sym))
           (let* ((pkg (symbol-package sym))
                  (pkg-name (package-name pkg))
                  (qualif (casequal pkg-name
                            ("keyword" ":")
                            ("usr" "")
                            (t `@{pkg-name}:`))))
             (if (eq sym 'contains)
               '("contain[s]") ;; Vim doesn't like the word "contains"
               (list `@qualif@(symbol-name sym)`)))))
@(do (set [txr-sym 0..0] '("end" "and" "or"
                           "catch" "finally"
                           "until" "last"
                           "if" "else" "elif"
                           "single" "first" "last" "empty" "mod" "modlast"
                           "include")))
@(set txr-sym @(sort (uniq txr-sym)))
@(set (tl-sym tl-orig-sym) @(multi-sort (list tl-sym tl-orig-sym)
                                        [list less]))
@(bind bs "\\\\")
@(bind ws "[\\t\\n ]")
@(bind hex "0-9A-Fa-f")
@(bind at "\\(@[ \\t]*\\)")
@(bind alpha "A-Za-z_")
@(bind alpha-noe "A-DF-Za-dfz_")
@(bind alnum "A-Za-z_0-9")
@(bind dig "0-9")
@(bind dig19 "1-9")
@(bind oct "0-7")
@(bind digsep `\\([@dig][,@dig]*[@dig]\\|[@dig]\\)`)
@(bind hexsep `\\([@hex][,@hex]*[@hex]\\|[@hex]\\)`)
@(bind octsep `\\([@oct][,@oct]*[@oct]\\|[@oct]\\)`)
@(bind binsep `\\([01][,01]*[01]\\|[01]\\)`)
@(bind chesc `abtnvfre@bs `)
@(bind glyph `!$%&*+\\-<=>?@{bs}_~`)
@(bind lispwords @(append-each ((sym tl-orig-sym)
                                (text tl-sym))
                    (if (or (special-operator-p sym)
                            (mboundp sym)
                            (ffi-type-operator-p sym))
                      (unless (memq sym '(and dwim inc oand opip or pset
                                              qquote quote qref rotate set
                                              shift swap sys:l1-setq
                                              sys:lisp1-setq sys:qquote
                                              sys:quasi sys:quasilist sys:setq
                                              sys:setqf new lnew
                                              meth umeth usl))
                        (list text)))))
@(bind comments #"\\;\\;\\; \\;\\; \\;")
@(bind txr-elem "txr_error,txr_atat,txr_comment,txr_contin,\
                 txr_char,txr_error,txr_char,txr_regdir,txr_variable,\
                 txr_splicevar,txr_metanum,txr_directive,txr_bracevar,\
                 txr_bracket")
@(bind txr-qelem "txr_splicevar,txr_metanum,txr_qbracevar,txr_list,\
                  txr_bracket,txr_escat,txr_stresc,txr_numesc,txr_badesc")
@(bind bvar "txr_num,txr_pnum,tl_ident,tl_splice,tl_metanum,\
             txr_metaat,txr_circ,txr_braced_ident,txr_dot,\
             txr_dotdot,txr_string,txr_list,txr_bracket,\
             txr_regex,tl_regex,txr_quasilit,\
             txr_chr,txr_nested_error")
@(bind dir "txr_keyword,txr_string,txr_list,txr_bracket,\
            txr_quasilit,txr_num,txr_pnum,\
            txr_badnum,tl_ident,tl_regex,txr_string,txr_chr,\
            txr_quote,txr_unquote,txr_splice,txr_dot,txr_dotdot,\
            txr_metaat,txr_circ,txr_ncomment,txr_nested_error")
@(bind list "tl_keyword,txr_string,tl_regex,txr_num,txr_pnum,\
             txr_badnum,tl_ident,txr_metanum,\
             txr_ign,txr_ign_json,txr_list,txr_bracket,\
             txr_quasilit,txr_chr,txr_buf,txr_quote,txr_unquote,\
             txr_splice,txr_dot,txr_dotdot,txr_metaat,txr_circ,txr_jhash,\
             txr_jarray,txr_jatom,txr_ncomment,tl_error,txr_nested_error")
@(bind jlist "txr_jarray_in,txr_jhash_in,txr_jkeyword,txr_jstring,\
              txr_jnum,txr_jpunc,txr_junqlist,txr_junqbkt,txr_junqtok,\
              txr_circ,txr_jerr")
@(bind jsonkw #"true false null")
@(bind jerr ".")
@(bind jpunc "[,: \\t\\n]")
@(bind jesc "\\\\[bfnrt\"\\\\/]")
@(bind juesc `\\\\u[@hex][@hex][@hex][@hex]`)
@(bind jnum `-\\?\\(0\\|[@dig19][@dig]*\\)\\([.][@dig]\\+\\)\\?\\([Ee][+-]\\?[@dig]\\+\\)\\?`)
@(define generate (txr-p))
@  (output @(if txr-p "txr.vim" "tl.vim"))
" VIM Syntax file for txr
" Kaz Kylheku <kaz@@kylheku.com>

" INSTALL-HOWTO:
"
" 1. Create the directory .vim/syntax in your home directory and
"    put the files txr.vim and tl.vim into this directory.
" 2. In your .vimrc, add this command to associate *.txr, *.tl and *.tlo
"    files with the txr and tl filetypes:
"    :au BufRead,BufNewFile *.txr set filetype=txr | set lisp
"    :au BufRead,BufNewFile *.tl,*.tlo set filetype=tl | set lisp
"
" If you want syntax highlighting to be on automatically (for any language)
" you need to add ":syntax on" in your .vimrc also. But you knew that already!
"
" This file is generated by the genvim.txr script in the TXR source tree.

syn case match
syn spell toplevel

setlocal iskeyword=a-z,A-Z,48-57,!,$,%,&,*,+,-,<,=,>,?,\\,_,~,/,^
@  (rep) @{tl-sym}@(mod 0 4)@\nsyn keyword tl_keyword contained @{tl-sym}@(end)
@  (if txr-p)
@    (rep) @{txr-sym}@(mod 0 4)@\nsyn keyword txr_keyword contained @{txr-sym}@(end)
syn match txr_at "@at" nextgroup=@{txr-elem}
syn match txr_error "[*]\?[\t ]*." contained
syn match txr_atat "@@" contained
syn match txr_comment "[#;].*" contained
syn match txr_contin "\\$" contained
syn match txr_char "\\." contained
syn match txr_error "\\[xo]" contained
syn match txr_char "\\x[@hex]\+;\?" contained
syn match txr_char "\\[@oct]\+;\?" contained
syn match txr_regdir "/\(\\/\|[^/]\|\\\n\)*/" contained
@  (end)
syn match txr_nested_error "[^\t ]\+" contained
syn match txr_variable "[*]\?[ \t]*[@alpha][@alnum]*" contained
syn match txr_splicevar "[ \t,*@@]*[@alpha][@alnum]*" contained
syn match txr_metanum "@at\+[0-9]\+"@(if txr-p " contained")
syn match txr_badesc "\\." contained
syn match txr_escat "\\@@" contained
syn match txr_stresc "\\[@chesc"`']" contained
syn match txr_numesc "\\x[@hex]\+;\?" contained
syn match txr_numesc "\\[@oct]\+;\?" contained
syn match txr_regesc "\\[@chesc/sSdDwW()\|.*?+~&%\[\]\-]" contained

syn match tl_error "#[^HSRTN]"@(if txr-p " contained")

syn match txr_chr "#\\x[@hex]\+"@(if txr-p " contained")
syn match txr_chr "#\\o[@oct]\+"@(if txr-p " contained")
syn match txr_chr "#\\[^ \t\n@alnum]"@(if txr-p " contained")
syn match txr_chr "#\\[@alnum]\+"@(if txr-p " contained")
syn match txr_ncomment ";.*"@(if txr-p " contained")

syn match txr_hashbang "\%^#!.*"

syn match txr_qat "@at" nextgroup=@{txr-qelem} contained
syn match txr_dot "\." contained
syn match txr_ident "[@alnum@glyph]*[@alpha@glyph^][@alnum@glyph^]*" contained
syn match txr_braced_ident "\(#\?:\)\?[[@alnum@glyph^/]\+" contained
syn match tl_ident "\(#\?:\)\?[@alnum@glyph/]\+[@alnum@glyph^/#]*"@(if txr-p " contained")
syn match txr_pnum "#[xob][+\-]\?[@alnum,]\+" contains=txr_xnum,txr_bnum,txr_onum@(if txr-p " contained")
syn match txr_xnum "#x[+\-]\?@hexsep" containedin=txr_pnum contained
syn match txr_onum "#o[+\-]\?@octsep" containedin=txr_pnum contained
syn match txr_bnum "#b[+\-]\?@binsep" containedin=txr_pnum contained
syn match txr_num "[+\-]\?@digsep"@(if txr-p " contained")
syn match txr_num "[+\-]\?@digsep\?[.]@digsep\([eE][+\-]\?[@dig]\+\)\?"@(if txr-p " contained")
syn match txr_num "[+\-]\?@digsep[.]\?\([eE][+\-]\?[@dig]\+\)"@(if txr-p " contained")
syn match txr_badnum "[+\-]\?@digsep\?[.]@digsep\([@{alpha-noe}@glyph^/#]\|[eE][^+\-@dig]\|[eE][+/-]\?$\|[eE][+\-][^0-9]\)"@(if txr-p " contained")
syn match txr_badnum "[+\-]\?@digsep[.]\?\([@{alpha-noe}@glyph^/#]\|[eE][^+\-@dig]\|[eE][+/-]\?$\|[eE][+\-][^0-9]\)"@(if txr-p " contained")
syn match tl_ident "#\?:"@(if txr-p " contained")
syn match tl_splice "[ \t,]\|,[*]"@(if txr-p " contained")

syn match txr_unquote "," contained
syn match txr_splice ",\*" contained
syn match txr_quote "'"@(if txr-p " contained")
syn match txr_quote "\^"@(if txr-p " contained")
syn match txr_dotdot "\.\." contained
syn match txr_metaat "@@"@(if txr-p " contained")

syn match txr_buf_error "[^']" contained
syn match txr_buf_interior "\([@hex][\n\t ]*[@hex]\|[\n\t ]\+\)" contained

syn region txr_bracevar contained matchgroup=Delimiter start="[*]\?{" matchgroup=Delimiter end="}" contains=@bvar
syn region txr_qbracevar contained matchgroup=Delimiter start="[*]\?{" matchgroup=Delimiter end="}" contains=@bvar
@  (if txr-p)
syn region txr_directive contained matchgroup=Delimiter start="(" matchgroup=Delimiter end=")" contains=@dir
@  (end)
syn region txr_list @(if txr-p "contained ")matchgroup=Delimiter start="\(#[HSRTN]\?\)\?(" matchgroup=Delimiter end=")" contains=@list
syn region txr_bracket @(if txr-p "contained ")matchgroup=Delimiter start="\[" matchgroup=Delimiter end="\]" contains=@list
syn region txr_string @(if txr-p "contained ")start=+#\?\*\?"+ skip=+\\\n+ end=+["\n]+ contains=txr_stresc,txr_numesc,txr_badesc
syn region txr_quasilit @(if txr-p "contained ")start=+#\?\*\?`+ skip=+\\\n+ end=+[`\n]+ contains=txr_qat,txr_stresc,txr_numesc,txr_badesc
syn region txr_regex @(if txr-p "contained ")start="/" skip=+\\\n+ end="[/\n]" contains=txr_regesc,txr_numesc,txr_badesc
syn region tl_regex @(if txr-p "contained ")start="#/" skip=+\\\n+ end="[/\n]" contains=txr_regesc,txr_numesc,txr_badesc
syn region txr_buf @(if txr-p "contained ")matchgroup=txr_buf start="#b'" end="'" contains=txr_buf_interior,txr_buf_error
syn region txr_ign @(if txr-p "contained ")matchgroup=Comment start="#;" end="[ \(\)\[\]]"me=e   contains=@list
syn region txr_ign @(if txr-p "contained ")matchgroup=Comment start="#;[ \t',^@@]*\(#[HSRTN]\?\)\?(" matchgroup=Comment end=")" contains=txr_ign_interior
syn region txr_ign @(if txr-p "contained ")matchgroup=Comment start="#;[ \t',^@@]*\(#[HSRTNJ]\?\)\?\[" matchgroup=Comment end="\]" contains=txr_ign_interior
syn region txr_ign_json @(if txr-p "contained ")matchgroup=Comment start="#;[ \t',^@@]*#J[~^]*{" matchgroup=Comment end="}" contains=txr_ign_interior
syn region txr_ign_json @(if txr-p "contained ")matchgroup=Comment start="#;[ \t',^@@]*#J[~^]*\[" matchgroup=Comment end="\]" contains=txr_ign_interior
syn region txr_ign_json @(if txr-p "contained ")matchgroup=Comment start="#;[ \t',^@@]*#J[~^]*(" matchgroup=Comment end=")" contains=txr_ign_interior
syn region txr_ign_interior contained matchgroup=Comment start="(" matchgroup=Comment end=")" contains=txr_ign_interior
syn region txr_ign_interior contained matchgroup=Comment start="\[" matchgroup=Comment end="\]" contains=txr_ign_interior
syn region txr_ign_interior contained matchgroup=Comment start="{" matchgroup=Comment end="}" contains=txr_ign_interior

syn match txr_jerr "@jerr" contained
syn match txr_jpunc "@jpunc" contained
syn match txr_jesc "@jesc" contained
syn match txr_juesc "@juesc" contained
syn match txr_jnum "@jnum" contained
syn match txr_jkeyword "@(join-with "\\|" . jsonkw)" contained

syn region txr_jatom @(if txr-p "contained ")matchgroup=Delimiter start="#J\^\?@ws*"rs=e end="@ws\|[\])}]"re=e-1 contains=@jlist
syn region txr_junqtok contained matchgroup=Delimiter start="\~" end="[ \(\)\[\]{}]"re=s contains=@list
syn region txr_junqlist contained matchgroup=Delimiter start="\~\*\?#\?(" end=")" contains=@list
syn region txr_junqbkt contained matchgroup=Delimiter start="\~\*\?\[" end="\]" contains=@list
syn region txr_jstring contained matchgroup=Delimiter start=+"+ end=+["\n]+ contains=txr_jesc,txr_juesc,txr_badesc
syn region txr_jarray @(if txr-p "contained ")matchgroup=Delimiter start="#J\^\?@ws*\[" matchgroup=Delimiter end="\]" contains=@jlist
syn region txr_jhash @(if txr-p "contained ")matchgroup=Delimiter start="#J\^\?@ws*{" matchgroup=Delimiter end="}" contains=@jlist
syn region txr_jarray_in contained matchgroup=Delimiter start="\[" end="\]" contains=@jlist
syn region txr_jhash_in contained matchgroup=Delimiter start="{" end="}" contains=@jlist

syn match txr_circ "#[0-9]\+[#=]" contained

hi def link txr_at Special
hi def link txr_atstar Special
hi def link txr_atat Special
hi def link txr_qat Special
hi def link txr_comment Comment
hi def link txr_ncomment Comment
hi def link txr_hashbang Preproc
hi def link txr_contin Preproc
hi def link txr_char String
@  (if txr-p)
hi def link txr_keyword Keyword
@  (end)
hi def link tl_keyword Type
hi def link txr_string String
hi def link txr_chr String
hi def link txr_quasilit String
hi def link txr_regex String
hi def link tl_regex String
hi def link txr_regdir String
hi def link txr_variable Identifier
hi def link txr_splicevar Identifier
hi def link txr_metanum Identifier
hi def link txr_escat Special
hi def link txr_stresc Special
hi def link txr_numesc Special
hi def link txr_regesc Special
hi def link txr_badesc Error
hi def link txr_ident Identifier
hi def link tl_ident Identifier
hi def link txr_num Number
hi def link txr_xnum Number
hi def link txr_bnum Number
hi def link txr_onum Number
hi def link txr_badnum Error
hi def link txr_pnum Error
hi def link txr_quote Special
hi def link txr_unquote Special
hi def link txr_splice Special
hi def link txr_dot Special
hi def link txr_dotdot Special
hi def link txr_metaat Special
hi def link txr_circ Special
hi def link txr_munqspl Special
hi def link tl_splice Special
hi def link txr_error Error
hi def link tl_error Error
hi def link txr_nested_error Error
hi def link txr_buf String
hi def link txr_buf_interior String
hi def link txr_buf_error Error
hi def link txr_ign_interior Comment
hi def link txr_ign Comment
hi def link txr_ign_json Comment

hi def link txr_jkeyword Type
hi def link txr_jnum Number
hi def link txr_jstring String
hi def link txr_jesc Special
hi def link txr_juesc Special
hi def link txr_jpunc Special
hi def link txr_jerr Error

let b:current_syntax = "lisp"

set lispwords=@{lispwords ","},:method,:function,:init,:postinit,:fini
set comments=@{[mapcar (ret `:@(if txr-p #\@ "")@1`) comments] ","}
@  (end)
@(end)
@(generate t)
@(generate nil)