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