PageRenderTime 45ms CodeModel.GetById 16ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

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

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