blob: e48b6686cbeeb8f45ec7a1fca586aa4dc2f0b822 [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
8" Last Change: Wed Oct 21, 2015 06:33AM
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:
15" syntax folding can be turned on by
16"
17" let r_syntax_folding = 1
18"
Bram Moolenaar483c5d82010-10-20 18:45:33 +020019" Some lines of code were borrowed from Zhuojun Chen.
Bram Moolenaar4770d092006-01-12 23:22:24 +000020
Bram Moolenaar483c5d82010-10-20 18:45:33 +020021if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000022 finish
23endif
24
Bram Moolenaar483c5d82010-10-20 18:45:33 +020025setlocal iskeyword=@,48-57,_,.
Bram Moolenaar071d4272004-06-13 20:20:40 +000026
Bram Moolenaar662db672011-03-22 14:05:35 +010027if exists("g:r_syntax_folding")
28 setlocal foldmethod=syntax
29endif
30
Bram Moolenaar071d4272004-06-13 20:20:40 +000031syn case match
32
33" Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +020034syn match rCommentTodo contained "\(BUG\|FIXME\|NOTE\|TODO\):"
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +010035syn match rComment contains=@Spell,rCommentTodo,rOBlock "#.*"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020036
37" Roxygen
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +010038syn region rOBlock start="^\s*\n#\{1,2}' " start="\%^#\{1,2}' " end="^\(#\{1,2}'\)\@!" contains=rOTitle,rOKeyword,rOExamples,@Spell keepend
39syn region rOTitle start="^\s*\n#\{1,2}' " start="\%^#\{1,2}' " end="^\(#\{1,2}'\s*$\)\@=" contained contains=rOCommentKey
40syn match rOCommentKey "#\{1,2}'" containedin=rOTitle contained
41
42syn region rOExamples start="^#\{1,2}' @examples.*"rs=e+1,hs=e+1 end="^\(#\{1,2}' @.*\)\@=" end="^\(#\{1,2}'\)\@!" contained contains=rOKeyword
43
44syn match rOKeyword contained "@\(param\|return\|name\|rdname\|examples\|example\|include\|docType\)"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020045syn match rOKeyword contained "@\(S3method\|TODO\|aliases\|alias\|assignee\|author\|callGraphDepth\|callGraph\)"
46syn match rOKeyword contained "@\(callGraphPrimitives\|concept\|exportClass\|exportMethod\|exportPattern\|export\|formals\)"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010047syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\|useDynLib\)"
Bram Moolenaardb6ea062014-07-10 22:01:47 +020048syn match rOKeyword contained "@\(method\|noRd\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)"
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +010049syn match rOKeyword contained "@\(family\|template\|templateVar\|description\|details\|inheritParams\|field\)"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020050
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
Bram Moolenaar662db672011-03-22 14:05:35 +010052if &filetype == "rhelp"
53 " string enclosed in double quotes
54 syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
55 " string enclosed in single quotes
56 syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
57else
58 " string enclosed in double quotes
59 syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
60 " string enclosed in single quotes
61 syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
62endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
Bram Moolenaar483c5d82010-10-20 18:45:33 +020064syn match rStrError display contained "\\."
65
Bram Moolenaar662db672011-03-22 14:05:35 +010066
Bram Moolenaar483c5d82010-10-20 18:45:33 +020067" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
68syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
69
70" Hexadecimal and Octal digits
71syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
72
73" Unicode characters
74syn match rSpecial display contained "\\u\x\{1,4}"
75syn match rSpecial display contained "\\U\x\{1,8}"
76syn match rSpecial display contained "\\u{\x\{1,4}}"
77syn match rSpecial display contained "\\U{\x\{1,8}}"
78
Bram Moolenaar071d4272004-06-13 20:20:40 +000079" Statement
80syn keyword rStatement break next return
81syn keyword rConditional if else
82syn keyword rRepeat for in repeat while
83
Bram Moolenaar483c5d82010-10-20 18:45:33 +020084" Constant (not really)
Bram Moolenaar203d04d2013-06-06 21:36:40 +020085syn keyword rConstant T F LETTERS letters month.abb month.name pi
Bram Moolenaar483c5d82010-10-20 18:45:33 +020086syn keyword rConstant R.version.string
87
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010088syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_
Bram Moolenaar662db672011-03-22 14:05:35 +010089
90" Constants
Bram Moolenaar071d4272004-06-13 20:20:40 +000091syn keyword rConstant NULL
92syn keyword rBoolean FALSE TRUE
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010093syn keyword rNumber NA Inf NaN
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
Bram Moolenaar483c5d82010-10-20 18:45:33 +020095" integer
96syn match rInteger "\<\d\+L"
97syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
98syn match rInteger "\<\d\+[Ee]+\=\d\+L"
99
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200100" number with no fractional part or exponent
101syn match rNumber "\<\d\+\>"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100102" hexadecimal number
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200103syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
104
105" floating point number with integer and fractional parts and optional exponent
106syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
107" floating point number with no integer part and optional exponent
108syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
109" floating point number with no fractional part and optional exponent
110syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
111
Bram Moolenaar662db672011-03-22 14:05:35 +0100112" complex number
113syn match rComplex "\<\d\+i"
114syn match rComplex "\<\d\++\d\+i"
115syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
116syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
117syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
118syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
119
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100120syn match rAssign '='
Bram Moolenaar662db672011-03-22 14:05:35 +0100121syn match rOperator "&"
122syn match rOperator '-'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200123syn match rOperator '\*'
Bram Moolenaar662db672011-03-22 14:05:35 +0100124syn match rOperator '+'
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200125if &filetype != "rmd" && &filetype != "rrst"
126 syn match rOperator "[|!<>^~/:]"
127else
128 syn match rOperator "[|!<>^~`/:]"
129endif
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200130syn match rOperator "%\{2}\|%\S\{-}%"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100131syn match rOperator '\([!><]\)\@<=='
132syn match rOperator '=='
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200133syn match rOpError '\*\{3}'
Bram Moolenaar662db672011-03-22 14:05:35 +0100134syn match rOpError '//'
135syn match rOpError '&&&'
136syn match rOpError '|||'
137syn match rOpError '<<'
138syn match rOpError '>>'
139
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100140syn match rAssign "<\{1,2}-"
141syn match rAssign "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
143" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200144syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000145
146" Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100147if exists("g:r_syntax_folding")
148 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
149 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
150 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
151else
152 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
153 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
154 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
155endif
156
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200157syn match rError "[)\]}]"
158syn match rBraceError "[)}]" contained
159syn match rCurlyError "[)\]]" contained
160syn match rParenError "[\]}]" contained
161
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100162" Source list of R functions produced by a filetype plugin (if installed)
163if has("nvim")
164 " Nvim-R
165 runtime R/functions.vim
166else
167 " Vim-R-plugin
168 runtime r-plugin/functions.vim
169endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100170
171syn match rDollar display contained "\$"
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200172syn match rDollar display contained "@"
Bram Moolenaar662db672011-03-22 14:05:35 +0100173
174" List elements will not be highlighted as functions:
175syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200176syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar662db672011-03-22 14:05:35 +0100177
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200178" Functions that may add new objects
179syn keyword rPreProc library require attach detach source
180
Bram Moolenaar662db672011-03-22 14:05:35 +0100181if &filetype == "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200182 syn match rHelpIdent '\\method'
183 syn match rHelpIdent '\\S4method'
Bram Moolenaar662db672011-03-22 14:05:35 +0100184endif
185
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200186" Type
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100187syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188
Bram Moolenaar662db672011-03-22 14:05:35 +0100189" Name of object with spaces
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200190if &filetype != "rmd" && &filetype != "rrst"
191 syn region rNameWSpace start="`" end="`"
192endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100193
194if &filetype == "rhelp"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100195 syn match rhPreProc "^#ifdef.*"
196 syn match rhPreProc "^#endif.*"
Bram Moolenaar662db672011-03-22 14:05:35 +0100197 syn match rhSection "\\dontrun\>"
198endif
199
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100200if exists("r_syn_minlines")
201 exe "syn sync minlines=" . r_syn_minlines
202else
203 syn sync minlines=40
204endif
205
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206" Define the default highlighting.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100207hi def link rAssign Statement
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200208hi def link rBoolean Boolean
209hi def link rBraceError Error
210hi def link rComment Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200211hi def link rCommentTodo Todo
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200212hi def link rComplex Number
213hi def link rConditional Conditional
214hi def link rConstant Constant
215hi def link rCurlyError Error
216hi def link rDelimiter Delimiter
217hi def link rDollar SpecialChar
218hi def link rError Error
219hi def link rFloat Float
Bram Moolenaar662db672011-03-22 14:05:35 +0100220hi def link rFunction Function
221hi def link rHelpIdent Identifier
222hi def link rhPreProc PreProc
223hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200224hi def link rInteger Number
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100225hi def link rLstElmt Normal
Bram Moolenaar662db672011-03-22 14:05:35 +0100226hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200227hi def link rNumber Number
228hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100229hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200230hi def link rParenError Error
231hi def link rPreProc PreProc
232hi def link rRepeat Repeat
233hi def link rSpecial SpecialChar
234hi def link rStatement Statement
235hi def link rString String
236hi def link rStrError Error
237hi def link rType Type
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200238hi def link rOKeyword Title
Bram Moolenaar2c5e8e82015-12-05 20:59:21 +0100239hi def link rOBlock Comment
240hi def link rOTitle Title
241hi def link rOCommentKey Comment
242hi def link rOExamples SpecialComment
243
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244
245let b:current_syntax="r"
246
247" vim: ts=8 sw=2