blob: 9677823fb12510033c6c2b8d0ae5a1702a377535 [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 Moolenaar8feef4f2015-01-07 16:57:10 +01006" Last Change: Wed Dec 31, 2014 12:36AM
Bram Moolenaar483c5d82010-10-20 18:45:33 +02007" Filenames: *.R *.r *.Rhistory *.Rt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008"
9" NOTE: The highlighting of R functions is defined in
10" runtime files created by a filetype plugin, if installed.
Bram Moolenaar483c5d82010-10-20 18:45:33 +020011"
Bram Moolenaar662db672011-03-22 14:05:35 +010012" CONFIGURATION:
13" syntax folding can be turned on by
14"
15" let r_syntax_folding = 1
16"
Bram Moolenaar483c5d82010-10-20 18:45:33 +020017" Some lines of code were borrowed from Zhuojun Chen.
Bram Moolenaar4770d092006-01-12 23:22:24 +000018
Bram Moolenaar483c5d82010-10-20 18:45:33 +020019if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000020 finish
21endif
22
Bram Moolenaar483c5d82010-10-20 18:45:33 +020023setlocal iskeyword=@,48-57,_,.
Bram Moolenaar071d4272004-06-13 20:20:40 +000024
Bram Moolenaar662db672011-03-22 14:05:35 +010025if exists("g:r_syntax_folding")
26 setlocal foldmethod=syntax
27endif
28
Bram Moolenaar071d4272004-06-13 20:20:40 +000029syn case match
30
31" Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +020032syn match rCommentTodo contained "\(BUG\|FIXME\|NOTE\|TODO\):"
33syn match rComment contains=@Spell,rCommentTodo "#.*"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020034
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\)"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010039syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\|useDynLib\)"
Bram Moolenaardb6ea062014-07-10 22:01:47 +020040syn match rOKeyword contained "@\(method\|noRd\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010041syn match rOKeyword contained "@\(family\|template\|templateVar\|description\|details\|inheritParams\)"
Bram Moolenaar203d04d2013-06-06 21:36:40 +020042syn match rOComment contains=@Spell,rOKeyword "#'.*"
43
Bram Moolenaar071d4272004-06-13 20:20:40 +000044
Bram Moolenaar662db672011-03-22 14:05:35 +010045if &filetype == "rhelp"
46 " string enclosed in double quotes
47 syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
48 " string enclosed in single quotes
49 syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
50else
51 " string enclosed in double quotes
52 syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
53 " string enclosed in single quotes
54 syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
55endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000056
Bram Moolenaar483c5d82010-10-20 18:45:33 +020057syn match rStrError display contained "\\."
58
Bram Moolenaar662db672011-03-22 14:05:35 +010059
Bram Moolenaar483c5d82010-10-20 18:45:33 +020060" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
61syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
62
63" Hexadecimal and Octal digits
64syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
65
66" Unicode characters
67syn match rSpecial display contained "\\u\x\{1,4}"
68syn match rSpecial display contained "\\U\x\{1,8}"
69syn match rSpecial display contained "\\u{\x\{1,4}}"
70syn match rSpecial display contained "\\U{\x\{1,8}}"
71
Bram Moolenaar071d4272004-06-13 20:20:40 +000072" Statement
73syn keyword rStatement break next return
74syn keyword rConditional if else
75syn keyword rRepeat for in repeat while
76
Bram Moolenaar483c5d82010-10-20 18:45:33 +020077" Constant (not really)
Bram Moolenaar203d04d2013-06-06 21:36:40 +020078syn keyword rConstant T F LETTERS letters month.abb month.name pi
Bram Moolenaar483c5d82010-10-20 18:45:33 +020079syn keyword rConstant R.version.string
80
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010081syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_
Bram Moolenaar662db672011-03-22 14:05:35 +010082
83" Constants
Bram Moolenaar071d4272004-06-13 20:20:40 +000084syn keyword rConstant NULL
85syn keyword rBoolean FALSE TRUE
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010086syn keyword rNumber NA Inf NaN
Bram Moolenaar071d4272004-06-13 20:20:40 +000087
Bram Moolenaar483c5d82010-10-20 18:45:33 +020088" integer
89syn match rInteger "\<\d\+L"
90syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
91syn match rInteger "\<\d\+[Ee]+\=\d\+L"
92
Bram Moolenaar483c5d82010-10-20 18:45:33 +020093" number with no fractional part or exponent
94syn match rNumber "\<\d\+\>"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010095" hexadecimal number
Bram Moolenaar483c5d82010-10-20 18:45:33 +020096syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
97
98" floating point number with integer and fractional parts and optional exponent
99syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
100" floating point number with no integer part and optional exponent
101syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
102" floating point number with no fractional part and optional exponent
103syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
104
Bram Moolenaar662db672011-03-22 14:05:35 +0100105" complex number
106syn match rComplex "\<\d\+i"
107syn match rComplex "\<\d\++\d\+i"
108syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
109syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
110syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
111syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
112
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100113syn match rAssign '='
Bram Moolenaar662db672011-03-22 14:05:35 +0100114syn 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 '+'
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200118if &filetype != "rmd" && &filetype != "rrst"
119 syn match rOperator "[|!<>^~/:]"
120else
121 syn match rOperator "[|!<>^~`/:]"
122endif
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200123syn match rOperator "%\{2}\|%\S\{-}%"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100124syn match rOperator '\([!><]\)\@<=='
125syn match rOperator '=='
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200126syn match rOpError '\*\{3}'
Bram Moolenaar662db672011-03-22 14:05:35 +0100127syn match rOpError '//'
128syn match rOpError '&&&'
129syn match rOpError '|||'
130syn match rOpError '<<'
131syn match rOpError '>>'
132
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100133syn match rAssign "<\{1,2}-"
134syn match rAssign "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135
136" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200137syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138
139" Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100140if exists("g:r_syntax_folding")
141 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
142 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
143 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
144else
145 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
146 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
147 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
148endif
149
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200150syn match rError "[)\]}]"
151syn match rBraceError "[)}]" contained
152syn match rCurlyError "[)\]]" contained
153syn match rParenError "[\]}]" contained
154
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100155" Source list of R functions produced by a filetype plugin (if installed)
156if has("nvim")
157 " Nvim-R
158 runtime R/functions.vim
159else
160 " Vim-R-plugin
161 runtime r-plugin/functions.vim
162endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100163
164syn match rDollar display contained "\$"
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200165syn match rDollar display contained "@"
Bram Moolenaar662db672011-03-22 14:05:35 +0100166
167" List elements will not be highlighted as functions:
168syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200169syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
Bram Moolenaar662db672011-03-22 14:05:35 +0100170
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200171" Functions that may add new objects
172syn keyword rPreProc library require attach detach source
173
Bram Moolenaar662db672011-03-22 14:05:35 +0100174if &filetype == "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200175 syn match rHelpIdent '\\method'
176 syn match rHelpIdent '\\S4method'
Bram Moolenaar662db672011-03-22 14:05:35 +0100177endif
178
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200179" Type
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100180syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000181
Bram Moolenaar662db672011-03-22 14:05:35 +0100182" Name of object with spaces
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200183if &filetype != "rmd" && &filetype != "rrst"
184 syn region rNameWSpace start="`" end="`"
185endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100186
187if &filetype == "rhelp"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100188 syn match rhPreProc "^#ifdef.*"
189 syn match rhPreProc "^#endif.*"
Bram Moolenaar662db672011-03-22 14:05:35 +0100190 syn match rhSection "\\dontrun\>"
191endif
192
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100193if exists("r_syn_minlines")
194 exe "syn sync minlines=" . r_syn_minlines
195else
196 syn sync minlines=40
197endif
198
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199" Define the default highlighting.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100200hi def link rAssign Statement
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200201hi def link rBoolean Boolean
202hi def link rBraceError Error
203hi def link rComment Comment
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200204hi def link rCommentTodo Todo
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200205hi def link rOComment Comment
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200206hi def link rComplex Number
207hi def link rConditional Conditional
208hi def link rConstant Constant
209hi def link rCurlyError Error
210hi def link rDelimiter Delimiter
211hi def link rDollar SpecialChar
212hi def link rError Error
213hi def link rFloat Float
Bram Moolenaar662db672011-03-22 14:05:35 +0100214hi def link rFunction Function
215hi def link rHelpIdent Identifier
216hi def link rhPreProc PreProc
217hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200218hi def link rInteger Number
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100219hi def link rLstElmt Normal
Bram Moolenaar662db672011-03-22 14:05:35 +0100220hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200221hi def link rNumber Number
222hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100223hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200224hi def link rParenError Error
225hi def link rPreProc PreProc
226hi def link rRepeat Repeat
227hi def link rSpecial SpecialChar
228hi def link rStatement Statement
229hi def link rString String
230hi def link rStrError Error
231hi def link rType Type
Bram Moolenaar203d04d2013-06-06 21:36:40 +0200232hi def link rOKeyword Title
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233
234let b:current_syntax="r"
235
236" vim: ts=8 sw=2