blob: f3e730ef92cdc3ba9a91a31f0abefada5b1ce19e [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: R (GNU S)
Bram Moolenaar4770d092006-01-12 23:22:24 +00003" Maintainer: Vaidotas Zemlys <zemlys@gmail.com>
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00004" Last Change: 2006 Apr 30
Bram Moolenaar4770d092006-01-12 23:22:24 +00005" Filenames: *.R *.Rout *.r *.Rhistory *.Rt *.Rout.save *.Rout.fail
6" URL: http://uosis.mif.vu.lt/~zemlys/vim-syntax/r.vim
7
8" First maintainer Tom Payne <tom@tompayne.org>
9" Modified to make syntax less colourful and added the highlighting of
10" R assignment arrow
Bram Moolenaar071d4272004-06-13 20:20:40 +000011
12" For version 5.x: Clear all syntax items
13" For version 6.x: Quit when a syntax file was already loaded
14if version < 600
15 syntax clear
16elseif exists("b:current_syntax")
17 finish
18endif
19
20if version >= 600
21 setlocal iskeyword=@,48-57,_,.
22else
23 set iskeyword=@,48-57,_,.
24endif
25
26syn case match
27
28" Comment
29syn match rComment /\#.*/
30
31" Constant
32" string enclosed in double quotes
33syn region rString start=/"/ skip=/\\\\\|\\"/ end=/"/
34" string enclosed in single quotes
35syn region rString start=/'/ skip=/\\\\\|\\'/ end=/'/
36" number with no fractional part or exponent
37syn match rNumber /\d\+/
38" floating point number with integer and fractional parts and optional exponent
39syn match rFloat /\d\+\.\d*\([Ee][-+]\=\d\+\)\=/
40" floating point number with no integer part and optional exponent
41syn match rFloat /\.\d\+\([Ee][-+]\=\d\+\)\=/
42" floating point number with no fractional part and optional exponent
43syn match rFloat /\d\+[Ee][-+]\=\d\+/
44
45" Identifier
46" identifier with leading letter and optional following keyword characters
47syn match rIdentifier /\a\k*/
48" identifier with leading period, one or more digits, and at least one non-digit keyword character
49syn match rIdentifier /\.\d*\K\k*/
50
51" Statement
52syn keyword rStatement break next return
53syn keyword rConditional if else
54syn keyword rRepeat for in repeat while
55
56" Constant
57syn keyword rConstant LETTERS letters month.ab month.name pi
58syn keyword rConstant NULL
59syn keyword rBoolean FALSE TRUE
60syn keyword rNumber NA
Bram Moolenaar4770d092006-01-12 23:22:24 +000061syn match rArrow /<\{1,2}-/
Bram Moolenaar071d4272004-06-13 20:20:40 +000062
63" Type
Bram Moolenaar4770d092006-01-12 23:22:24 +000064syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
66" Special
67syn match rDelimiter /[,;:]/
68
69" Error
70syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
71syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
72syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
73syn match rError /[)\]}]/
74syn match rBraceError /[)}]/ contained
75syn match rCurlyError /[)\]]/ contained
76syn match rParenError /[\]}]/ contained
77
78" Define the default highlighting.
79" For version 5.7 and earlier: only when not done already
80" For version 5.8 and later: only when an item doesn't have highlighting yet
81if version >= 508 || !exists("did_r_syn_inits")
82 if version < 508
83 let did_r_syn_inits = 1
84 command -nargs=+ HiLink hi link <args>
85 else
86 command -nargs=+ HiLink hi def link <args>
87 endif
88 HiLink rComment Comment
89 HiLink rConstant Constant
90 HiLink rString String
91 HiLink rNumber Number
92 HiLink rBoolean Boolean
93 HiLink rFloat Float
94 HiLink rStatement Statement
95 HiLink rConditional Conditional
96 HiLink rRepeat Repeat
Bram Moolenaar4770d092006-01-12 23:22:24 +000097 HiLink rIdentifier Normal
98 HiLink rArrow Statement
99 HiLink rType Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100 HiLink rDelimiter Delimiter
101 HiLink rError Error
102 HiLink rBraceError Error
103 HiLink rCurlyError Error
104 HiLink rParenError Error
105 delcommand HiLink
106endif
107
108let b:current_syntax="r"
109
110" vim: ts=8 sw=2
Bram Moolenaar4770d092006-01-12 23:22:24 +0000111