xref: /vim-8.2.3635/runtime/syntax/r.vim (revision dee2e315)
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" Last Change:	      Sun May 19, 2013  05:59PM
7" 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"
13" CONFIGURATION:
14"   syntax folding can be turned on by
15"
16"      let r_syntax_folding = 1
17"
18" Some lines of code were borrowed from Zhuojun Chen.
19
20if exists("b:current_syntax")
21  finish
22endif
23
24setlocal iskeyword=@,48-57,_,.
25
26if exists("g:r_syntax_folding")
27  setlocal foldmethod=syntax
28endif
29
30syn case match
31
32" Comment
33syn 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
43
44if &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
55
56syn match rStrError display contained "\\."
57
58
59" 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
71" Statement
72syn keyword rStatement   break next return
73syn keyword rConditional if else
74syn keyword rRepeat      for in repeat while
75
76" Constant (not really)
77syn keyword rConstant T F LETTERS letters month.abb month.name pi
78syn keyword rConstant R.version.string
79
80syn keyword rNumber   NA_integer_ NA_real_ NA_complex_ NA_character_
81
82" Constants
83syn keyword rConstant NULL
84syn keyword rBoolean  FALSE TRUE
85syn keyword rNumber   NA Inf NaN
86
87" 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
92" 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
104" 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    '-'
114syn match rOperator    '\*'
115syn match rOperator    '+'
116syn match rOperator    '='
117if &filetype != "rmd" && &filetype != "rrst"
118  syn match rOperator    "[|!<>^~/:]"
119else
120  syn match rOperator    "[|!<>^~`/:]"
121endif
122syn match rOperator    "%\{2}\|%\S*%"
123syn match rOpError  '\*\{3}'
124syn match rOpError  '//'
125syn match rOpError  '&&&'
126syn match rOpError  '|||'
127syn match rOpError  '<<'
128syn match rOpError  '>>'
129
130syn match rArrow "<\{1,2}-"
131syn match rArrow "->\{1,2}"
132
133" Special
134syn match rDelimiter "[,;:]"
135
136" Error
137if 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
147syn match rError      "[)\]}]"
148syn match rBraceError "[)}]" contained
149syn match rCurlyError "[)\]]" contained
150syn match rParenError "[\]}]" contained
151
152" 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 "\$"
157syn match rDollar display contained "@"
158
159" List elements will not be highlighted as functions:
160syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
161syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
162
163" Functions that may add new objects
164syn keyword rPreProc     library require attach detach source
165
166if &filetype == "rhelp"
167    syn match rHelpIdent '\\method'
168    syn match rHelpIdent '\\S4method'
169endif
170
171" Type
172syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
173
174" Name of object with spaces
175if &filetype != "rmd" && &filetype != "rrst"
176  syn region rNameWSpace start="`" end="`"
177endif
178
179if &filetype == "rhelp"
180  syn match rhPreProc "^#ifdef.*"
181  syn match rhPreProc "^#endif.*"
182  syn match rhSection "\\dontrun\>"
183endif
184
185" Define the default highlighting.
186hi def link rArrow       Statement
187hi def link rBoolean     Boolean
188hi def link rBraceError  Error
189hi def link rComment     Comment
190hi def link rOComment    Comment
191hi 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
199hi def link rFunction    Function
200hi def link rHelpIdent   Identifier
201hi def link rhPreProc    PreProc
202hi def link rhSection    PreCondit
203hi def link rInteger     Number
204hi def link rLstElmt	 Normal
205hi def link rNameWSpace  Normal
206hi def link rNumber      Number
207hi def link rOperator    Operator
208hi def link rOpError     Error
209hi 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
217hi def link rOKeyword    Title
218
219let b:current_syntax="r"
220
221" vim: ts=8 sw=2
222