xref: /vim-8.2.3635/runtime/syntax/r.vim (revision 17fb0e89)
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 Feb 20, 2011  12:06PM
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
35if &filetype == "rhelp"
36  " string enclosed in double quotes
37  syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
38  " string enclosed in single quotes
39  syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
40else
41  " string enclosed in double quotes
42  syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
43  " string enclosed in single quotes
44  syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
45endif
46
47syn match rStrError display contained "\\."
48
49
50" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
51syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
52
53" Hexadecimal and Octal digits
54syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
55
56" Unicode characters
57syn match rSpecial display contained "\\u\x\{1,4}"
58syn match rSpecial display contained "\\U\x\{1,8}"
59syn match rSpecial display contained "\\u{\x\{1,4}}"
60syn match rSpecial display contained "\\U{\x\{1,8}}"
61
62" Statement
63syn keyword rStatement   break next return
64syn keyword rConditional if else
65syn keyword rRepeat      for in repeat while
66
67" Constant (not really)
68syn keyword rConstant T F LETTERS letters month.ab month.name pi
69syn keyword rConstant R.version.string
70
71syn keyword rNumber   NA_integer_ NA_real_ NA_complex_ NA_character_
72
73" Constants
74syn keyword rConstant NULL
75syn keyword rBoolean  FALSE TRUE
76syn keyword rNumber   NA Inf NaN
77
78" integer
79syn match rInteger "\<\d\+L"
80syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
81syn match rInteger "\<\d\+[Ee]+\=\d\+L"
82
83" number with no fractional part or exponent
84syn match rNumber "\<\d\+\>"
85" hexadecimal number
86syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
87
88" floating point number with integer and fractional parts and optional exponent
89syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
90" floating point number with no integer part and optional exponent
91syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
92" floating point number with no fractional part and optional exponent
93syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
94
95" complex number
96syn match rComplex "\<\d\+i"
97syn match rComplex "\<\d\++\d\+i"
98syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
99syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
100syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
101syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
102
103syn match rOperator    "&"
104syn match rOperator    '-'
105syn match rOperator    '*'
106syn match rOperator    '+'
107syn match rOperator    '='
108syn match rOperator    "[|!<>^~`/:@]"
109syn match rOperator    "%\{2}\|%\*%\|%\/%\|%in%\|%o%\|%x%"
110syn match rOpError  '*\{3}'
111syn match rOpError  '//'
112syn match rOpError  '&&&'
113syn match rOpError  '|||'
114syn match rOpError  '<<'
115syn match rOpError  '>>'
116
117syn match rArrow "<\{1,2}-"
118syn match rArrow "->\{1,2}"
119
120" Special
121syn match rDelimiter "[,;:]"
122
123" Error
124if exists("g:r_syntax_folding")
125  syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
126  syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
127  syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
128else
129  syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
130  syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
131  syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
132endif
133
134syn match rError      "[)\]}]"
135syn match rBraceError "[)}]" contained
136syn match rCurlyError "[)\]]" contained
137syn match rParenError "[\]}]" contained
138
139" Source list of R functions. The list is produced by the Vim-R-plugin
140" http://www.vim.org/scripts/script.php?script_id=2628
141runtime r-plugin/functions.vim
142
143syn match rDollar display contained "\$"
144
145" List elements will not be highlighted as functions:
146syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
147
148" Functions that may add new objects
149syn keyword rPreProc     library require attach detach source
150
151if &filetype == "rhelp"
152    syn match rHelpIdent '\\method'
153    syn match rHelpIdent '\\S4method'
154endif
155
156" Type
157syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
158
159" Name of object with spaces
160syn region rNameWSpace start="`" end="`"
161
162if &filetype == "rhelp"
163  syn match rhPreProc "^#ifdef.*"
164  syn match rhPreProc "^#endif.*"
165  syn match rhSection "\\dontrun\>"
166endif
167
168" Define the default highlighting.
169hi def link rArrow       Statement
170hi def link rBoolean     Boolean
171hi def link rBraceError  Error
172hi def link rComment     Comment
173hi def link rComplex     Number
174hi def link rConditional Conditional
175hi def link rConstant    Constant
176hi def link rCurlyError  Error
177hi def link rDelimiter   Delimiter
178hi def link rDollar      SpecialChar
179hi def link rError       Error
180hi def link rFloat       Float
181hi def link rFunction    Function
182hi def link rHelpIdent   Identifier
183hi def link rhPreProc    PreProc
184hi def link rhSection    PreCondit
185hi def link rInteger     Number
186hi def link rLstElmt	 Normal
187hi def link rNameWSpace  Normal
188hi def link rNumber      Number
189hi def link rOperator    Operator
190hi def link rOpError     Error
191hi def link rParenError  Error
192hi def link rPreProc     PreProc
193hi def link rRepeat      Repeat
194hi def link rSpecial     SpecialChar
195hi def link rStatement   Statement
196hi def link rString      String
197hi def link rStrError    Error
198hi def link rType        Type
199
200let b:current_syntax="r"
201
202" vim: ts=8 sw=2
203