blob: d92f5c5bd0412fccdffad777325606074e36587d [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 '-'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200105syn match rOperator '\*'
Bram Moolenaar662db672011-03-22 14:05:35 +0100106syn match rOperator '+'
107syn match rOperator '='
108syn match rOperator "[|!<>^~`/:@]"
109syn match rOperator "%\{2}\|%\*%\|%\/%\|%in%\|%o%\|%x%"
Bram Moolenaar662db672011-03-22 14:05:35 +0100110syn match rOpError '//'
111syn match rOpError '&&&'
112syn match rOpError '|||'
113syn match rOpError '<<'
114syn match rOpError '>>'
115
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200116syn match rArrow "<\{1,2}-"
117syn match rArrow "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118
119" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200120syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121
122" Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100123if 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
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200133syn match rError "[)\]}]"
134syn match rBraceError "[)}]" contained
135syn match rCurlyError "[)\]]" contained
136syn match rParenError "[\]}]" contained
137
Bram Moolenaar662db672011-03-22 14:05:35 +0100138" 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
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200147" Functions that may add new objects
148syn keyword rPreProc library require attach detach source
149
Bram Moolenaar662db672011-03-22 14:05:35 +0100150if &filetype == "rhelp"
151 syn match rHelpIdent '\\method'
152 syn match rHelpIdent '\\S4method'
153endif
154
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200155" Type
156syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157
Bram Moolenaar662db672011-03-22 14:05:35 +0100158" 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167" Define the default highlighting.
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200168hi 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
Bram Moolenaar662db672011-03-22 14:05:35 +0100180hi def link rFunction Function
181hi def link rHelpIdent Identifier
182hi def link rhPreProc PreProc
183hi def link rhSection PreCondit
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200184hi def link rInteger Number
Bram Moolenaar662db672011-03-22 14:05:35 +0100185hi def link rLstElmt Normal
186hi def link rNameWSpace Normal
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200187hi def link rNumber Number
188hi def link rOperator Operator
Bram Moolenaar662db672011-03-22 14:05:35 +0100189hi def link rOpError Error
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200190hi 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198
199let b:current_syntax="r"
200
201" vim: ts=8 sw=2