Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Scheme (R5RS) |
| 3 | " Maintainer: Dirk van Deun <dirk@igwe.vub.ac.be> |
| 4 | " Last Change: April 30, 1998 |
| 5 | |
| 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. |
| 9 | |
| 10 | " Suggestions and bug reports are solicited by the author. |
| 11 | |
| 12 | " Initializing: |
| 13 | |
| 14 | " For version 5.x: Clear all syntax items |
| 15 | " For version 6.x: Quit when a syntax file was already loaded |
| 16 | if version < 600 |
| 17 | syntax clear |
| 18 | elseif exists("b:current_syntax") |
| 19 | finish |
| 20 | endif |
| 21 | |
| 22 | syn case ignore |
| 23 | |
| 24 | " Fascist highlighting: everything that doesn't fit the rules is an error... |
| 25 | |
| 26 | syn match schemeError oneline ![^ \t()";]*! |
| 27 | syn match schemeError oneline ")" |
| 28 | |
| 29 | " Quoted and backquoted stuff |
| 30 | |
| 31 | syn region schemeQuoted matchgroup=Delimiter start="['`]" end=![ \t()";]!me=e-1 contains=ALLBUT,schemeStruc,schemeSyntax,schemeFunc |
| 32 | |
| 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 |
| 35 | |
| 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 |
| 38 | |
| 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 |
| 41 | |
| 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 |
| 44 | |
| 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 |
| 47 | |
| 48 | " R5RS Scheme Functions and Syntax: |
| 49 | |
| 50 | if version < 600 |
| 51 | set iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_ |
| 52 | else |
| 53 | setlocal iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_ |
| 54 | endif |
| 55 | |
| 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 |
| 60 | |
| 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 |
| 98 | |
| 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: |
| 102 | |
| 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()";]*! |
| 105 | |
| 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) |
| 110 | |
| 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 |
| 114 | |
| 115 | " Simple literals: |
| 116 | |
| 117 | syn match schemeBoolean oneline "#[tf]" |
| 118 | syn match schemeError oneline !#[tf][^ \t()";]\+! |
| 119 | |
| 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()";]\+! |
| 127 | |
| 128 | " This keeps all other stuff unhighlighted, except *stuff* and <stuff>: |
| 129 | |
| 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()";]*, |
| 132 | |
| 133 | syn match schemeOther oneline "\.\.\." |
| 134 | syn match schemeError oneline !\.\.\.[^ \t()";]\+! |
| 135 | " ... a special identifier |
| 136 | |
| 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()";]*, |
| 140 | |
| 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()";]*, |
| 144 | |
| 145 | " Non-quoted lists, and strings: |
| 146 | |
| 147 | syn region schemeStruc matchgroup=Delimiter start="(" matchgroup=Delimiter end=")" contains=ALL |
| 148 | syn region schemeStruc matchgroup=Delimiter start="#(" matchgroup=Delimiter end=")" contains=ALL |
| 149 | |
| 150 | syn region schemeString start=+"+ skip=+\\[\\"]+ end=+"+ |
| 151 | |
| 152 | " Comments: |
| 153 | |
| 154 | syn match schemeComment ";.*$" |
| 155 | |
| 156 | " Synchronization and the wrapping up... |
| 157 | |
| 158 | syn sync match matchPlace grouphere NONE "^[^ \t]" |
| 159 | " ... i.e. synchronize on a line that starts at the left margin |
| 160 | |
| 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") |
| 165 | if version < 508 |
| 166 | let did_scheme_syntax_inits = 1 |
| 167 | command -nargs=+ HiLink hi link <args> |
| 168 | else |
| 169 | command -nargs=+ HiLink hi def link <args> |
| 170 | endif |
| 171 | |
| 172 | HiLink schemeSyntax Statement |
| 173 | HiLink schemeFunc Function |
| 174 | |
| 175 | HiLink schemeString String |
| 176 | HiLink schemeChar Character |
| 177 | HiLink schemeNumber Number |
| 178 | HiLink schemeBoolean Boolean |
| 179 | |
| 180 | HiLink schemeDelimiter Delimiter |
| 181 | HiLink schemeConstant Constant |
| 182 | |
| 183 | HiLink schemeComment Comment |
| 184 | HiLink schemeError Error |
| 185 | |
| 186 | delcommand HiLink |
| 187 | endif |
| 188 | |
| 189 | let b:current_syntax = "scheme" |