blob: 5e76e7af7f92ecf521b1a9678eb4f0df07f25434 [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 Moolenaar203d04d2013-06-06 21:36:40 +02006" Last Change: Sun May 19, 2013 05:59PM
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 Moolenaar203d04d2013-06-06 21:36:40 +020033syn match rComment contains=@Spell "#.*"
34
35" Roxygen
36syn match rOKeyword contained "@\(param\|return\|name\|rdname\|examples\|include\|docType\)"
37syn match rOKeyword contained "@\(S3method\|TODO\|aliases\|alias\|assignee\|author\|callGraphDepth\|callGraph\)"
38syn match rOKeyword contained "@\(callGraphPrimitives\|concept\|exportClass\|exportMethod\|exportPattern\|export\|formals\)"
39syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\)"
40syn match rOKeyword contained "@\(method\|nord\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)"
41syn match rOComment contains=@Spell,rOKeyword "#'.*"
42
Bram Moolenaar071d4272004-06-13 20:20:40 +000043
Bram Moolenaar662db672011-03-22 14:05:35 +010044if &filetype == "rhelp"
45 " string enclosed in double quotes
46 syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
47 " string enclosed in single quotes
48 syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
49else
50 " string enclosed in double quotes
51 syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
52 " string enclosed in single quotes
53 syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
54endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
Bram Moolenaar483c5d82010-10-20 18:45:33 +020056syn match rStrError display contained "\\."
57
Bram Moolenaar662db672011-03-22 14:05:35 +010058
Bram Moolenaar483c5d82010-10-20 18:45:33 +020059" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
60syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
61
62" Hexadecimal and Octal digits
63syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
64
65" Unicode characters
66syn match rSpecial display contained "\\u\x\{1,4}"
67syn match rSpecial display contained "\\U\x\{1,8}"
68syn match rSpecial display contained "\\u{\x\{1,4}}"
69syn match rSpecial display contained "\\U{\x\{1,8}}"
70
Bram Moolenaar071d4272004-06-13 20:20:40 +000071" Statement
72syn keyword rStatement break next return
73syn keyword rConditional if else
74syn keyword rRepeat for in repeat while
75
Bram Moolenaar483c5d82010-10-20 18:45:33 +020076" Constant (not really)
Bram Moolenaar203d04d2013-06-06 21:36:40 +020077syn keyword rConstant T F LETTERS letters month.abb month.name pi
Bram Moolenaar483c5d82010-10-20 18:45:33 +020078syn keyword rConstant R.version.string
79
Bram Moolenaar662db672011-03-22 14:05:35 +010080syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_
81
82" Constants
Bram Moolenaar071d4272004-06-13 20:20:40 +000083syn keyword rConstant NULL
84syn keyword rBoolean FALSE TRUE
Bram Moolenaar662db672011-03-22 14:05:35 +010085syn keyword rNumber NA Inf NaN
Bram Moolenaar071d4272004-06-13 20:20:40 +000086
Bram Moolenaar483c5d82010-10-20 18:45:33 +020087" integer
88syn match rInteger "\<\d\+L"
89syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
90syn match rInteger "\<\d\+[Ee]+\=\d\+L"
91
Bram Moolenaar483c5d82010-10-20 18:45:33 +020092" number with no fractional part or exponent
93syn match rNumber "\<\d\+\>"
94" hexadecimal number
95syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
96
97" floating point number with integer and fractional parts and optional exponent
98syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
99" floating point number with no integer part and optional exponent
100syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
101" floating point number with no fractional part and optional exponent
102syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
103
Bram Moolenaar662db672011-03-22 14:05:35 +0100104" complex number
105syn match rComplex "\<\d\+i"
106syn match rComplex "\<\d\++\d\+i"
107syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
108syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
109syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
110syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
111
112syn match rOperator "&"
113syn match rOperator '-'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200114syn match rOperator '\*'
Bram Moolenaar662db672011-03-22 14:05:35 +0100115syn match rOperator '+'
116syn match rOperator '='
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200117if &filetype != "rmd" && &filetype != "rrst"
118 syn match rOperator "[|!<>^~/:]"
119else
120 syn match rOperator "[|!<>^~`/:]"
121endif
122syn match rOperator "%\{2}\|%\S*%"
123syn match rOpError '\*\{3}'
Bram Moolenaar662db672011-03-22 14:05:35 +0100124syn match rOpError '//'
125syn match rOpError '&&&'
126syn match rOpError '|||'
127syn match rOpError '<<'
128syn match rOpError '>>'
129
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200130syn match rArrow "<\{1,2}-"
131syn match rArrow "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132
133" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200134syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135
136" Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100137if exists("g:r_syntax_folding")
138 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
139 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
140 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
141else
142 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
143 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
144 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
145endif
146
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200147syn match rError "[)\]}]"
148syn match rBraceError "[)}]" contained
149syn match rCurlyError "[)\]]" contained
150syn match rParenError "[\]}]" contained
151
Bram Moolenaar662db672011-03-22 14:05:35 +0100152" Source list of R functions. The list is produced by the Vim-R-plugin
153" http://www.vim.org/scripts/script.php?script_id=2628
154runtime r-plugin/functions.vim
155
156syn match rDollar display contained "\$"
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200157syn match rDollar display contained "@"
Bram Moolenaar662db672011-03-22 14:05:35 +0100158
159" List elements will not be highlighted as functions:
160syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200161syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar662db672011-03-22 14:05:35 +0100162
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200163" Functions that may add new objects
164syn keyword rPreProc library require attach detach source
165
Bram Moolenaar662db672011-03-22 14:05:35 +0100166if &filetype == "rhelp"
167 syn match rHelpIdent '\\method'
168 syn match rHelpIdent '\\S4method'
169endif
170
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200171" Type
172syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000173
Bram Moolenaar662db672011-03-22 14:05:35 +0100174" Name of object with spaces
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200175if &filetype != "rmd" && &filetype != "rrst"
176 syn region rNameWSpace start="`" end="`"
177endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100178
179if &filetype == "rhelp"
180 syn match rhPreProc "^#ifdef.*"
181 syn match rhPreProc "^#endif.*"
182 syn match rhSection "\\dontrun\>"
183endif
184
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185" Define the default highlighting.
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200186hi def link rArrow Statement
187hi def link rBoolean Boolean
188hi def link rBraceError Error
189hi def link rComment Comment
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200190hi def link rOComment Comment
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200191hi def link rComplex Number
192hi def link rConditional Conditional
193hi def link rConstant Constant
194hi def link rCurlyError Error
195hi def link rDelimiter Delimiter
196hi def link rDollar SpecialChar
197hi def link rError Error
198hi def link rFloat Float
Bram Moolenaar662db672011-03-22 14:05:35 +0100199hi def link rFunction Function
200hi def link rHelpIdent Identifier
201hi def link rhPreProc PreProc
202hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200203hi def link rInteger Number
Bram Moolenaar662db672011-03-22 14:05:35 +0100204hi def link rLstElmt Normal
205hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200206hi def link rNumber Number
207hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100208hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200209hi def link rParenError Error
210hi def link rPreProc PreProc
211hi def link rRepeat Repeat
212hi def link rSpecial SpecialChar
213hi def link rStatement Statement
214hi def link rString String
215hi def link rStrError Error
216hi def link rType Type
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200217hi def link rOKeyword Title
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218
219let b:current_syntax="r"
220
221" vim: ts=8 sw=2