blob: 7d98e92b748fba92e455ce5f5fadecb1f06d2152 [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>
6" Last Change: Wed Sep 29, 2010 09:31AM
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" Some lines of code were borrowed from Zhuojun Chen.
Bram Moolenaar4770d092006-01-12 23:22:24 +000014
Bram Moolenaar483c5d82010-10-20 18:45:33 +020015if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000016 finish
17endif
18
Bram Moolenaar483c5d82010-10-20 18:45:33 +020019setlocal iskeyword=@,48-57,_,.
Bram Moolenaar071d4272004-06-13 20:20:40 +000020
21syn case match
22
23" Comment
Bram Moolenaar483c5d82010-10-20 18:45:33 +020024syn match rComment contains=@Spell "\#.*"
Bram Moolenaar071d4272004-06-13 20:20:40 +000025
Bram Moolenaar071d4272004-06-13 20:20:40 +000026" string enclosed in double quotes
Bram Moolenaar483c5d82010-10-20 18:45:33 +020027syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
Bram Moolenaar071d4272004-06-13 20:20:40 +000028" string enclosed in single quotes
Bram Moolenaar483c5d82010-10-20 18:45:33 +020029syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
Bram Moolenaar071d4272004-06-13 20:20:40 +000030
Bram Moolenaar483c5d82010-10-20 18:45:33 +020031syn match rStrError display contained "\\."
32
33" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
34syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
35
36" Hexadecimal and Octal digits
37syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
38
39" Unicode characters
40syn match rSpecial display contained "\\u\x\{1,4}"
41syn match rSpecial display contained "\\U\x\{1,8}"
42syn match rSpecial display contained "\\u{\x\{1,4}}"
43syn match rSpecial display contained "\\U{\x\{1,8}}"
44
45
46syn match rDollar "\$"
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
48" Statement
49syn keyword rStatement break next return
50syn keyword rConditional if else
51syn keyword rRepeat for in repeat while
52
Bram Moolenaar483c5d82010-10-20 18:45:33 +020053" Constant (not really)
54syn keyword rConstant T F LETTERS letters month.ab month.name pi
55syn keyword rConstant R.version.string
56
Bram Moolenaar071d4272004-06-13 20:20:40 +000057" Constant
Bram Moolenaar071d4272004-06-13 20:20:40 +000058syn keyword rConstant NULL
59syn keyword rBoolean FALSE TRUE
Bram Moolenaar483c5d82010-10-20 18:45:33 +020060syn keyword rNumber NA NA_integer_ NA_real_ NA_complex_ NA_character_
61syn keyword rNumber Inf NaN
Bram Moolenaar071d4272004-06-13 20:20:40 +000062
Bram Moolenaar483c5d82010-10-20 18:45:33 +020063" integer
64syn match rInteger "\<\d\+L"
65syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
66syn match rInteger "\<\d\+[Ee]+\=\d\+L"
67
68syn match rOperator "[\*\!\&\+\-\<\>\=\^\|\~\`/:@]"
69syn match rOperator "%\{2}\|%\*%\|%\/%\|%in%\|%o%\|%x%"
70
71syn match rComplex "\<\d\+i"
72syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
73syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
74syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
75syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
76
77" number with no fractional part or exponent
78syn match rNumber "\<\d\+\>"
79" hexadecimal number
80syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
81
82" floating point number with integer and fractional parts and optional exponent
83syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
84" floating point number with no integer part and optional exponent
85syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
86" floating point number with no fractional part and optional exponent
87syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
88
89syn match rArrow "<\{1,2}-"
90syn match rArrow "->\{1,2}"
Bram Moolenaar071d4272004-06-13 20:20:40 +000091
92" Special
Bram Moolenaar483c5d82010-10-20 18:45:33 +020093syn match rDelimiter "[,;:]"
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
95" Error
96syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
97syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
98syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
Bram Moolenaar483c5d82010-10-20 18:45:33 +020099syn match rError "[)\]}]"
100syn match rBraceError "[)}]" contained
101syn match rCurlyError "[)\]]" contained
102syn match rParenError "[\]}]" contained
103
104" Functions that may add new objects
105syn keyword rPreProc library require attach detach source
106
107" Type
108syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109
110" Define the default highlighting.
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200111hi def link rArrow Statement
112hi def link rBoolean Boolean
113hi def link rBraceError Error
114hi def link rComment Comment
115hi def link rComplex Number
116hi def link rConditional Conditional
117hi def link rConstant Constant
118hi def link rCurlyError Error
119hi def link rDelimiter Delimiter
120hi def link rDollar SpecialChar
121hi def link rError Error
122hi def link rFloat Float
123hi def link rInteger Number
124hi def link rNumber Number
125hi def link rOperator Operator
126hi def link rParenError Error
127hi def link rPreProc PreProc
128hi def link rRepeat Repeat
129hi def link rSpecial SpecialChar
130hi def link rStatement Statement
131hi def link rString String
132hi def link rStrError Error
133hi def link rType Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134
135let b:current_syntax="r"
136
137" vim: ts=8 sw=2