blob: 8912ba191e3aade9e4ff49948bcfa242f3063c4c [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 Moolenaar662db672011-03-22 14:05:35 +01006" Last Change: Sun Feb 20, 2011 12:06PM
Bram Moolenaar483c5d82010-10-20 18:45:33 +02007" 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"
Bram Moolenaar662db672011-03-22 14:05:35 +010013" CONFIGURATION:
14" syntax folding can be turned on by
15"
16" let r_syntax_folding = 1
17"
Bram Moolenaar483c5d82010-10-20 18:45:33 +020018" Some lines of code were borrowed from Zhuojun Chen.
Bram Moolenaar4770d092006-01-12 23:22:24 +000019
Bram Moolenaar483c5d82010-10-20 18:45:33 +020020if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000021 finish
22endif
23
Bram Moolenaar483c5d82010-10-20 18:45:33 +020024setlocal iskeyword=@,48-57,_,.
Bram Moolenaar071d4272004-06-13 20:20:40 +000025
Bram Moolenaar662db672011-03-22 14:05:35 +010026if exists("g:r_syntax_folding")
27 setlocal foldmethod=syntax
28endif
29
Bram Moolenaar071d4272004-06-13 20:20:40 +000030syn case match
31
32" Comment
Bram Moolenaar483c5d82010-10-20 18:45:33 +020033syn match rComment contains=@Spell "\#.*"
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
Bram Moolenaar662db672011-03-22 14:05:35 +010035if &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
Bram Moolenaar071d4272004-06-13 20:20:40 +000046
Bram Moolenaar483c5d82010-10-20 18:45:33 +020047syn match rStrError display contained "\\."
48
Bram Moolenaar662db672011-03-22 14:05:35 +010049
Bram Moolenaar483c5d82010-10-20 18:45:33 +020050" 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
Bram Moolenaar071d4272004-06-13 20:20:40 +000062" Statement
63syn keyword rStatement break next return
64syn keyword rConditional if else
65syn keyword rRepeat for in repeat while
66
Bram Moolenaar483c5d82010-10-20 18:45:33 +020067" Constant (not really)
68syn keyword rConstant T F LETTERS letters month.ab month.name pi
69syn keyword rConstant R.version.string
70
Bram Moolenaar662db672011-03-22 14:05:35 +010071syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_
72
73" Constants
Bram Moolenaar071d4272004-06-13 20:20:40 +000074syn keyword rConstant NULL
75syn keyword rBoolean FALSE TRUE
Bram Moolenaar662db672011-03-22 14:05:35 +010076syn keyword rNumber NA Inf NaN
Bram Moolenaar071d4272004-06-13 20:20:40 +000077
Bram Moolenaar483c5d82010-10-20 18:45:33 +020078" 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
Bram Moolenaar483c5d82010-10-20 18:45:33 +020083" 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
Bram Moolenaar662db672011-03-22 14:05:35 +010095" 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
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200117syn match rArrow "<\{1,2}-"
118syn match rArrow "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119
120" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200121syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122
123" Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100124if 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
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200134syn match rError "[)\]}]"
135syn match rBraceError "[)}]" contained
136syn match rCurlyError "[)\]]" contained
137syn match rParenError "[\]}]" contained
138
Bram Moolenaar662db672011-03-22 14:05:35 +0100139" 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
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200148" Functions that may add new objects
149syn keyword rPreProc library require attach detach source
150
Bram Moolenaar662db672011-03-22 14:05:35 +0100151if &filetype == "rhelp"
152 syn match rHelpIdent '\\method'
153 syn match rHelpIdent '\\S4method'
154endif
155
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200156" Type
157syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000158
Bram Moolenaar662db672011-03-22 14:05:35 +0100159" 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168" Define the default highlighting.
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200169hi 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
Bram Moolenaar662db672011-03-22 14:05:35 +0100181hi def link rFunction Function
182hi def link rHelpIdent Identifier
183hi def link rhPreProc PreProc
184hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200185hi def link rInteger Number
Bram Moolenaar662db672011-03-22 14:05:35 +0100186hi def link rLstElmt Normal
187hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200188hi def link rNumber Number
189hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100190hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200191hi 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199
200let b:current_syntax="r"
201
202" vim: ts=8 sw=2