Install vim74
[msysgit.git] / share / vim / vim74 / syntax / r.vim
blob5e76e7af7f92ecf521b1a9678eb4f0df07f25434
1 " Vim syntax file
2 " 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:        Sun May 19, 2013  05:59PM
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
13 " CONFIGURATION:
14 "   syntax folding can be turned on by
16 "      let r_syntax_folding = 1
18 " Some lines of code were borrowed from Zhuojun Chen.
20 if exists("b:current_syntax")
21   finish
22 endif
24 setlocal iskeyword=@,48-57,_,.
26 if exists("g:r_syntax_folding")
27   setlocal foldmethod=syntax
28 endif
30 syn case match
32 " Comment
33 syn match rComment contains=@Spell "#.*"
35 " Roxygen
36 syn match rOKeyword contained "@\(param\|return\|name\|rdname\|examples\|include\|docType\)"
37 syn match rOKeyword contained "@\(S3method\|TODO\|aliases\|alias\|assignee\|author\|callGraphDepth\|callGraph\)"
38 syn match rOKeyword contained "@\(callGraphPrimitives\|concept\|exportClass\|exportMethod\|exportPattern\|export\|formals\)"
39 syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\)"
40 syn match rOKeyword contained "@\(method\|nord\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)"
41 syn match rOComment contains=@Spell,rOKeyword "#'.*"
44 if &filetype == "rhelp"
45   " string enclosed in double quotes
46   syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
47   " string enclosed in single quotes
48   syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
49 else
50   " string enclosed in double quotes
51   syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
52   " string enclosed in single quotes
53   syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
54 endif
56 syn match rStrError display contained "\\."
59 " New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
60 syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
62 " Hexadecimal and Octal digits
63 syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
65 " Unicode characters
66 syn match rSpecial display contained "\\u\x\{1,4}"
67 syn match rSpecial display contained "\\U\x\{1,8}"
68 syn match rSpecial display contained "\\u{\x\{1,4}}"
69 syn match rSpecial display contained "\\U{\x\{1,8}}"
71 " Statement
72 syn keyword rStatement   break next return
73 syn keyword rConditional if else
74 syn keyword rRepeat      for in repeat while
76 " Constant (not really)
77 syn keyword rConstant T F LETTERS letters month.abb month.name pi
78 syn keyword rConstant R.version.string
80 syn keyword rNumber   NA_integer_ NA_real_ NA_complex_ NA_character_ 
82 " Constants
83 syn keyword rConstant NULL
84 syn keyword rBoolean  FALSE TRUE
85 syn keyword rNumber   NA Inf NaN 
87 " integer
88 syn match rInteger "\<\d\+L"
89 syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
90 syn match rInteger "\<\d\+[Ee]+\=\d\+L"
92 " number with no fractional part or exponent
93 syn match rNumber "\<\d\+\>"
94 " hexadecimal number 
95 syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
97 " floating point number with integer and fractional parts and optional exponent
98 syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
99 " floating point number with no integer part and optional exponent
100 syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
101 " floating point number with no fractional part and optional exponent
102 syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
104 " complex number
105 syn match rComplex "\<\d\+i"
106 syn match rComplex "\<\d\++\d\+i"
107 syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
108 syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
109 syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
110 syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
112 syn match rOperator    "&"
113 syn match rOperator    '-'
114 syn match rOperator    '\*'
115 syn match rOperator    '+'
116 syn match rOperator    '='
117 if &filetype != "rmd" && &filetype != "rrst"
118   syn match rOperator    "[|!<>^~/:]"
119 else
120   syn match rOperator    "[|!<>^~`/:]"
121 endif
122 syn match rOperator    "%\{2}\|%\S*%"
123 syn match rOpError  '\*\{3}'
124 syn match rOpError  '//'
125 syn match rOpError  '&&&'
126 syn match rOpError  '|||'
127 syn match rOpError  '<<'
128 syn match rOpError  '>>'
130 syn match rArrow "<\{1,2}-"
131 syn match rArrow "->\{1,2}"
133 " Special
134 syn match rDelimiter "[,;:]"
136 " Error
137 if exists("g:r_syntax_folding")
138   syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
139   syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
140   syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
141 else
142   syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
143   syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
144   syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
145 endif
147 syn match rError      "[)\]}]"
148 syn match rBraceError "[)}]" contained
149 syn match rCurlyError "[)\]]" contained
150 syn match rParenError "[\]}]" contained
152 " Source list of R functions. The list is produced by the Vim-R-plugin
153 " http://www.vim.org/scripts/script.php?script_id=2628
154 runtime r-plugin/functions.vim
156 syn match rDollar display contained "\$"
157 syn match rDollar display contained "@"
159 " List elements will not be highlighted as functions:
160 syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
161 syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar
163 " Functions that may add new objects
164 syn keyword rPreProc     library require attach detach source
166 if &filetype == "rhelp"
167     syn match rHelpIdent '\\method'
168     syn match rHelpIdent '\\S4method'
169 endif
171 " Type
172 syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame 
174 " Name of object with spaces
175 if &filetype != "rmd" && &filetype != "rrst"
176   syn region rNameWSpace start="`" end="`"
177 endif
179 if &filetype == "rhelp"
180   syn match rhPreProc "^#ifdef.*" 
181   syn match rhPreProc "^#endif.*" 
182   syn match rhSection "\\dontrun\>"
183 endif
185 " Define the default highlighting.
186 hi def link rArrow       Statement      
187 hi def link rBoolean     Boolean
188 hi def link rBraceError  Error
189 hi def link rComment     Comment
190 hi def link rOComment    Comment
191 hi def link rComplex     Number
192 hi def link rConditional Conditional
193 hi def link rConstant    Constant
194 hi def link rCurlyError  Error
195 hi def link rDelimiter   Delimiter
196 hi def link rDollar      SpecialChar
197 hi def link rError       Error
198 hi def link rFloat       Float
199 hi def link rFunction    Function
200 hi def link rHelpIdent   Identifier
201 hi def link rhPreProc    PreProc
202 hi def link rhSection    PreCondit
203 hi def link rInteger     Number
204 hi def link rLstElmt     Normal
205 hi def link rNameWSpace  Normal
206 hi def link rNumber      Number
207 hi def link rOperator    Operator
208 hi def link rOpError     Error
209 hi def link rParenError  Error
210 hi def link rPreProc     PreProc
211 hi def link rRepeat      Repeat
212 hi def link rSpecial     SpecialChar
213 hi def link rStatement   Statement
214 hi def link rString      String
215 hi def link rStrError    Error
216 hi def link rType        Type
217 hi def link rOKeyword    Title
219 let b:current_syntax="r"
221 " vim: ts=8 sw=2