2 " Language: Scheme (R5RS)
3 " Maintainer: Dirk van Deun <dvandeun@poboxes.com>
4 " Last Change: April 30, 1998
6 " This script incorrectly recognizes some junk input as numerals:
7 " parsing the complete system of Scheme numerals using the pattern
8 " language is practically impossible: I did a lax approximation.
10 " Suggestions and bug reports are solicited by the author.
14 " For version 5.x: Clear all syntax items
15 " For version 6.x: Quit when a syntax file was already loaded
18 elseif exists("b:current_syntax")
24 " Fascist highlighting: everything that doesn't fit the rules is an error...
26 syn match schemeError oneline ![^ \t()";]*!
27 syn match schemeError oneline ")"
29 " Quoted and backquoted stuff
31 syn region schemeQuoted matchgroup=Delimiter start="['`]" end=![ \t()";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
33 syn region schemeQuoted matchgroup=Delimiter start="['`](" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
34 syn region schemeQuoted matchgroup=Delimiter start="['`]#(" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
36 syn region schemeStrucRestricted matchgroup=Delimiter start="(" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
37 syn region schemeStrucRestricted matchgroup=Delimiter start="#(" matchgroup=Delimiter end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
39 syn region schemeUnquote matchgroup=Delimiter start="," end=![ \t()";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
40 syn region schemeUnquote matchgroup=Delimiter start=",@" end=![ \t()";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
42 syn region schemeUnquote matchgroup=Delimiter start=",(" end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
43 syn region schemeUnquote matchgroup=Delimiter start=",@(" end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
45 syn region schemeUnquote matchgroup=Delimiter start=",#(" end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
46 syn region schemeUnquote matchgroup=Delimiter start=",@#(" end=")" contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc
48 " R5RS Scheme Functions and Syntax:
51 set iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_
53 setlocal iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_
56 syn keyword schemeSyntax lambda and or if cond case define let let* letrec
57 syn keyword schemeSyntax begin do delay set! else =>
58 syn keyword schemeSyntax quote quasiquote unquote unquote-splicing
59 syn keyword schemeSyntax define-syntax let-syntax letrec-syntax syntax-rules
61 syn keyword schemeFunc not boolean? eq? eqv? equal? pair? cons car cdr set-car!
62 syn keyword schemeFunc set-cdr! caar cadr cdar cddr caaar caadr cadar caddr
63 syn keyword schemeFunc cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr
64 syn keyword schemeFunc cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr
65 syn keyword schemeFunc cddaar cddadr cdddar cddddr null? list? list length
66 syn keyword schemeFunc append reverse list-ref memq memv member assq assv assoc
67 syn keyword schemeFunc symbol? symbol->string string->symbol number? complex?
68 syn keyword schemeFunc real? rational? integer? exact? inexact? = < > <= >=
69 syn keyword schemeFunc zero? positive? negative? odd? even? max min + * - / abs
70 syn keyword schemeFunc quotient remainder modulo gcd lcm numerator denominator
71 syn keyword schemeFunc floor ceiling truncate round rationalize exp log sin cos
72 syn keyword schemeFunc tan asin acos atan sqrt expt make-rectangular make-polar
73 syn keyword schemeFunc real-part imag-part magnitude angle exact->inexact
74 syn keyword schemeFunc inexact->exact number->string string->number char=?
75 syn keyword schemeFunc char-ci=? char<? char-ci<? char>? char-ci>? char<=?
76 syn keyword schemeFunc char-ci<=? char>=? char-ci>=? char-alphabetic? char?
77 syn keyword schemeFunc char-numeric? char-whitespace? char-upper-case?
78 syn keyword schemeFunc char-lower-case?
79 syn keyword schemeFunc char->integer integer->char char-upcase char-downcase
80 syn keyword schemeFunc string? make-string string string-length string-ref
81 syn keyword schemeFunc string-set! string=? string-ci=? string<? string-ci<?
82 syn keyword schemeFunc string>? string-ci>? string<=? string-ci<=? string>=?
83 syn keyword schemeFunc string-ci>=? substring string-append vector? make-vector
84 syn keyword schemeFunc vector vector-length vector-ref vector-set! procedure?
85 syn keyword schemeFunc apply map for-each call-with-current-continuation
86 syn keyword schemeFunc call-with-input-file call-with-output-file input-port?
87 syn keyword schemeFunc output-port? current-input-port current-output-port
88 syn keyword schemeFunc open-input-file open-output-file close-input-port
89 syn keyword schemeFunc close-output-port eof-object? read read-char peek-char
90 syn keyword schemeFunc write display newline write-char call/cc
91 syn keyword schemeFunc list-tail string->list list->string string-copy
92 syn keyword schemeFunc string-fill! vector->list list->vector vector-fill!
93 syn keyword schemeFunc force with-input-from-file with-output-to-file
94 syn keyword schemeFunc char-ready? load transcript-on transcript-off eval
95 syn keyword schemeFunc dynamic-wind port? values call-with-values
96 syn keyword schemeFunc scheme-report-environment null-environment
97 syn keyword schemeFunc interaction-environment
99 " Writing out the complete description of Scheme numerals without
100 " using variables is a day's work for a trained secretary...
101 " This is a useful lax approximation:
103 syn match schemeNumber oneline "[-#+0-9.][-#+/0-9a-f@i.boxesfdl]*"
104 syn match schemeError oneline ![-#+0-9.][-#+/0-9a-f@i.boxesfdl]*[^-#+/0-9a-f@i.boxesfdl \t()";][^ \t()";]*!
106 syn match schemeOther oneline ![+-][ \t()";]!me=e-1
107 syn match schemeOther oneline ![+-]$!
108 " ... so that a single + or -, inside a quoted context, would not be
109 " interpreted as a number (outside such contexts, it's a schemeFunc)
111 syn match schemeDelimiter oneline !\.[ \t()";]!me=e-1
112 syn match schemeDelimiter oneline !\.$!
113 " ... and a single dot is not a number but a delimiter
117 syn match schemeBoolean oneline "#[tf]"
118 syn match schemeError oneline !#[tf][^ \t()";]\+!
120 syn match schemeChar oneline "#\\"
121 syn match schemeChar oneline "#\\."
122 syn match schemeError oneline !#\\.[^ \t()";]\+!
123 syn match schemeChar oneline "#\\space"
124 syn match schemeError oneline !#\\space[^ \t()";]\+!
125 syn match schemeChar oneline "#\\newline"
126 syn match schemeError oneline !#\\newline[^ \t()";]\+!
128 " This keeps all other stuff unhighlighted, except *stuff* and <stuff>:
130 syn match schemeOther oneline ,[a-z!$%&*/:<=>?^_~][-a-z!$%&*/:<=>?^_~0-9+.@]*,
131 syn match schemeError oneline ,[a-z!$%&*/:<=>?^_~][-a-z!$%&*/:<=>?^_~0-9+.@]*[^-a-z!$%&*/:<=>?^_~0-9+.@ \t()";]\+[^ \t()";]*,
133 syn match schemeOther oneline "\.\.\."
134 syn match schemeError oneline !\.\.\.[^ \t()";]\+!
135 " ... a special identifier
137 syn match schemeConstant oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*[ \t()";],me=e-1
138 syn match schemeConstant oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*$,
139 syn match schemeError oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*[^-a-z!$%&*/:<=>?^_~0-9+.@ \t()";]\+[^ \t()";]*,
141 syn match schemeConstant oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>[ \t()";],me=e-1
142 syn match schemeConstant oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>$,
143 syn match schemeError oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>[^-a-z!$%&*/:<=>?^_~0-9+.@ \t()";]\+[^ \t()";]*,
145 " Non-quoted lists, and strings:
147 syn region schemeStruc matchgroup=Delimiter start="(" matchgroup=Delimiter end=")" contains=ALL
148 syn region schemeStruc matchgroup=Delimiter start="#(" matchgroup=Delimiter end=")" contains=ALL
150 syn region schemeString start=+"+ skip=+\\[\\"]+ end=+"+
154 syn match schemeComment ";.*$"
156 " Synchronization and the wrapping up...
158 syn sync match matchPlace grouphere NONE "^[^ \t]"
159 " ... i.e. synchronize on a line that starts at the left margin
161 " Define the default highlighting.
162 " For version 5.7 and earlier: only when not done already
163 " For version 5.8 and later: only when an item doesn't have highlighting yet
164 if version >= 508 || !exists("did_scheme_syntax_inits")
166 let did_scheme_syntax_inits = 1
167 command -nargs=+ HiLink hi link <args>
169 command -nargs=+ HiLink hi def link <args>
172 HiLink schemeSyntax Statement
173 HiLink schemeFunc Function
175 HiLink schemeString String
176 HiLink schemeChar Character
177 HiLink schemeNumber Number
178 HiLink schemeBoolean Boolean
180 HiLink schemeDelimiter Delimiter
181 HiLink schemeConstant Constant
183 HiLink schemeComment Comment
184 HiLink schemeError Error
189 let b:current_syntax = "scheme"