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