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