xref: /vim-8.2.3635/runtime/syntax/r.vim (revision 36e294c0)
1" Vim syntax file
2" Language:	      R (GNU S)
3" Maintainer:	      Jakson Aquino <[email protected]>
4" Former Maintainers: Vaidotas Zemlys <[email protected]>
5" 		      Tom Payne <[email protected]>
6" Contributor:        Johannes Ranke <[email protected]>
7" Homepage:           https://github.com/jalvesaq/R-Vim-runtime
8" Last Change:	      Wed Oct 21, 2015  06:33AM
9" Filenames:	      *.R *.r *.Rhistory *.Rt
10"
11" NOTE: The highlighting of R functions is defined in
12" runtime files created by a filetype plugin, if installed.
13"
14" CONFIGURATION:
15"   syntax folding can be turned on by
16"
17"      let r_syntax_folding = 1
18"
19" Some lines of code were borrowed from Zhuojun Chen.
20
21if exists("b:current_syntax")
22  finish
23endif
24
25setlocal iskeyword=@,48-57,_,.
26
27if exists("g:r_syntax_folding")
28  setlocal foldmethod=syntax
29endif
30
31syn case match
32
33" Comment
34syn match rCommentTodo contained "\(BUG\|FIXME\|NOTE\|TODO\):"
35syn match rComment contains=@Spell,rCommentTodo,rOBlock "#.*"
36
37" Roxygen
38syn 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\)"
45syn match rOKeyword contained "@\(S3method\|TODO\|aliases\|alias\|assignee\|author\|callGraphDepth\|callGraph\)"
46syn match rOKeyword contained "@\(callGraphPrimitives\|concept\|exportClass\|exportMethod\|exportPattern\|export\|formals\)"
47syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\|useDynLib\)"
48syn match rOKeyword contained "@\(method\|noRd\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)"
49syn match rOKeyword contained "@\(family\|template\|templateVar\|description\|details\|inheritParams\|field\)"
50
51
52if &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
63
64syn match rStrError display contained "\\."
65
66
67" 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
79" Statement
80syn keyword rStatement   break next return
81syn keyword rConditional if else
82syn keyword rRepeat      for in repeat while
83
84" Constant (not really)
85syn keyword rConstant T F LETTERS letters month.abb month.name pi
86syn keyword rConstant R.version.string
87
88syn keyword rNumber   NA_integer_ NA_real_ NA_complex_ NA_character_
89
90" Constants
91syn keyword rConstant NULL
92syn keyword rBoolean  FALSE TRUE
93syn keyword rNumber   NA Inf NaN
94
95" 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
100" number with no fractional part or exponent
101syn match rNumber "\<\d\+\>"
102" hexadecimal number
103syn 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
112" 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
120syn match rAssign    '='
121syn match rOperator    "&"
122syn match rOperator    '-'
123syn match rOperator    '\*'
124syn match rOperator    '+'
125if &filetype != "rmd" && &filetype != "rrst"
126  syn match rOperator    "[|!<>^~/:]"
127else
128  syn match rOperator    "[|!<>^~`/:]"
129endif
130syn match rOperator    "%\{2}\|%\S\{-}%"
131syn match rOperator '\([!><]\)\@<=='
132syn match rOperator '=='
133syn match rOpError  '\*\{3}'
134syn match rOpError  '//'
135syn match rOpError  '&&&'
136syn match rOpError  '|||'
137syn match rOpError  '<<'
138syn match rOpError  '>>'
139
140syn match rAssign "<\{1,2}-"
141syn match rAssign "->\{1,2}"
142
143" Special
144syn match rDelimiter "[,;:]"
145
146" Error
147if 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
157syn match rError      "[)\]}]"
158syn match rBraceError "[)}]" contained
159syn match rCurlyError "[)\]]" contained
160syn match rParenError "[\]}]" contained
161
162" 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
170
171syn match rDollar display contained "\$"
172syn match rDollar display contained "@"
173
174" List elements will not be highlighted as functions:
175syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
176syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
177
178" Functions that may add new objects
179syn keyword rPreProc     library require attach detach source
180
181if &filetype == "rhelp"
182  syn match rHelpIdent '\\method'
183  syn match rHelpIdent '\\S4method'
184endif
185
186" Type
187syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
188
189" Name of object with spaces
190if &filetype != "rmd" && &filetype != "rrst"
191  syn region rNameWSpace start="`" end="`"
192endif
193
194if &filetype == "rhelp"
195  syn match rhPreProc "^#ifdef.*"
196  syn match rhPreProc "^#endif.*"
197  syn match rhSection "\\dontrun\>"
198endif
199
200if exists("r_syn_minlines")
201  exe "syn sync minlines=" . r_syn_minlines
202else
203  syn sync minlines=40
204endif
205
206" Define the default highlighting.
207hi def link rAssign      Statement
208hi def link rBoolean     Boolean
209hi def link rBraceError  Error
210hi def link rComment     Comment
211hi def link rCommentTodo Todo
212hi 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
220hi def link rFunction    Function
221hi def link rHelpIdent   Identifier
222hi def link rhPreProc    PreProc
223hi def link rhSection    PreCondit
224hi def link rInteger     Number
225hi def link rLstElmt     Normal
226hi def link rNameWSpace  Normal
227hi def link rNumber      Number
228hi def link rOperator    Operator
229hi def link rOpError     Error
230hi 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
238hi def link rOKeyword    Title
239hi def link rOBlock      Comment
240hi def link rOTitle      Title
241hi def link rOCommentKey Comment
242hi def link rOExamples   SpecialComment
243
244
245let b:current_syntax="r"
246
247" vim: ts=8 sw=2
248