xref: /vim-8.2.3635/runtime/syntax/r.vim (revision 5b8d8fdb)
1" Vim syntax file
2" Language:	R (GNU S)
3" Maintainer:	Tom Payne <[email protected]>
4" Last Change:  2003 May 11
5" Filenames:	*.r
6" URL:		http://www.tompayne.org/vim/syntax/r.vim
7
8" For version 5.x: Clear all syntax items
9" For version 6.x: Quit when a syntax file was already loaded
10if version < 600
11  syntax clear
12elseif exists("b:current_syntax")
13  finish
14endif
15
16if version >= 600
17  setlocal iskeyword=@,48-57,_,.
18else
19  set iskeyword=@,48-57,_,.
20endif
21
22syn case match
23
24" Comment
25syn match rComment /\#.*/
26
27" Constant
28" string enclosed in double quotes
29syn region rString start=/"/ skip=/\\\\\|\\"/ end=/"/
30" string enclosed in single quotes
31syn region rString start=/'/ skip=/\\\\\|\\'/ end=/'/
32" number with no fractional part or exponent
33syn match rNumber /\d\+/
34" floating point number with integer and fractional parts and optional exponent
35syn match rFloat /\d\+\.\d*\([Ee][-+]\=\d\+\)\=/
36" floating point number with no integer part and optional exponent
37syn match rFloat /\.\d\+\([Ee][-+]\=\d\+\)\=/
38" floating point number with no fractional part and optional exponent
39syn match rFloat /\d\+[Ee][-+]\=\d\+/
40
41" Identifier
42" identifier with leading letter and optional following keyword characters
43syn match rIdentifier /\a\k*/
44" identifier with leading period, one or more digits, and at least one non-digit keyword character
45syn match rIdentifier /\.\d*\K\k*/
46
47" Statement
48syn keyword rStatement   break next return
49syn keyword rConditional if else
50syn keyword rRepeat      for in repeat while
51
52" Constant
53syn keyword rConstant LETTERS letters month.ab month.name pi
54syn keyword rConstant NULL
55syn keyword rBoolean  FALSE TRUE
56syn keyword rNumber   NA
57
58" Type
59syn keyword rType array category character complex double function integer list logical matrix numeric vector
60
61" Special
62syn match rDelimiter /[,;:]/
63
64" Error
65syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
66syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
67syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
68syn match rError      /[)\]}]/
69syn match rBraceError /[)}]/ contained
70syn match rCurlyError /[)\]]/ contained
71syn match rParenError /[\]}]/ contained
72
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
76if version >= 508 || !exists("did_r_syn_inits")
77  if version < 508
78    let did_r_syn_inits = 1
79    command -nargs=+ HiLink hi link <args>
80  else
81    command -nargs=+ HiLink hi def link <args>
82  endif
83  HiLink rComment     Comment
84  HiLink rConstant    Constant
85  HiLink rString      String
86  HiLink rNumber      Number
87  HiLink rBoolean     Boolean
88  HiLink rFloat       Float
89  HiLink rStatement   Statement
90  HiLink rConditional Conditional
91  HiLink rRepeat      Repeat
92  HiLink rIdentifier  Identifier
93  HiLink rType	      Type
94  HiLink rDelimiter   Delimiter
95  HiLink rError       Error
96  HiLink rBraceError  Error
97  HiLink rCurlyError  Error
98  HiLink rParenError  Error
99  delcommand HiLink
100endif
101
102let b:current_syntax="r"
103
104" vim: ts=8 sw=2
105