7
|
1 " Vim syntax file
|
|
2 " Language: Scheme (R5RS)
|
1619
|
3 " Last Change: 2007 Jun 16
|
36
|
4 " Maintainer: Sergey Khorev <sergey.khorev@gmail.com>
|
17
|
5 " Original author: Dirk van Deun <dirk@igwe.vub.ac.be>
|
7
|
6
|
|
7 " This script incorrectly recognizes some junk input as numerals:
|
|
8 " parsing the complete system of Scheme numerals using the pattern
|
|
9 " language is practically impossible: I did a lax approximation.
|
17
|
10
|
|
11 " MzScheme extensions can be activated with setting is_mzscheme variable
|
7
|
12
|
|
13 " Suggestions and bug reports are solicited by the author.
|
|
14
|
|
15 " Initializing:
|
|
16
|
|
17 " For version 5.x: Clear all syntax items
|
|
18 " For version 6.x: Quit when a syntax file was already loaded
|
|
19 if version < 600
|
|
20 syntax clear
|
|
21 elseif exists("b:current_syntax")
|
|
22 finish
|
|
23 endif
|
|
24
|
|
25 syn case ignore
|
|
26
|
|
27 " Fascist highlighting: everything that doesn't fit the rules is an error...
|
|
28
|
17
|
29 syn match schemeError oneline ![^ \t()\[\]";]*!
|
7
|
30 syn match schemeError oneline ")"
|
|
31
|
|
32 " Quoted and backquoted stuff
|
|
33
|
17
|
34 syn region schemeQuoted matchgroup=Delimiter start="['`]" end=![ \t()\[\]";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
7
|
35
|
|
36 syn region schemeQuoted matchgroup=Delimiter start="['`](" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
37 syn region schemeQuoted matchgroup=Delimiter start="['`]#(" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
38
|
|
39 syn region schemeStrucRestricted matchgroup=Delimiter start="(" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
40 syn region schemeStrucRestricted matchgroup=Delimiter start="#(" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
41
|
17
|
42 " Popular Scheme extension:
|
|
43 " using [] as well as ()
|
|
44 syn region schemeStrucRestricted matchgroup=Delimiter start="\[" matchgroup=Delimiter end="\]" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
45 syn region schemeStrucRestricted matchgroup=Delimiter start="#\[" matchgroup=Delimiter end="\]" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
7
|
46
|
17
|
47 syn region schemeUnquote matchgroup=Delimiter start="," end=![ \t\[\]()";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
48 syn region schemeUnquote matchgroup=Delimiter start=",@" end=![ \t\[\]()";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
49
|
|
50 syn region schemeUnquote matchgroup=Delimiter start=",(" end=")" contains=ALL
|
|
51 syn region schemeUnquote matchgroup=Delimiter start=",@(" end=")" contains=ALL
|
7
|
52
|
|
53 syn region schemeUnquote matchgroup=Delimiter start=",#(" end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
54 syn region schemeUnquote matchgroup=Delimiter start=",@#(" end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
55
|
17
|
56 syn region schemeUnquote matchgroup=Delimiter start=",\[" end="\]" contains=ALL
|
|
57 syn region schemeUnquote matchgroup=Delimiter start=",@\[" end="\]" contains=ALL
|
|
58
|
|
59 syn region schemeUnquote matchgroup=Delimiter start=",#\[" end="\]" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
60 syn region schemeUnquote matchgroup=Delimiter start=",@#\[" end="\]" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
|
|
61
|
7
|
62 " R5RS Scheme Functions and Syntax:
|
|
63
|
|
64 if version < 600
|
|
65 set iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_
|
|
66 else
|
|
67 setlocal iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_
|
|
68 endif
|
|
69
|
|
70 syn keyword schemeSyntax lambda and or if cond case define let let* letrec
|
|
71 syn keyword schemeSyntax begin do delay set! else =>
|
|
72 syn keyword schemeSyntax quote quasiquote unquote unquote-splicing
|
|
73 syn keyword schemeSyntax define-syntax let-syntax letrec-syntax syntax-rules
|
|
74
|
|
75 syn keyword schemeFunc not boolean? eq? eqv? equal? pair? cons car cdr set-car!
|
|
76 syn keyword schemeFunc set-cdr! caar cadr cdar cddr caaar caadr cadar caddr
|
|
77 syn keyword schemeFunc cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr
|
|
78 syn keyword schemeFunc cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr
|
|
79 syn keyword schemeFunc cddaar cddadr cdddar cddddr null? list? list length
|
|
80 syn keyword schemeFunc append reverse list-ref memq memv member assq assv assoc
|
|
81 syn keyword schemeFunc symbol? symbol->string string->symbol number? complex?
|
|
82 syn keyword schemeFunc real? rational? integer? exact? inexact? = < > <= >=
|
|
83 syn keyword schemeFunc zero? positive? negative? odd? even? max min + * - / abs
|
|
84 syn keyword schemeFunc quotient remainder modulo gcd lcm numerator denominator
|
|
85 syn keyword schemeFunc floor ceiling truncate round rationalize exp log sin cos
|
|
86 syn keyword schemeFunc tan asin acos atan sqrt expt make-rectangular make-polar
|
|
87 syn keyword schemeFunc real-part imag-part magnitude angle exact->inexact
|
|
88 syn keyword schemeFunc inexact->exact number->string string->number char=?
|
|
89 syn keyword schemeFunc char-ci=? char<? char-ci<? char>? char-ci>? char<=?
|
|
90 syn keyword schemeFunc char-ci<=? char>=? char-ci>=? char-alphabetic? char?
|
|
91 syn keyword schemeFunc char-numeric? char-whitespace? char-upper-case?
|
|
92 syn keyword schemeFunc char-lower-case?
|
|
93 syn keyword schemeFunc char->integer integer->char char-upcase char-downcase
|
|
94 syn keyword schemeFunc string? make-string string string-length string-ref
|
|
95 syn keyword schemeFunc string-set! string=? string-ci=? string<? string-ci<?
|
|
96 syn keyword schemeFunc string>? string-ci>? string<=? string-ci<=? string>=?
|
|
97 syn keyword schemeFunc string-ci>=? substring string-append vector? make-vector
|
|
98 syn keyword schemeFunc vector vector-length vector-ref vector-set! procedure?
|
|
99 syn keyword schemeFunc apply map for-each call-with-current-continuation
|
|
100 syn keyword schemeFunc call-with-input-file call-with-output-file input-port?
|
|
101 syn keyword schemeFunc output-port? current-input-port current-output-port
|
|
102 syn keyword schemeFunc open-input-file open-output-file close-input-port
|
|
103 syn keyword schemeFunc close-output-port eof-object? read read-char peek-char
|
|
104 syn keyword schemeFunc write display newline write-char call/cc
|
|
105 syn keyword schemeFunc list-tail string->list list->string string-copy
|
|
106 syn keyword schemeFunc string-fill! vector->list list->vector vector-fill!
|
|
107 syn keyword schemeFunc force with-input-from-file with-output-to-file
|
|
108 syn keyword schemeFunc char-ready? load transcript-on transcript-off eval
|
|
109 syn keyword schemeFunc dynamic-wind port? values call-with-values
|
|
110 syn keyword schemeFunc scheme-report-environment null-environment
|
|
111 syn keyword schemeFunc interaction-environment
|
|
112
|
|
113 " ... so that a single + or -, inside a quoted context, would not be
|
|
114 " interpreted as a number (outside such contexts, it's a schemeFunc)
|
|
115
|
17
|
116 syn match schemeDelimiter oneline !\.[ \t\[\]()";]!me=e-1
|
7
|
117 syn match schemeDelimiter oneline !\.$!
|
|
118 " ... and a single dot is not a number but a delimiter
|
|
119
|
|
120 " This keeps all other stuff unhighlighted, except *stuff* and <stuff>:
|
|
121
|
17
|
122 syn match schemeOther oneline ,[a-z!$%&*/:<=>?^_~+@#%-][-a-z!$%&*/:<=>?^_~0-9+.@#%]*,
|
|
123 syn match schemeError oneline ,[a-z!$%&*/:<=>?^_~+@#%-][-a-z!$%&*/:<=>?^_~0-9+.@#%]*[^-a-z!$%&*/:<=>?^_~0-9+.@ \t\[\]()";]\+[^ \t\[\]()";]*,
|
7
|
124
|
|
125 syn match schemeOther oneline "\.\.\."
|
17
|
126 syn match schemeError oneline !\.\.\.[^ \t\[\]()";]\+!
|
7
|
127 " ... a special identifier
|
|
128
|
17
|
129 syn match schemeConstant oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*[ \t\[\]()";],me=e-1
|
7
|
130 syn match schemeConstant oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*$,
|
17
|
131 syn match schemeError oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*[^-a-z!$%&*/:<=>?^_~0-9+.@ \t\[\]()";]\+[^ \t\[\]()";]*,
|
7
|
132
|
17
|
133 syn match schemeConstant oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>[ \t\[\]()";],me=e-1
|
7
|
134 syn match schemeConstant oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>$,
|
17
|
135 syn match schemeError oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>[^-a-z!$%&*/:<=>?^_~0-9+.@ \t\[\]()";]\+[^ \t\[\]()";]*,
|
7
|
136
|
|
137 " Non-quoted lists, and strings:
|
|
138
|
|
139 syn region schemeStruc matchgroup=Delimiter start="(" matchgroup=Delimiter end=")" contains=ALL
|
|
140 syn region schemeStruc matchgroup=Delimiter start="#(" matchgroup=Delimiter end=")" contains=ALL
|
|
141
|
17
|
142 syn region schemeStruc matchgroup=Delimiter start="\[" matchgroup=Delimiter end="\]" contains=ALL
|
|
143 syn region schemeStruc matchgroup=Delimiter start="#\[" matchgroup=Delimiter end="\]" contains=ALL
|
|
144
|
|
145 " Simple literals:
|
36
|
146 syn region schemeString start=+\%(\\\)\@<!"+ skip=+\\[\\"]+ end=+"+
|
7
|
147
|
|
148 " Comments:
|
|
149
|
|
150 syn match schemeComment ";.*$"
|
|
151
|
17
|
152
|
|
153 " Writing out the complete description of Scheme numerals without
|
|
154 " using variables is a day's work for a trained secretary...
|
|
155
|
|
156 syn match schemeOther oneline ![+-][ \t\[\]()";]!me=e-1
|
|
157 syn match schemeOther oneline ![+-]$!
|
|
158 "
|
|
159 " This is a useful lax approximation:
|
|
160 syn match schemeNumber oneline "[-#+0-9.][-#+/0-9a-f@i.boxesfdl]*"
|
|
161 syn match schemeError oneline ![-#+0-9.][-#+/0-9a-f@i.boxesfdl]*[^-#+/0-9a-f@i.boxesfdl \t\[\]()";][^ \t\[\]()";]*!
|
|
162
|
|
163 syn match schemeBoolean oneline "#[tf]"
|
|
164 syn match schemeError oneline !#[tf][^ \t\[\]()";]\+!
|
|
165
|
|
166 syn match schemeChar oneline "#\\"
|
|
167 syn match schemeChar oneline "#\\."
|
|
168 syn match schemeError oneline !#\\.[^ \t\[\]()";]\+!
|
|
169 syn match schemeChar oneline "#\\space"
|
|
170 syn match schemeError oneline !#\\space[^ \t\[\]()";]\+!
|
|
171 syn match schemeChar oneline "#\\newline"
|
|
172 syn match schemeError oneline !#\\newline[^ \t\[\]()";]\+!
|
|
173
|
|
174 if exists("b:is_mzscheme") || exists("is_mzscheme")
|
36
|
175 " MzScheme extensions
|
17
|
176 " multiline comment
|
36
|
177 syn region schemeComment start="#|" end="|#"
|
|
178
|
17
|
179 " #%xxx are the special MzScheme identifiers
|
|
180 syn match schemeOther oneline "#%[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
|
|
181 " anything limited by |'s is identifier
|
|
182 syn match schemeOther oneline "|[^|]\+|"
|
|
183
|
36
|
184 syn match schemeChar oneline "#\\\%(return\|tab\)"
|
17
|
185
|
|
186 " Modules require stmt
|
|
187 syn keyword schemeExtSyntax module require dynamic-require lib prefix all-except prefix-all-except rename
|
|
188 " modules provide stmt
|
|
189 syn keyword schemeExtSyntax provide struct all-from all-from-except all-defined all-defined-except
|
|
190 " Other from MzScheme
|
|
191 syn keyword schemeExtSyntax with-handlers when unless instantiate define-struct case-lambda syntax-case
|
|
192 syn keyword schemeExtSyntax free-identifier=? bound-identifier=? module-identifier=? syntax-object->datum
|
|
193 syn keyword schemeExtSyntax datum->syntax-object
|
|
194 syn keyword schemeExtSyntax let-values let*-values letrec-values set!-values fluid-let parameterize begin0
|
|
195 syn keyword schemeExtSyntax error raise opt-lambda define-values unit unit/sig define-signature
|
|
196 syn keyword schemeExtSyntax invoke-unit/sig define-values/invoke-unit/sig compound-unit/sig import export
|
|
197 syn keyword schemeExtSyntax link syntax quasisyntax unsyntax with-syntax
|
|
198
|
|
199 syn keyword schemeExtFunc format system-type current-extension-compiler current-extension-linker
|
|
200 syn keyword schemeExtFunc use-standard-linker use-standard-compiler
|
|
201 syn keyword schemeExtFunc find-executable-path append-object-suffix append-extension-suffix
|
|
202 syn keyword schemeExtFunc current-library-collection-paths current-extension-compiler-flags make-parameter
|
|
203 syn keyword schemeExtFunc current-directory build-path normalize-path current-extension-linker-flags
|
|
204 syn keyword schemeExtFunc file-exists? directory-exists? delete-directory/files delete-directory delete-file
|
|
205 syn keyword schemeExtFunc system compile-file system-library-subpath getenv putenv current-standard-link-libraries
|
|
206 syn keyword schemeExtFunc remove* file-size find-files fold-files directory-list shell-execute split-path
|
|
207 syn keyword schemeExtFunc current-error-port process/ports process printf fprintf open-input-string open-output-string
|
|
208 syn keyword schemeExtFunc get-output-string
|
|
209 " exceptions
|
|
210 syn keyword schemeExtFunc exn exn:application:arity exn:application:continuation exn:application:fprintf:mismatch
|
|
211 syn keyword schemeExtFunc exn:application:mismatch exn:application:type exn:application:mismatch exn:break exn:i/o:filesystem exn:i/o:port
|
|
212 syn keyword schemeExtFunc exn:i/o:port:closed exn:i/o:tcp exn:i/o:udp exn:misc exn:misc:application exn:misc:unsupported exn:module exn:read
|
|
213 syn keyword schemeExtFunc exn:read:non-char exn:special-comment exn:syntax exn:thread exn:user exn:variable exn:application:mismatch
|
|
214 syn keyword schemeExtFunc exn? exn:application:arity? exn:application:continuation? exn:application:fprintf:mismatch? exn:application:mismatch?
|
|
215 syn keyword schemeExtFunc exn:application:type? exn:application:mismatch? exn:break? exn:i/o:filesystem? exn:i/o:port? exn:i/o:port:closed?
|
|
216 syn keyword schemeExtFunc exn:i/o:tcp? exn:i/o:udp? exn:misc? exn:misc:application? exn:misc:unsupported? exn:module? exn:read? exn:read:non-char?
|
|
217 syn keyword schemeExtFunc exn:special-comment? exn:syntax? exn:thread? exn:user? exn:variable? exn:application:mismatch?
|
|
218 " Command-line parsing
|
|
219 syn keyword schemeExtFunc command-line current-command-line-arguments once-any help-labels multi once-each
|
|
220
|
|
221 " syntax quoting, unquoting and quasiquotation
|
|
222 syn region schemeUnquote matchgroup=Delimiter start="#," end=![ \t\[\]()";]!me=e-1 contains=ALL
|
|
223 syn region schemeUnquote matchgroup=Delimiter start="#,@" end=![ \t\[\]()";]!me=e-1 contains=ALL
|
|
224 syn region schemeUnquote matchgroup=Delimiter start="#,(" end=")" contains=ALL
|
|
225 syn region schemeUnquote matchgroup=Delimiter start="#,@(" end=")" contains=ALL
|
|
226 syn region schemeUnquote matchgroup=Delimiter start="#,\[" end="\]" contains=ALL
|
|
227 syn region schemeUnquote matchgroup=Delimiter start="#,@\[" end="\]" contains=ALL
|
|
228 syn region schemeQuoted matchgroup=Delimiter start="#['`]" end=![ \t()\[\]";]!me=e-1 contains=ALL
|
|
229 syn region schemeQuoted matchgroup=Delimiter start="#['`](" matchgroup=Delimiter end=")" contains=ALL
|
|
230 endif
|
|
231
|
26
|
232
|
|
233 if exists("b:is_chicken") || exists("is_chicken")
|
36
|
234 " multiline comment
|
|
235 syntax region schemeMultilineComment start=/#|/ end=/|#/ contains=schemeMultilineComment
|
|
236
|
26
|
237 syn match schemeOther oneline "##[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
|
|
238 syn match schemeExtSyntax oneline "#:[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
|
|
239
|
|
240 syn keyword schemeExtSyntax unit uses declare hide foreign-declare foreign-parse foreign-parse/spec
|
36
|
241 syn keyword schemeExtSyntax foreign-lambda foreign-lambda* define-external define-macro load-library
|
|
242 syn keyword schemeExtSyntax let-values let*-values letrec-values ->string require-extension
|
|
243 syn keyword schemeExtSyntax let-optionals let-optionals* define-foreign-variable define-record
|
|
244 syn keyword schemeExtSyntax pointer tag-pointer tagged-pointer? define-foreign-type
|
|
245 syn keyword schemeExtSyntax require require-for-syntax cond-expand and-let* receive argc+argv
|
|
246 syn keyword schemeExtSyntax fixnum? fx= fx> fx< fx>= fx<= fxmin fxmax
|
26
|
247 syn keyword schemeExtFunc ##core#inline ##sys#error ##sys#update-errno
|
|
248
|
|
249 " here-string
|
|
250 syn region schemeString start=+#<<\s*\z(.*\)+ end=+^\z1$+
|
|
251
|
|
252 if filereadable(expand("<sfile>:p:h")."/cpp.vim")
|
|
253 unlet! b:current_syntax
|
|
254 syn include @ChickenC <sfile>:p:h/cpp.vim
|
|
255 syn region ChickenC matchgroup=schemeOther start=+(\@<=foreign-declare "+ end=+")\@=+ contains=@ChickenC
|
|
256 syn region ChickenC matchgroup=schemeComment start=+foreign-declare\s*#<<\z(.*\)$+hs=s+15 end=+^\z1$+ contains=@ChickenC
|
|
257 syn region ChickenC matchgroup=schemeOther start=+(\@<=foreign-parse "+ end=+")\@=+ contains=@ChickenC
|
|
258 syn region ChickenC matchgroup=schemeComment start=+foreign-parse\s*#<<\z(.*\)$+hs=s+13 end=+^\z1$+ contains=@ChickenC
|
|
259 syn region ChickenC matchgroup=schemeOther start=+(\@<=foreign-parse/spec "+ end=+")\@=+ contains=@ChickenC
|
|
260 syn region ChickenC matchgroup=schemeComment start=+foreign-parse/spec\s*#<<\z(.*\)$+hs=s+18 end=+^\z1$+ contains=@ChickenC
|
|
261 syn region ChickenC matchgroup=schemeComment start=+#>+ end=+<#+ contains=@ChickenC
|
|
262 syn region ChickenC matchgroup=schemeComment start=+#>?+ end=+<#+ contains=@ChickenC
|
|
263 syn region ChickenC matchgroup=schemeComment start=+#>!+ end=+<#+ contains=@ChickenC
|
|
264 syn region ChickenC matchgroup=schemeComment start=+#>\$+ end=+<#+ contains=@ChickenC
|
|
265 syn region ChickenC matchgroup=schemeComment start=+#>%+ end=+<#+ contains=@ChickenC
|
|
266 endif
|
|
267
|
1619
|
268 " suggested by Alex Queiroz
|
|
269 syn match schemeExtSyntax oneline "#![-a-z!$%&*/:<=>?^_~0-9+.@#%]\+"
|
|
270 syn region schemeString start=+#<#\s*\z(.*\)+ end=+^\z1$+
|
26
|
271 endif
|
|
272
|
7
|
273 " Synchronization and the wrapping up...
|
|
274
|
|
275 syn sync match matchPlace grouphere NONE "^[^ \t]"
|
|
276 " ... i.e. synchronize on a line that starts at the left margin
|
|
277
|
|
278 " Define the default highlighting.
|
|
279 " For version 5.7 and earlier: only when not done already
|
|
280 " For version 5.8 and later: only when an item doesn't have highlighting yet
|
|
281 if version >= 508 || !exists("did_scheme_syntax_inits")
|
|
282 if version < 508
|
|
283 let did_scheme_syntax_inits = 1
|
|
284 command -nargs=+ HiLink hi link <args>
|
|
285 else
|
|
286 command -nargs=+ HiLink hi def link <args>
|
|
287 endif
|
|
288
|
|
289 HiLink schemeSyntax Statement
|
|
290 HiLink schemeFunc Function
|
|
291
|
|
292 HiLink schemeString String
|
|
293 HiLink schemeChar Character
|
|
294 HiLink schemeNumber Number
|
|
295 HiLink schemeBoolean Boolean
|
|
296
|
|
297 HiLink schemeDelimiter Delimiter
|
26
|
298 HiLink schemeConstant Constant
|
7
|
299
|
|
300 HiLink schemeComment Comment
|
17
|
301 HiLink schemeMultilineComment Comment
|
7
|
302 HiLink schemeError Error
|
|
303
|
26
|
304 HiLink schemeExtSyntax Type
|
|
305 HiLink schemeExtFunc PreProc
|
7
|
306 delcommand HiLink
|
|
307 endif
|
|
308
|
|
309 let b:current_syntax = "scheme"
|