Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Scheme (R5RS) |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 3 | " Last Change: July 14, 2004 |
| 4 | " Maintainer: Sergey Khorev <iamphet@nm.ru> |
| 5 | " Original author: Dirk van Deun <dirk@igwe.vub.ac.be> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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. |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 10 | |
| 11 | " MzScheme extensions can be activated with setting is_mzscheme variable |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 29 | syn match schemeError oneline ![^ \t()\[\]";]*! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | syn match schemeError oneline ")" |
| 31 | |
| 32 | " Quoted and backquoted stuff |
| 33 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 34 | syn region schemeQuoted matchgroup=Delimiter start="['`]" end=![ \t()\[\]";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 116 | syn match schemeDelimiter oneline !\.[ \t\[\]()";]!me=e-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 117 | syn match schemeDelimiter oneline !\.$! |
| 118 | " ... and a single dot is not a number but a delimiter |
| 119 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 120 | " This keeps all other stuff unhighlighted, except *stuff* and <stuff>: |
| 121 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 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\[\]()";]*, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 124 | |
| 125 | syn match schemeOther oneline "\.\.\." |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 126 | syn match schemeError oneline !\.\.\.[^ \t\[\]()";]\+! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 127 | " ... a special identifier |
| 128 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 129 | syn match schemeConstant oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*[ \t\[\]()";],me=e-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 130 | syn match schemeConstant oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*$, |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 131 | syn match schemeError oneline ,\*[-a-z!$%&*/:<=>?^_~0-9+.@]*\*[^-a-z!$%&*/:<=>?^_~0-9+.@ \t\[\]()";]\+[^ \t\[\]()";]*, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 132 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 133 | syn match schemeConstant oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>[ \t\[\]()";],me=e-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | syn match schemeConstant oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>$, |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 135 | syn match schemeError oneline ,<[-a-z!$%&*/:<=>?^_~0-9+.@]*>[^-a-z!$%&*/:<=>?^_~0-9+.@ \t\[\]()";]\+[^ \t\[\]()";]*, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 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: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 146 | syn region schemeString start=+"+ skip=+\\[\\"]+ end=+"+ |
| 147 | |
| 148 | " Comments: |
| 149 | |
| 150 | syn match schemeComment ";.*$" |
| 151 | |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 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") |
| 175 | " MzScheme extensions added by Sergey Khorev |
| 176 | " multiline comment |
| 177 | syntax region schemeMultilineComment start=/#|/ end=/|#/ |
| 178 | " #%xxx are the special MzScheme identifiers |
| 179 | syn match schemeOther oneline "#%[-a-z!$%&*/:<=>?^_~0-9+.@#%]\+" |
| 180 | " anything limited by |'s is identifier |
| 181 | syn match schemeOther oneline "|[^|]\+|" |
| 182 | |
| 183 | syn match schemeChar oneline "#\\return" |
| 184 | |
| 185 | " Modules require stmt |
| 186 | syn keyword schemeExtSyntax module require dynamic-require lib prefix all-except prefix-all-except rename |
| 187 | " modules provide stmt |
| 188 | syn keyword schemeExtSyntax provide struct all-from all-from-except all-defined all-defined-except |
| 189 | " Other from MzScheme |
| 190 | syn keyword schemeExtSyntax with-handlers when unless instantiate define-struct case-lambda syntax-case |
| 191 | syn keyword schemeExtSyntax free-identifier=? bound-identifier=? module-identifier=? syntax-object->datum |
| 192 | syn keyword schemeExtSyntax datum->syntax-object |
| 193 | syn keyword schemeExtSyntax let-values let*-values letrec-values set!-values fluid-let parameterize begin0 |
| 194 | syn keyword schemeExtSyntax error raise opt-lambda define-values unit unit/sig define-signature |
| 195 | syn keyword schemeExtSyntax invoke-unit/sig define-values/invoke-unit/sig compound-unit/sig import export |
| 196 | syn keyword schemeExtSyntax link syntax quasisyntax unsyntax with-syntax |
| 197 | hi def link schemeExtSyntax Type |
| 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 | hi def link schemeExtFunc PreProc |
| 221 | |
| 222 | " syntax quoting, unquoting and quasiquotation |
| 223 | syn region schemeUnquote matchgroup=Delimiter start="#," end=![ \t\[\]()";]!me=e-1 contains=ALL |
| 224 | syn region schemeUnquote matchgroup=Delimiter start="#,@" end=![ \t\[\]()";]!me=e-1 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 schemeUnquote matchgroup=Delimiter start="#,@\[" end="\]" contains=ALL |
| 229 | syn region schemeQuoted matchgroup=Delimiter start="#['`]" end=![ \t()\[\]";]!me=e-1 contains=ALL |
| 230 | syn region schemeQuoted matchgroup=Delimiter start="#['`](" matchgroup=Delimiter end=")" contains=ALL |
| 231 | endif |
| 232 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 233 | " Synchronization and the wrapping up... |
| 234 | |
| 235 | syn sync match matchPlace grouphere NONE "^[^ \t]" |
| 236 | " ... i.e. synchronize on a line that starts at the left margin |
| 237 | |
| 238 | " Define the default highlighting. |
| 239 | " For version 5.7 and earlier: only when not done already |
| 240 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 241 | if version >= 508 || !exists("did_scheme_syntax_inits") |
| 242 | if version < 508 |
| 243 | let did_scheme_syntax_inits = 1 |
| 244 | command -nargs=+ HiLink hi link <args> |
| 245 | else |
| 246 | command -nargs=+ HiLink hi def link <args> |
| 247 | endif |
| 248 | |
| 249 | HiLink schemeSyntax Statement |
| 250 | HiLink schemeFunc Function |
| 251 | |
| 252 | HiLink schemeString String |
| 253 | HiLink schemeChar Character |
| 254 | HiLink schemeNumber Number |
| 255 | HiLink schemeBoolean Boolean |
| 256 | |
| 257 | HiLink schemeDelimiter Delimiter |
| 258 | HiLink schemeConstant Constant |
| 259 | |
| 260 | HiLink schemeComment Comment |
Bram Moolenaar | 21cf823 | 2004-07-16 20:18:37 +0000 | [diff] [blame] | 261 | HiLink schemeMultilineComment Comment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 262 | HiLink schemeError Error |
| 263 | |
| 264 | delcommand HiLink |
| 265 | endif |
| 266 | |
| 267 | let b:current_syntax = "scheme" |