blob: 85a6eaa2aed2da9b05563c8fe870bb24c3c02eb5 [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 Moolenaardb6ea062014-07-10 22:01:47 +02006" Last Change: Wed Jul 09, 2014 10:29PM
Bram Moolenaar483c5d82010-10-20 18:45:33 +02007" 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"
Bram Moolenaar662db672011-03-22 14:05:35 +010013" CONFIGURATION:
14" syntax folding can be turned on by
15"
16" let r_syntax_folding = 1
17"
Bram Moolenaar483c5d82010-10-20 18:45:33 +020018" Some lines of code were borrowed from Zhuojun Chen.
Bram Moolenaar4770d092006-01-12 23:22:24 +000019
Bram Moolenaar483c5d82010-10-20 18:45:33 +020020if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000021 finish
22endif
23
Bram Moolenaar483c5d82010-10-20 18:45:33 +020024setlocal iskeyword=@,48-57,_,.
Bram Moolenaar071d4272004-06-13 20:20:40 +000025
Bram Moolenaar662db672011-03-22 14:05:35 +010026if exists("g:r_syntax_folding")
27 setlocal foldmethod=syntax
28endif
29
Bram Moolenaar071d4272004-06-13 20:20:40 +000030syn case match
31
32" Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +020033syn match rCommentTodo contained "\(BUG\|FIXME\|NOTE\|TODO\):"
34syn match rComment contains=@Spell,rCommentTodo "#.*"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020035
36" Roxygen
37syn match rOKeyword contained "@\(param\|return\|name\|rdname\|examples\|include\|docType\)"
38syn match rOKeyword contained "@\(S3method\|TODO\|aliases\|alias\|assignee\|author\|callGraphDepth\|callGraph\)"
39syn match rOKeyword contained "@\(callGraphPrimitives\|concept\|exportClass\|exportMethod\|exportPattern\|export\|formals\)"
40syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\)"
Bram Moolenaardb6ea062014-07-10 22:01:47 +020041syn match rOKeyword contained "@\(method\|noRd\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)"
42syn match rOKeyword contained "@\(family\|template\|templateVar\|description\|details\|inheritsParams\)"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020043syn match rOComment contains=@Spell,rOKeyword "#'.*"
44
Bram Moolenaar071d4272004-06-13 20:20:40 +000045
Bram Moolenaar662db672011-03-22 14:05:35 +010046if &filetype == "rhelp"
47 " string enclosed in double quotes
48 syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
49 " string enclosed in single quotes
50 syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
51else
52 " string enclosed in double quotes
53 syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
54 " string enclosed in single quotes
55 syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
56endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
Bram Moolenaar483c5d82010-10-20 18:45:33 +020058syn match rStrError display contained "\\."
59
Bram Moolenaar662db672011-03-22 14:05:35 +010060
Bram Moolenaar483c5d82010-10-20 18:45:33 +020061" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
62syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
63
64" Hexadecimal and Octal digits
65syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
66
67" Unicode characters
68syn match rSpecial display contained "\\u\x\{1,4}"
69syn match rSpecial display contained "\\U\x\{1,8}"
70syn match rSpecial display contained "\\u{\x\{1,4}}"
71syn match rSpecial display contained "\\U{\x\{1,8}}"
72
Bram Moolenaar071d4272004-06-13 20:20:40 +000073" Statement
74syn keyword rStatement break next return
75syn keyword rConditional if else
76syn keyword rRepeat for in repeat while
77
Bram Moolenaar483c5d82010-10-20 18:45:33 +020078" Constant (not really)
Bram Moolenaar203d04d2013-06-06 21:36:40 +020079syn keyword rConstant T F LETTERS letters month.abb month.name pi
Bram Moolenaar483c5d82010-10-20 18:45:33 +020080syn keyword rConstant R.version.string
81
Bram Moolenaar662db672011-03-22 14:05:35 +010082syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_
83
84" Constants
Bram Moolenaar071d4272004-06-13 20:20:40 +000085syn keyword rConstant NULL
86syn keyword rBoolean FALSE TRUE
Bram Moolenaar662db672011-03-22 14:05:35 +010087syn keyword rNumber NA Inf NaN
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
Bram Moolenaar483c5d82010-10-20 18:45:33 +020089" integer
90syn match rInteger "\<\d\+L"
91syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
92syn match rInteger "\<\d\+[Ee]+\=\d\+L"
93
Bram Moolenaar483c5d82010-10-20 18:45:33 +020094" number with no fractional part or exponent
95syn match rNumber "\<\d\+\>"
96" hexadecimal number
97syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
98
99" floating point number with integer and fractional parts and optional exponent
100syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
101" floating point number with no integer part and optional exponent
102syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
103" floating point number with no fractional part and optional exponent
104syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
105
Bram Moolenaar662db672011-03-22 14:05:35 +0100106" complex number
107syn match rComplex "\<\d\+i"
108syn match rComplex "\<\d\++\d\+i"
109syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
110syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
111syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
112syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
113
114syn match rOperator "&"
115syn match rOperator '-'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200116syn match rOperator '\*'
Bram Moolenaar662db672011-03-22 14:05:35 +0100117syn match rOperator '+'
118syn match rOperator '='
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200119if &filetype != "rmd" && &filetype != "rrst"
120 syn match rOperator "[|!<>^~/:]"
121else
122 syn match rOperator "[|!<>^~`/:]"
123endif
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200124syn match rOperator "%\{2}\|%\S\{-}%"
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200125syn match rOpError '\*\{3}'
Bram Moolenaar662db672011-03-22 14:05:35 +0100126syn match rOpError '//'
127syn match rOpError '&&&'
128syn match rOpError '|||'
129syn match rOpError '<<'
130syn match rOpError '>>'
131
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200132syn match rArrow "<\{1,2}-"
133syn match rArrow "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134
135" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200136syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137
138" Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100139if exists("g:r_syntax_folding")
140 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
141 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
142 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
143else
144 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
145 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
146 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
147endif
148
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200149syn match rError "[)\]}]"
150syn match rBraceError "[)}]" contained
151syn match rCurlyError "[)\]]" contained
152syn match rParenError "[\]}]" contained
153
Bram Moolenaar662db672011-03-22 14:05:35 +0100154" Source list of R functions. The list is produced by the Vim-R-plugin
155" http://www.vim.org/scripts/script.php?script_id=2628
156runtime r-plugin/functions.vim
157
158syn match rDollar display contained "\$"
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200159syn match rDollar display contained "@"
Bram Moolenaar662db672011-03-22 14:05:35 +0100160
161" List elements will not be highlighted as functions:
162syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200163syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar662db672011-03-22 14:05:35 +0100164
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200165" Functions that may add new objects
166syn keyword rPreProc library require attach detach source
167
Bram Moolenaar662db672011-03-22 14:05:35 +0100168if &filetype == "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200169 syn match rHelpIdent '\\method'
170 syn match rHelpIdent '\\S4method'
Bram Moolenaar662db672011-03-22 14:05:35 +0100171endif
172
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200173" Type
174syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175
Bram Moolenaar662db672011-03-22 14:05:35 +0100176" Name of object with spaces
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200177if &filetype != "rmd" && &filetype != "rrst"
178 syn region rNameWSpace start="`" end="`"
179endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100180
181if &filetype == "rhelp"
182 syn match rhPreProc "^#ifdef.*"
183 syn match rhPreProc "^#endif.*"
184 syn match rhSection "\\dontrun\>"
185endif
186
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187" Define the default highlighting.
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200188hi def link rArrow Statement
189hi def link rBoolean Boolean
190hi def link rBraceError Error
191hi def link rComment Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200192hi def link rCommentTodo Todo
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200193hi def link rOComment Comment
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200194hi def link rComplex Number
195hi def link rConditional Conditional
196hi def link rConstant Constant
197hi def link rCurlyError Error
198hi def link rDelimiter Delimiter
199hi def link rDollar SpecialChar
200hi def link rError Error
201hi def link rFloat Float
Bram Moolenaar662db672011-03-22 14:05:35 +0100202hi def link rFunction Function
203hi def link rHelpIdent Identifier
204hi def link rhPreProc PreProc
205hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200206hi def link rInteger Number
Bram Moolenaar662db672011-03-22 14:05:35 +0100207hi def link rLstElmt Normal
208hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200209hi def link rNumber Number
210hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100211hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200212hi def link rParenError Error
213hi def link rPreProc PreProc
214hi def link rRepeat Repeat
215hi def link rSpecial SpecialChar
216hi def link rStatement Statement
217hi def link rString String
218hi def link rStrError Error
219hi def link rType Type
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200220hi def link rOKeyword Title
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221
222let b:current_syntax="r"
223
224" vim: ts=8 sw=2