home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / runtime / dos / syntax / r.vim < prev    next >
Encoding:
Text File  |  2011-05-27  |  6.8 KB  |  203 lines

  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 Feb 20, 2011  12:06PM
  7. " Filenames:          *.R *.r *.Rhistory *.Rt
  8. " NOTE: The highlighting of R functions is defined in the
  9. " r-plugin/functions.vim, which is part of vim-r-plugin2:
  10. " http://www.vim.org/scripts/script.php?script_id=2628
  11. "
  12. " CONFIGURATION:
  13. "   syntax folding can be turned on by
  14. "
  15. "      let r_syntax_folding = 1
  16. "
  17. " Some lines of code were borrowed from Zhuojun Chen.
  18.  
  19. if exists("b:current_syntax")
  20.   finish
  21. endif
  22.  
  23. setlocal iskeyword=@,48-57,_,.
  24.  
  25. if exists("g:r_syntax_folding")
  26.   setlocal foldmethod=syntax
  27. endif
  28.  
  29. syn case match
  30.  
  31. " Comment
  32. syn match rComment contains=@Spell "\#.*"
  33.  
  34. if &filetype == "rhelp"
  35.   " string enclosed in double quotes
  36.   syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
  37.   " string enclosed in single quotes
  38.   syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
  39. else
  40.   " string enclosed in double quotes
  41.   syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/
  42.   " string enclosed in single quotes
  43.   syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/
  44. endif
  45.  
  46. syn match rStrError display contained "\\."
  47.  
  48.  
  49. " New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash
  50. syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
  51.  
  52. " Hexadecimal and Octal digits
  53. syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)"
  54.  
  55. " Unicode characters
  56. syn match rSpecial display contained "\\u\x\{1,4}"
  57. syn match rSpecial display contained "\\U\x\{1,8}"
  58. syn match rSpecial display contained "\\u{\x\{1,4}}"
  59. syn match rSpecial display contained "\\U{\x\{1,8}}"
  60.  
  61. " Statement
  62. syn keyword rStatement   break next return
  63. syn keyword rConditional if else
  64. syn keyword rRepeat      for in repeat while
  65.  
  66. " Constant (not really)
  67. syn keyword rConstant T F LETTERS letters month.ab month.name pi
  68. syn keyword rConstant R.version.string
  69.  
  70. syn keyword rNumber   NA_integer_ NA_real_ NA_complex_ NA_character_ 
  71.  
  72. " Constants
  73. syn keyword rConstant NULL
  74. syn keyword rBoolean  FALSE TRUE
  75. syn keyword rNumber   NA Inf NaN 
  76.  
  77. " integer
  78. syn match rInteger "\<\d\+L"
  79. syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L"
  80. syn match rInteger "\<\d\+[Ee]+\=\d\+L"
  81.  
  82. " number with no fractional part or exponent
  83. syn match rNumber "\<\d\+\>"
  84. " hexadecimal number 
  85. syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+"
  86.  
  87. " floating point number with integer and fractional parts and optional exponent
  88. syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\="
  89. " floating point number with no integer part and optional exponent
  90. syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\="
  91. " floating point number with no fractional part and optional exponent
  92. syn match rFloat "\<\d\+[Ee][-+]\=\d\+"
  93.  
  94. " complex number
  95. syn match rComplex "\<\d\+i"
  96. syn match rComplex "\<\d\++\d\+i"
  97. syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i"
  98. syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i"
  99. syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i"
  100. syn match rComplex "\<\d\+[Ee][-+]\=\d\+i"
  101.  
  102. syn match rOperator    "&"
  103. syn match rOperator    '-'
  104. syn match rOperator    '*'
  105. syn match rOperator    '+'
  106. syn match rOperator    '='
  107. syn match rOperator    "[|!<>^~`/:@]"
  108. syn match rOperator    "%\{2}\|%\*%\|%\/%\|%in%\|%o%\|%x%"
  109. syn match rOpError  '*\{3}'
  110. syn match rOpError  '//'
  111. syn match rOpError  '&&&'
  112. syn match rOpError  '|||'
  113. syn match rOpError  '<<'
  114. syn match rOpError  '>>'
  115.  
  116. syn match rArrow "<\{1,2}-"
  117. syn match rArrow "->\{1,2}"
  118.  
  119. " Special
  120. syn match rDelimiter "[,;:]"
  121.  
  122. " Error
  123. if exists("g:r_syntax_folding")
  124.   syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
  125.   syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
  126.   syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
  127. else
  128.   syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
  129.   syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
  130.   syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
  131. endif
  132.  
  133. syn match rError      "[)\]}]"
  134. syn match rBraceError "[)}]" contained
  135. syn match rCurlyError "[)\]]" contained
  136. syn match rParenError "[\]}]" contained
  137.  
  138. " Source list of R functions. The list is produced by the Vim-R-plugin
  139. " http://www.vim.org/scripts/script.php?script_id=2628
  140. runtime r-plugin/functions.vim
  141.  
  142. syn match rDollar display contained "\$"
  143.  
  144. " List elements will not be highlighted as functions:
  145. syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar
  146.  
  147. " Functions that may add new objects
  148. syn keyword rPreProc     library require attach detach source
  149.  
  150. if &filetype == "rhelp"
  151.     syn match rHelpIdent '\\method'
  152.     syn match rHelpIdent '\\S4method'
  153. endif
  154.  
  155. " Type
  156. syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame 
  157.  
  158. " Name of object with spaces
  159. syn region rNameWSpace start="`" end="`"
  160.  
  161. if &filetype == "rhelp"
  162.   syn match rhPreProc "^#ifdef.*" 
  163.   syn match rhPreProc "^#endif.*" 
  164.   syn match rhSection "\\dontrun\>"
  165. endif
  166.  
  167. " Define the default highlighting.
  168. hi def link rArrow       Statement    
  169. hi def link rBoolean     Boolean
  170. hi def link rBraceError  Error
  171. hi def link rComment     Comment
  172. hi def link rComplex     Number
  173. hi def link rConditional Conditional
  174. hi def link rConstant    Constant
  175. hi def link rCurlyError  Error
  176. hi def link rDelimiter   Delimiter
  177. hi def link rDollar      SpecialChar
  178. hi def link rError       Error
  179. hi def link rFloat       Float
  180. hi def link rFunction    Function
  181. hi def link rHelpIdent   Identifier
  182. hi def link rhPreProc    PreProc
  183. hi def link rhSection    PreCondit
  184. hi def link rInteger     Number
  185. hi def link rLstElmt     Normal
  186. hi def link rNameWSpace  Normal
  187. hi def link rNumber      Number
  188. hi def link rOperator    Operator
  189. hi def link rOpError     Error
  190. hi def link rParenError  Error
  191. hi def link rPreProc     PreProc
  192. hi def link rRepeat      Repeat
  193. hi def link rSpecial     SpecialChar
  194. hi def link rStatement   Statement
  195. hi def link rString      String
  196. hi def link rStrError    Error
  197. hi def link rType        Type
  198.  
  199. let b:current_syntax="r"
  200.  
  201. " vim: ts=8 sw=2
  202.