blob: 30a5b23f840108de8f4002a5db42e3a8d9ad60e6 [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 Moolenaare4a3bcf2016-08-26 19:52:37 +02008" Last Change: Thu Aug 25, 2016 08:52PM
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 Moolenaare4a3bcf2016-08-26 19:52:37 +020029syn 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 Moolenaar8feef4f2015-01-07 16:57:10 +0100177endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100178
179syn match rDollar display contained "\$"
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200180syn match rDollar display contained "@"
Bram Moolenaar662db672011-03-22 14:05:35 +0100181
182" List elements will not be highlighted as functions:
183syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200184syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar662db672011-03-22 14:05:35 +0100185
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200186" Functions that may add new objects
187syn keyword rPreProc library require attach detach source
188
Bram Moolenaar662db672011-03-22 14:05:35 +0100189if &filetype == "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200190 syn match rHelpIdent '\\method'
191 syn match rHelpIdent '\\S4method'
Bram Moolenaar662db672011-03-22 14:05:35 +0100192endif
193
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200194" Type
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100195syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000196
Bram Moolenaar662db672011-03-22 14:05:35 +0100197" Name of object with spaces
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200198if &filetype != "rmd" && &filetype != "rrst"
199 syn region rNameWSpace start="`" end="`"
200endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100201
202if &filetype == "rhelp"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100203 syn match rhPreProc "^#ifdef.*"
204 syn match rhPreProc "^#endif.*"
Bram Moolenaar662db672011-03-22 14:05:35 +0100205 syn match rhSection "\\dontrun\>"
206endif
207
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100208if exists("r_syn_minlines")
209 exe "syn sync minlines=" . r_syn_minlines
210else
211 syn sync minlines=40
212endif
213
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214" Define the default highlighting.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100215hi def link rAssign Statement
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200216hi def link rBoolean Boolean
217hi def link rBraceError Error
218hi def link rComment Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200219hi def link rCommentTodo Todo
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200220hi def link rComplex Number
221hi def link rConditional Conditional
222hi def link rConstant Constant
223hi def link rCurlyError Error
224hi def link rDelimiter Delimiter
225hi def link rDollar SpecialChar
226hi def link rError Error
227hi def link rFloat Float
Bram Moolenaar662db672011-03-22 14:05:35 +0100228hi def link rFunction Function
229hi def link rHelpIdent Identifier
230hi def link rhPreProc PreProc
231hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200232hi def link rInteger Number
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100233hi def link rLstElmt Normal
Bram Moolenaar662db672011-03-22 14:05:35 +0100234hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200235hi def link rNumber Number
236hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100237hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200238hi def link rParenError Error
239hi def link rPreProc PreProc
240hi def link rRepeat Repeat
241hi def link rSpecial SpecialChar
242hi def link rStatement Statement
243hi def link rString String
244hi def link rStrError Error
245hi def link rType Type
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100246if g:r_hl_roxygen
247 hi def link rOKeyword Title
248 hi def link rOBlock Comment
249 hi def link rOTitle Title
250 hi def link rOCommentKey Comment
251 hi def link rOExamples SpecialComment
252endif
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +0100253
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254
255let b:current_syntax="r"
256
257" vim: ts=8 sw=2