blob: d96bf96acb30fb4d85cca36850a26dd9598a01e8 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaar483c5d82010-10-20 18:45:33 +02002" 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>
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +01006" Contributor: Johannes Ranke <jranke@uni-bremen.de>
7" Homepage: https://github.com/jalvesaq/R-Vim-runtime
Bram Moolenaar77cdfd12016-03-12 12:57:59 +01008" Last Change: Thu Mar 10, 2016 12:26PM
Bram Moolenaar483c5d82010-10-20 18:45:33 +02009" Filenames: *.R *.r *.Rhistory *.Rt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010"
11" NOTE: The highlighting of R functions is defined in
12" runtime files created by a filetype plugin, if installed.
Bram Moolenaar483c5d82010-10-20 18:45:33 +020013"
Bram Moolenaar662db672011-03-22 14:05:35 +010014" CONFIGURATION:
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010015" Syntax folding can be turned on by
Bram Moolenaar662db672011-03-22 14:05:35 +010016"
17" let r_syntax_folding = 1
18"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010019" ROxygen highlighting can be turned off by
20"
21" let r_hl_roxygen = 0
22"
Bram Moolenaar483c5d82010-10-20 18:45:33 +020023" Some lines of code were borrowed from Zhuojun Chen.
Bram Moolenaar4770d092006-01-12 23:22:24 +000024
Bram Moolenaar483c5d82010-10-20 18:45:33 +020025if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 finish
27endif
28
Bram Moolenaar483c5d82010-10-20 18:45:33 +020029setlocal iskeyword=@,48-57,_,.
Bram Moolenaar071d4272004-06-13 20:20:40 +000030
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010031if exists("g:r_syntax_folding") && g:r_syntax_folding
Bram Moolenaar662db672011-03-22 14:05:35 +010032 setlocal foldmethod=syntax
33endif
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010034if !exists("g:r_hl_roxygen")
35 let g:r_hl_roxygen = 1
36endif
Bram Moolenaar662db672011-03-22 14:05:35 +010037
Bram Moolenaar071d4272004-06-13 20:20:40 +000038syn case match
39
40" Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +020041syn match rCommentTodo contained "\(BUG\|FIXME\|NOTE\|TODO\):"
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +010042syn match rComment contains=@Spell,rCommentTodo,rOBlock "#.*"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020043
44" Roxygen
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010045if g:r_hl_roxygen
46 syn region rOBlock start="^\s*\n#\{1,2}' " start="\%^#\{1,2}' " end="^\(#\{1,2}'\)\@!" contains=rOTitle,rOKeyword,rOExamples,@Spell keepend
47 syn region rOTitle start="^\s*\n#\{1,2}' " start="\%^#\{1,2}' " end="^\(#\{1,2}'\s*$\)\@=" contained contains=rOCommentKey
48 syn match rOCommentKey "#\{1,2}'" containedin=rOTitle contained
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +010049
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010050 syn region rOExamples start="^#\{1,2}' @examples.*"rs=e+1,hs=e+1 end="^\(#\{1,2}' @.*\)\@=" end="^\(#\{1,2}'\)\@!" contained contains=rOKeyword
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +010051
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010052 syn match rOKeyword contained "@\(param\|return\|name\|rdname\|examples\|example\|include\|docType\)"
53 syn match rOKeyword contained "@\(S3method\|TODO\|aliases\|alias\|assignee\|author\|callGraphDepth\|callGraph\)"
54 syn match rOKeyword contained "@\(callGraphPrimitives\|concept\|exportClass\|exportMethod\|exportPattern\|export\|formals\)"
55 syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\|useDynLib\)"
56 syn match rOKeyword contained "@\(method\|noRd\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)"
57 syn match rOKeyword contained "@\(family\|template\|templateVar\|description\|details\|inheritParams\|field\)"
58endif
Bram Moolenaar203d04d2013-06-06 21:36:40 +020059
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
Bram Moolenaar662db672011-03-22 14:05:35 +010061if &filetype == "rhelp"
62 " string enclosed in double quotes
63 syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
64 " string enclosed in single quotes
65 syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
66else
67 " string enclosed in double quotes
68 syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
69 " string enclosed in single quotes
70 syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
71endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
Bram Moolenaar483c5d82010-10-20 18:45:33 +020073syn match rStrError display contained "\\."
74
Bram Moolenaar662db672011-03-22 14:05:35 +010075
Bram Moolenaar483c5d82010-10-20 18:45:33 +020076" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
77syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
78
79" Hexadecimal and Octal digits
80syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
81
82" Unicode characters
83syn match rSpecial display contained "\\u\x\{1,4}"
84syn match rSpecial display contained "\\U\x\{1,8}"
85syn match rSpecial display contained "\\u{\x\{1,4}}"
86syn match rSpecial display contained "\\U{\x\{1,8}}"
87
Bram Moolenaar071d4272004-06-13 20:20:40 +000088" Statement
89syn keyword rStatement break next return
90syn keyword rConditional if else
91syn keyword rRepeat for in repeat while
92
Bram Moolenaar483c5d82010-10-20 18:45:33 +020093" Constant (not really)
Bram Moolenaar203d04d2013-06-06 21:36:40 +020094syn keyword rConstant T F LETTERS letters month.abb month.name pi
Bram Moolenaar483c5d82010-10-20 18:45:33 +020095syn keyword rConstant R.version.string
96
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010097syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_
Bram Moolenaar662db672011-03-22 14:05:35 +010098
99" Constants
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100syn keyword rConstant NULL
101syn keyword rBoolean FALSE TRUE
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100102syn keyword rNumber NA Inf NaN
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200104" integer
105syn match rInteger "\<\d\+L"
106syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
107syn match rInteger "\<\d\+[Ee]+\=\d\+L"
108
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200109" number with no fractional part or exponent
110syn match rNumber "\<\d\+\>"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100111" hexadecimal number
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200112syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
113
114" floating point number with integer and fractional parts and optional exponent
115syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
116" floating point number with no integer part and optional exponent
117syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
118" floating point number with no fractional part and optional exponent
119syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
120
Bram Moolenaar662db672011-03-22 14:05:35 +0100121" complex number
122syn match rComplex "\<\d\+i"
123syn match rComplex "\<\d\++\d\+i"
124syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
125syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
126syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
127syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
128
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100129syn match rAssign '='
Bram Moolenaar662db672011-03-22 14:05:35 +0100130syn match rOperator "&"
131syn match rOperator '-'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200132syn match rOperator '\*'
Bram Moolenaar662db672011-03-22 14:05:35 +0100133syn match rOperator '+'
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200134if &filetype != "rmd" && &filetype != "rrst"
135 syn match rOperator "[|!<>^~/:]"
136else
137 syn match rOperator "[|!<>^~`/:]"
138endif
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200139syn match rOperator "%\{2}\|%\S\{-}%"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100140syn match rOperator '\([!><]\)\@<=='
141syn match rOperator '=='
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200142syn match rOpError '\*\{3}'
Bram Moolenaar662db672011-03-22 14:05:35 +0100143syn match rOpError '//'
144syn match rOpError '&&&'
145syn match rOpError '|||'
146syn match rOpError '<<'
147syn match rOpError '>>'
148
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100149syn match rAssign "<\{1,2}-"
150syn match rAssign "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151
152" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200153syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154
155" Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100156if exists("g:r_syntax_folding")
157 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
158 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
159 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
160else
161 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
162 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
163 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
164endif
165
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200166syn match rError "[)\]}]"
167syn match rBraceError "[)}]" contained
168syn match rCurlyError "[)\]]" contained
169syn match rParenError "[\]}]" contained
170
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100171if !exists("g:R_hi_fun")
172 let g:R_hi_fun = 1
173endif
174if g:R_hi_fun
175 " Nvim-R:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100176 runtime R/functions.vim
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100177 " Vim-R-plugin:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100178 runtime r-plugin/functions.vim
179endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100180
181syn match rDollar display contained "\$"
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200182syn match rDollar display contained "@"
Bram Moolenaar662db672011-03-22 14:05:35 +0100183
184" List elements will not be highlighted as functions:
185syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200186syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar662db672011-03-22 14:05:35 +0100187
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200188" Functions that may add new objects
189syn keyword rPreProc library require attach detach source
190
Bram Moolenaar662db672011-03-22 14:05:35 +0100191if &filetype == "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200192 syn match rHelpIdent '\\method'
193 syn match rHelpIdent '\\S4method'
Bram Moolenaar662db672011-03-22 14:05:35 +0100194endif
195
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200196" Type
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100197syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198
Bram Moolenaar662db672011-03-22 14:05:35 +0100199" Name of object with spaces
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200200if &filetype != "rmd" && &filetype != "rrst"
201 syn region rNameWSpace start="`" end="`"
202endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100203
204if &filetype == "rhelp"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100205 syn match rhPreProc "^#ifdef.*"
206 syn match rhPreProc "^#endif.*"
Bram Moolenaar662db672011-03-22 14:05:35 +0100207 syn match rhSection "\\dontrun\>"
208endif
209
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100210if exists("r_syn_minlines")
211 exe "syn sync minlines=" . r_syn_minlines
212else
213 syn sync minlines=40
214endif
215
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216" Define the default highlighting.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100217hi def link rAssign Statement
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200218hi def link rBoolean Boolean
219hi def link rBraceError Error
220hi def link rComment Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200221hi def link rCommentTodo Todo
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200222hi def link rComplex Number
223hi def link rConditional Conditional
224hi def link rConstant Constant
225hi def link rCurlyError Error
226hi def link rDelimiter Delimiter
227hi def link rDollar SpecialChar
228hi def link rError Error
229hi def link rFloat Float
Bram Moolenaar662db672011-03-22 14:05:35 +0100230hi def link rFunction Function
231hi def link rHelpIdent Identifier
232hi def link rhPreProc PreProc
233hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200234hi def link rInteger Number
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100235hi def link rLstElmt Normal
Bram Moolenaar662db672011-03-22 14:05:35 +0100236hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200237hi def link rNumber Number
238hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100239hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200240hi def link rParenError Error
241hi def link rPreProc PreProc
242hi def link rRepeat Repeat
243hi def link rSpecial SpecialChar
244hi def link rStatement Statement
245hi def link rString String
246hi def link rStrError Error
247hi def link rType Type
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100248if g:r_hl_roxygen
249 hi def link rOKeyword Title
250 hi def link rOBlock Comment
251 hi def link rOTitle Title
252 hi def link rOCommentKey Comment
253 hi def link rOExamples SpecialComment
254endif
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +0100255
Bram Moolenaar071d4272004-06-13 20:20:40 +0000256
257let b:current_syntax="r"
258
259" vim: ts=8 sw=2