Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 2 | " Language: R (GNU S) |
| 3 | " Maintainer: Jakson Aquino <jalvesaq@gmail.com> |
| 4 | " Former Maintainers: Vaidotas Zemlys <zemlys@gmail.com> |
| 5 | " Tom Payne <tom@tompayne.org> |
| 6 | " Last Change: Wed Sep 29, 2010 09:31AM |
| 7 | " Filenames: *.R *.r *.Rhistory *.Rt |
| 8 | " |
| 9 | " NOTE: The highlighting of R functions is defined in the |
| 10 | " r-plugin/functions.vim, which is part of vim-r-plugin2: |
| 11 | " http://www.vim.org/scripts/script.php?script_id=2628 |
| 12 | " |
| 13 | " Some lines of code were borrowed from Zhuojun Chen. |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 14 | |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 15 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | finish |
| 17 | endif |
| 18 | |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 19 | setlocal iskeyword=@,48-57,_,. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 20 | |
| 21 | syn case match |
| 22 | |
| 23 | " Comment |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 24 | syn match rComment contains=@Spell "\#.*" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 25 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | " string enclosed in double quotes |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 27 | syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 28 | " string enclosed in single quotes |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 29 | syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 31 | syn match rStrError display contained "\\." |
| 32 | |
| 33 | " New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash |
| 34 | syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\" |
| 35 | |
| 36 | " Hexadecimal and Octal digits |
| 37 | syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)" |
| 38 | |
| 39 | " Unicode characters |
| 40 | syn match rSpecial display contained "\\u\x\{1,4}" |
| 41 | syn match rSpecial display contained "\\U\x\{1,8}" |
| 42 | syn match rSpecial display contained "\\u{\x\{1,4}}" |
| 43 | syn match rSpecial display contained "\\U{\x\{1,8}}" |
| 44 | |
| 45 | |
| 46 | syn match rDollar "\$" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | |
| 48 | " Statement |
| 49 | syn keyword rStatement break next return |
| 50 | syn keyword rConditional if else |
| 51 | syn keyword rRepeat for in repeat while |
| 52 | |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 53 | " Constant (not really) |
| 54 | syn keyword rConstant T F LETTERS letters month.ab month.name pi |
| 55 | syn keyword rConstant R.version.string |
| 56 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 57 | " Constant |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 58 | syn keyword rConstant NULL |
| 59 | syn keyword rBoolean FALSE TRUE |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 60 | syn keyword rNumber NA NA_integer_ NA_real_ NA_complex_ NA_character_ |
| 61 | syn keyword rNumber Inf NaN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 62 | |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 63 | " integer |
| 64 | syn match rInteger "\<\d\+L" |
| 65 | syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L" |
| 66 | syn match rInteger "\<\d\+[Ee]+\=\d\+L" |
| 67 | |
| 68 | syn match rOperator "[\*\!\&\+\-\<\>\=\^\|\~\`/:@]" |
| 69 | syn match rOperator "%\{2}\|%\*%\|%\/%\|%in%\|%o%\|%x%" |
| 70 | |
| 71 | syn match rComplex "\<\d\+i" |
| 72 | syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i" |
| 73 | syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i" |
| 74 | syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i" |
| 75 | syn match rComplex "\<\d\+[Ee][-+]\=\d\+i" |
| 76 | |
| 77 | " number with no fractional part or exponent |
| 78 | syn match rNumber "\<\d\+\>" |
| 79 | " hexadecimal number |
| 80 | syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+" |
| 81 | |
| 82 | " floating point number with integer and fractional parts and optional exponent |
| 83 | syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=" |
| 84 | " floating point number with no integer part and optional exponent |
| 85 | syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\=" |
| 86 | " floating point number with no fractional part and optional exponent |
| 87 | syn match rFloat "\<\d\+[Ee][-+]\=\d\+" |
| 88 | |
| 89 | syn match rArrow "<\{1,2}-" |
| 90 | syn match rArrow "->\{1,2}" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 91 | |
| 92 | " Special |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 93 | syn match rDelimiter "[,;:]" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 94 | |
| 95 | " Error |
| 96 | syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError |
| 97 | syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError |
| 98 | syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 99 | syn match rError "[)\]}]" |
| 100 | syn match rBraceError "[)}]" contained |
| 101 | syn match rCurlyError "[)\]]" contained |
| 102 | syn match rParenError "[\]}]" contained |
| 103 | |
| 104 | " Functions that may add new objects |
| 105 | syn keyword rPreProc library require attach detach source |
| 106 | |
| 107 | " Type |
| 108 | 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] | 109 | |
| 110 | " Define the default highlighting. |
Bram Moolenaar | 483c5d8 | 2010-10-20 18:45:33 +0200 | [diff] [blame] | 111 | hi def link rArrow Statement |
| 112 | hi def link rBoolean Boolean |
| 113 | hi def link rBraceError Error |
| 114 | hi def link rComment Comment |
| 115 | hi def link rComplex Number |
| 116 | hi def link rConditional Conditional |
| 117 | hi def link rConstant Constant |
| 118 | hi def link rCurlyError Error |
| 119 | hi def link rDelimiter Delimiter |
| 120 | hi def link rDollar SpecialChar |
| 121 | hi def link rError Error |
| 122 | hi def link rFloat Float |
| 123 | hi def link rInteger Number |
| 124 | hi def link rNumber Number |
| 125 | hi def link rOperator Operator |
| 126 | hi def link rParenError Error |
| 127 | hi def link rPreProc PreProc |
| 128 | hi def link rRepeat Repeat |
| 129 | hi def link rSpecial SpecialChar |
| 130 | hi def link rStatement Statement |
| 131 | hi def link rString String |
| 132 | hi def link rStrError Error |
| 133 | hi def link rType Type |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | |
| 135 | let b:current_syntax="r" |
| 136 | |
| 137 | " vim: ts=8 sw=2 |