3 " Maintainer: Tom Payne <tom@tompayne.org>
4 " Last Change: 2001 May 10
6 " URL: http://www.tompayne.org/vim/syntax/r.vim
8 " For version 5.x: Clear all syntax items
9 " For version 6.x: Quit when a syntax file was already loaded
12 elseif exists("b:current_syntax")
17 setlocal iskeyword=@,48-57,_,.
19 set iskeyword=@,48-57,_,.
25 syn match rComment /\#.*/
28 " string enclosed in double quotes
29 syn region rString start=/"/ skip=/\\\\\|\\"/ end=/"/
30 " string enclosed in single quotes
31 syn region rString start=/'/ skip=/\\\\\|\\'/ end=/'/
32 " number with no fractional part or exponent
33 syn match rNumber /\d\+/
34 " floating point number with integer and fractional parts and optional exponent
35 syn match rFloat /\d\+\.\d*\([Ee][-+]\=\d\+\)\=/
36 " floating point number with no integer part and optional exponent
37 syn match rFloat /\.\d\+\([Ee][-+]\=\d\+\)\=/
38 " floating point number with no fractional part and optional exponent
39 syn match rFloat /\d\+[Ee][-+]\=\d\+/
42 " identifier with leading letter and optional following keyword characters
43 syn match rIdentifier /\a\k*/
44 " identifier with leading period, one or more digits, and at least one non-digit keyword character
45 syn match rIdentifier /\.\d*\K\k*/
48 syn keyword rStatement break next return
49 syn keyword rConditional if else
50 syn keyword rRepeat for in repeat while
53 syn keyword rConstant LETTERS letters month.ab month.name pi
54 syn keyword rConstant NULL
55 syn keyword rBoolean FALSE TRUE
56 syn keyword rNumber NA
59 syn keyword rType array category character complex double function integer list logical matrix numeric vector
62 syn match rDelimiter /[,;:]/
65 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
66 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
67 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
68 syn match rError /[)\]}]/
69 syn match rBraceError /[)}]/ contained
70 syn match rCurlyError /[)\]]/ contained
71 syn match rParenError /[\]}]/ contained
73 " Define the default highlighting.
74 " For version 5.7 and earlier: only when not done already
75 " For version 5.8 and later: only when an item doesn't have highlighting yet
76 if version >= 508 || !exists("did_r_syn_inits")
78 let did_r_syn_inits = 1
79 command -nargs=+ HiLink hi link <args>
81 command -nargs=+ HiLink hi def link <args>
83 HiLink rComment Comment
84 HiLink rConstant Constant
87 HiLink rBoolean Boolean
89 HiLink rStatement Statement
90 HiLink rConditional Conditional
92 HiLink rIdentifier Identifier
94 HiLink rDelimiter Delimiter
96 HiLink rBraceError Error
97 HiLink rCurlyError Error
98 HiLink rParenError Error
102 let b:current_syntax="r"