/src/etc/vim/syntax/rust.vim

http://github.com/jruderman/rust · Vim Script · 134 lines · 93 code · 25 blank · 16 comment · 5 complexity · 642c80a8bb4c2a37d7ee15806ed4da01 MD5 · raw file

  1. " Vim syntax file
  2. " Language: Rust
  3. " Maintainer: Patrick Walton <pcwalton@mozilla.com>
  4. " Maintainer: Ben Blum <bblum@mozilla.com>
  5. " Last Change: 2012 Jul 06
  6. if version < 600
  7. syntax clear
  8. elseif exists("b:current_syntax")
  9. finish
  10. endif
  11. syn keyword rustAssert assert
  12. syn match rustAssert "assert\(\w\)*"
  13. syn keyword rustKeyword alt again as break
  14. syn keyword rustKeyword check claim const copy do drop else export extern fail
  15. syn keyword rustKeyword for if impl import in let log
  16. syn keyword rustKeyword loop match mod module move mut new of owned pure
  17. syn keyword rustKeyword ret return self to unchecked
  18. syn match rustKeyword "unsafe" " Allows also matching unsafe::foo()
  19. syn keyword rustKeyword use while with
  20. " FIXME: Scoped impl's name is also fallen in this category
  21. syn keyword rustKeyword mod trait class struct enum type nextgroup=rustIdentifier skipwhite
  22. syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
  23. syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
  24. syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
  25. " Reserved words
  26. syn keyword rustKeyword m32 m64 m128 f80 f16 f128
  27. syn keyword rustType int uint float char bool u8 u16 u32 u64 f32
  28. syn keyword rustType f64 i8 i16 i32 i64 str
  29. syn keyword rustType option either
  30. " Types from libc
  31. syn keyword rustType c_float c_double c_void FILE fpos_t
  32. syn keyword rustType DIR dirent
  33. syn keyword rustType c_char c_schar c_uchar
  34. syn keyword rustType c_short c_ushort c_int c_uint c_long c_ulong
  35. syn keyword rustType size_t ptrdiff_t clock_t time_t
  36. syn keyword rustType c_longlong c_ulonglong intptr_t uintptr_t
  37. syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t
  38. syn keyword rustBoolean true false
  39. syn keyword rustConstant some none " option
  40. syn keyword rustConstant left right " either
  41. syn keyword rustConstant ok err " result
  42. syn keyword rustConstant success failure " task
  43. syn keyword rustConstant cons nil " list
  44. " syn keyword rustConstant empty node " tree
  45. " Constants from libc
  46. syn keyword rustConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
  47. syn keyword rustConstant EOF SEEK_SET SEEK_CUR SEEK_END _IOFBF _IONBF
  48. syn keyword rustConstant _IOLBF BUFSIZ FOPEN_MAX FILENAME_MAX L_tmpnam
  49. syn keyword rustConstant TMP_MAX O_RDONLY O_WRONLY O_RDWR O_APPEND O_CREAT
  50. syn keyword rustConstant O_EXCL O_TRUNC S_IFIFO S_IFCHR S_IFBLK S_IFDIR
  51. syn keyword rustConstant S_IFREG S_IFMT S_IEXEC S_IWRITE S_IREAD S_IRWXU
  52. syn keyword rustConstant S_IXUSR S_IWUSR S_IRUSR F_OK R_OK W_OK X_OK
  53. syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
  54. " If foo::bar changes to foo.bar, change this ("::" to "\.").
  55. " If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
  56. syn match rustModPath "\w\(\w\)*::[^<]"he=e-3,me=e-3
  57. syn match rustModPathSep "::"
  58. syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1 contains=rustAssert
  59. syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 contains=rustAssert " foo::<T>();
  60. syn match rustMacro '\w\(\w\)*!'
  61. syn match rustMacro '#\w\(\w\)*'
  62. syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo
  63. syn region rustAttribute start="#\[" end="\]" contains=rustString
  64. " Number literals
  65. syn match rustNumber display "\<[0-9][0-9_]*\>"
  66. syn match rustNumber display "\<[0-9][0-9_]*\(u\|u8\|u16\|u32\|u64\)\>"
  67. syn match rustNumber display "\<[0-9][0-9_]*\(i8\|i16\|i32\|i64\)\>"
  68. syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\>"
  69. syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(u\|u8\|u16\|u32\|u64\)\>"
  70. syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(i8\|i16\|i32\|i64\)\>"
  71. syn match rustBinNumber display "\<0b[01_]\+\>"
  72. syn match rustBinNumber display "\<0b[01_]\+\(u\|u8\|u16\|u32\|u64\)\>"
  73. syn match rustBinNumber display "\<0b[01_]\+\(i8\|i16\|i32\|i64\)\>"
  74. syn match rustFloat display "\<[0-9][0-9_]*\(f\|f32\|f64\)\>"
  75. syn match rustFloat display "\<[0-9][0-9_]*\([eE][+-]\=[0-9_]\+\)\>"
  76. syn match rustFloat display "\<[0-9][0-9_]*\([eE][+-]\=[0-9_]\+\)\(f\|f32\|f64\)\>"
  77. syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\>"
  78. syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\(f\|f32\|f64\)\>"
  79. syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\>"
  80. syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\(f\|f32\|f64\)\>"
  81. syn match rustCharacter "'\([^'\\]\|\\\(['nrt\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'"
  82. syn region rustComment start="/\*" end="\*/" contains=rustComment,rustTodo
  83. syn region rustComment start="//" skip="\\$" end="$" contains=rustTodo keepend
  84. syn keyword rustTodo TODO FIXME XXX NB
  85. hi def link rustHexNumber rustNumber
  86. hi def link rustBinNumber rustNumber
  87. hi def link rustIdentifierPrime rustIdentifier
  88. hi def link rustString String
  89. hi def link rustCharacter Character
  90. hi def link rustNumber Number
  91. hi def link rustBoolean Boolean
  92. hi def link rustConstant Constant
  93. hi def link rustFloat Float
  94. hi def link rustAssert Keyword
  95. hi def link rustKeyword Keyword
  96. hi def link rustIdentifier Identifier
  97. hi def link rustModPath Include
  98. hi def link rustFuncName Function
  99. hi def link rustComment Comment
  100. hi def link rustMacro Macro
  101. hi def link rustType Type
  102. hi def link rustTodo Todo
  103. hi def link rustAttribute PreProc
  104. " Other Suggestions:
  105. " hi rustAssert ctermfg=yellow
  106. " hi rustMacro ctermfg=magenta
  107. syn sync minlines=200
  108. syn sync maxlines=500
  109. let b:current_syntax = "rust"