Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: R (GNU S) |
| 3 | " Maintainer: Tom Payne <tom@tompayne.org> |
| 4 | " Last Change: 2003 May 11 |
| 5 | " Filenames: *.r |
| 6 | " URL: http://www.tompayne.org/vim/syntax/r.vim |
| 7 | |
| 8 | " For version 5.x: Clear all syntax items |
| 9 | " For version 6.x: Quit when a syntax file was already loaded |
| 10 | if version < 600 |
| 11 | syntax clear |
| 12 | elseif exists("b:current_syntax") |
| 13 | finish |
| 14 | endif |
| 15 | |
| 16 | if version >= 600 |
| 17 | setlocal iskeyword=@,48-57,_,. |
| 18 | else |
| 19 | set iskeyword=@,48-57,_,. |
| 20 | endif |
| 21 | |
| 22 | syn case match |
| 23 | |
| 24 | " Comment |
| 25 | syn match rComment /\#.*/ |
| 26 | |
| 27 | " Constant |
| 28 | " string enclosed in double quotes |
| 29 | syn region rString start=/"/ skip=/\\\\\|\\"/ end=/"/ |
| 30 | " string enclosed in single quotes |
| 31 | syn region rString start=/'/ skip=/\\\\\|\\'/ end=/'/ |
| 32 | " number with no fractional part or exponent |
| 33 | syn match rNumber /\d\+/ |
| 34 | " floating point number with integer and fractional parts and optional exponent |
| 35 | syn match rFloat /\d\+\.\d*\([Ee][-+]\=\d\+\)\=/ |
| 36 | " floating point number with no integer part and optional exponent |
| 37 | syn match rFloat /\.\d\+\([Ee][-+]\=\d\+\)\=/ |
| 38 | " floating point number with no fractional part and optional exponent |
| 39 | syn match rFloat /\d\+[Ee][-+]\=\d\+/ |
| 40 | |
| 41 | " Identifier |
| 42 | " identifier with leading letter and optional following keyword characters |
| 43 | syn match rIdentifier /\a\k*/ |
| 44 | " identifier with leading period, one or more digits, and at least one non-digit keyword character |
| 45 | syn match rIdentifier /\.\d*\K\k*/ |
| 46 | |
| 47 | " Statement |
| 48 | syn keyword rStatement break next return |
| 49 | syn keyword rConditional if else |
| 50 | syn keyword rRepeat for in repeat while |
| 51 | |
| 52 | " Constant |
| 53 | syn keyword rConstant LETTERS letters month.ab month.name pi |
| 54 | syn keyword rConstant NULL |
| 55 | syn keyword rBoolean FALSE TRUE |
| 56 | syn keyword rNumber NA |
| 57 | |
| 58 | " Type |
| 59 | syn keyword rType array category character complex double function integer list logical matrix numeric vector |
| 60 | |
| 61 | " Special |
| 62 | syn match rDelimiter /[,;:]/ |
| 63 | |
| 64 | " Error |
| 65 | syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError |
| 66 | syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError |
| 67 | syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError |
| 68 | syn match rError /[)\]}]/ |
| 69 | syn match rBraceError /[)}]/ contained |
| 70 | syn match rCurlyError /[)\]]/ contained |
| 71 | syn match rParenError /[\]}]/ contained |
| 72 | |
| 73 | " Define the default highlighting. |
| 74 | " For version 5.7 and earlier: only when not done already |
| 75 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 76 | if version >= 508 || !exists("did_r_syn_inits") |
| 77 | if version < 508 |
| 78 | let did_r_syn_inits = 1 |
| 79 | command -nargs=+ HiLink hi link <args> |
| 80 | else |
| 81 | command -nargs=+ HiLink hi def link <args> |
| 82 | endif |
| 83 | HiLink rComment Comment |
| 84 | HiLink rConstant Constant |
| 85 | HiLink rString String |
| 86 | HiLink rNumber Number |
| 87 | HiLink rBoolean Boolean |
| 88 | HiLink rFloat Float |
| 89 | HiLink rStatement Statement |
| 90 | HiLink rConditional Conditional |
| 91 | HiLink rRepeat Repeat |
| 92 | HiLink rIdentifier Identifier |
| 93 | HiLink rType Type |
| 94 | HiLink rDelimiter Delimiter |
| 95 | HiLink rError Error |
| 96 | HiLink rBraceError Error |
| 97 | HiLink rCurlyError Error |
| 98 | HiLink rParenError Error |
| 99 | delcommand HiLink |
| 100 | endif |
| 101 | |
| 102 | let b:current_syntax="r" |
| 103 | |
| 104 | " vim: ts=8 sw=2 |