xref: /vim-8.2.3635/runtime/syntax/r.vim (revision 543b7ef7)
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  '//'
111syn match rOpError  '&&&'
112syn match rOpError  '|||'
113syn match rOpError  '<<'
114syn match rOpError  '>>'
115
116syn match rArrow "<\{1,2}-"
117syn match rArrow "->\{1,2}"
118
119" Special
120syn match rDelimiter "[,;:]"
121
122" Error
123if exists("g:r_syntax_folding")
124  syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
125  syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
126  syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
127else
128  syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
129  syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
130  syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
131endif
132
133syn match rError      "[)\]}]"
134syn match rBraceError "[)}]" contained
135syn match rCurlyError "[)\]]" contained
136syn match rParenError "[\]}]" contained
137
138" Source list of R functions. The list is produced by the Vim-R-plugin
139" http://www.vim.org/scripts/script.php?script_id=2628
140runtime r-plugin/functions.vim
141
142syn match rDollar display contained "\$"
143
144" List elements will not be highlighted as functions:
145syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
146
147" Functions that may add new objects
148syn keyword rPreProc     library require attach detach source
149
150if &filetype == "rhelp"
151    syn match rHelpIdent '\\method'
152    syn match rHelpIdent '\\S4method'
153endif
154
155" Type
156syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
157
158" Name of object with spaces
159syn region rNameWSpace start="`" end="`"
160
161if &filetype == "rhelp"
162  syn match rhPreProc "^#ifdef.*"
163  syn match rhPreProc "^#endif.*"
164  syn match rhSection "\\dontrun\>"
165endif
166
167" Define the default highlighting.
168hi def link rArrow       Statement
169hi def link rBoolean     Boolean
170hi def link rBraceError  Error
171hi def link rComment     Comment
172hi def link rComplex     Number
173hi def link rConditional Conditional
174hi def link rConstant    Constant
175hi def link rCurlyError  Error
176hi def link rDelimiter   Delimiter
177hi def link rDollar      SpecialChar
178hi def link rError       Error
179hi def link rFloat       Float
180hi def link rFunction    Function
181hi def link rHelpIdent   Identifier
182hi def link rhPreProc    PreProc
183hi def link rhSection    PreCondit
184hi def link rInteger     Number
185hi def link rLstElmt	 Normal
186hi def link rNameWSpace  Normal
187hi def link rNumber      Number
188hi def link rOperator    Operator
189hi def link rOpError     Error
190hi def link rParenError  Error
191hi def link rPreProc     PreProc
192hi def link rRepeat      Repeat
193hi def link rSpecial     SpecialChar
194hi def link rStatement   Statement
195hi def link rString      String
196hi def link rStrError    Error
197hi def link rType        Type
198
199let b:current_syntax="r"
200
201" vim: ts=8 sw=2
202