go.vim (7159B)
1 " Copyright 2009 The Go Authors. All rights reserved. 2 " Use of this source code is governed by a BSD-style 3 " license that can be found in the LICENSE file. 4 " 5 " go.vim: Vim syntax file for Go. 6 " 7 " Options: 8 " There are some options for customizing the highlighting; the recommended 9 " settings are the default values, but you can write: 10 " let OPTION_NAME = 0 11 " in your ~/.vimrc file to disable particular options. You can also write: 12 " let OPTION_NAME = 1 13 " to enable particular options. At present, all options default to on. 14 " 15 " - go_highlight_array_whitespace_error 16 " Highlights white space after "[]". 17 " - go_highlight_chan_whitespace_error 18 " Highlights white space around the communications operator that don't follow 19 " the standard style. 20 " - go_highlight_extra_types 21 " Highlights commonly used library types (os.Error, etc.). 22 " - go_highlight_space_tab_error 23 " Highlights instances of tabs following spaces. 24 " - go_highlight_trailing_whitespace_error 25 " Highlights trailing white space. 26 27 " Quit when a (custom) syntax file was already loaded 28 if exists("b:current_syntax") 29 finish 30 endif 31 32 if !exists("go_highlight_array_whitespace_error") 33 let go_highlight_array_whitespace_error = 1 34 endif 35 if !exists("go_highlight_chan_whitespace_error") 36 let go_highlight_chan_whitespace_error = 1 37 endif 38 if !exists("go_highlight_extra_types") 39 let go_highlight_extra_types = 1 40 endif 41 if !exists("go_highlight_space_tab_error") 42 let go_highlight_space_tab_error = 1 43 endif 44 if !exists("go_highlight_trailing_whitespace_error") 45 let go_highlight_trailing_whitespace_error = 1 46 endif 47 48 syn case match 49 50 syn keyword goDirective package import 51 syn keyword goDeclaration var const type 52 syn keyword goDeclType struct interface 53 54 hi def link goDirective Statement 55 hi def link goDeclaration Keyword 56 hi def link goDeclType Keyword 57 58 " Keywords within functions 59 syn keyword goStatement defer go goto return break continue fallthrough 60 syn keyword goConditional if else switch select 61 syn keyword goLabel case default 62 syn keyword goRepeat for range 63 64 hi def link goStatement Statement 65 hi def link goConditional Conditional 66 hi def link goLabel Label 67 hi def link goRepeat Repeat 68 69 " Predefined types 70 syn keyword goType chan map bool string 71 syn keyword goSignedInts int int8 int16 int32 int64 72 syn keyword goUnsignedInts byte uint uint8 uint16 uint32 uint64 uintptr 73 syn keyword goFloats float float32 float64 74 75 hi def link goType Type 76 hi def link goSignedInts Type 77 hi def link goUnsignedInts Type 78 hi def link goFloats Type 79 80 " Treat func specially: it's a declaration at the start of a line, but a type 81 " elsewhere. Order matters here. 82 syn match goType /\<func\>/ 83 syn match goDeclaration /^func\>/ 84 85 " Predefined functions and values 86 syn keyword goBuiltins cap close closed convert len make new panic panicln print println 87 syn keyword goConstants iota true false nil 88 89 hi def link goBuiltins Keyword 90 hi def link goConstants Keyword 91 92 " Comments; their contents 93 syn keyword goTodo contained TODO FIXME XXX BUG 94 syn cluster goCommentGroup contains=goTodo 95 syn region goComment start="/\*" end="\*/" contains=@goCommentGroup 96 syn region goComment start="//" end="$" contains=@goCommentGroup 97 98 hi def link goComment Comment 99 hi def link goTodo Todo 100 101 " Go escapes 102 syn match goEscapeOctal display contained "\\[0-7]\{3}" 103 syn match goEscapeC display contained +\\[abfnrtv\\'"]+ 104 syn match goEscapeX display contained "\\x\x\{2}" 105 syn match goEscapeU display contained "\\u\x\{4}" 106 syn match goEscapeBigU display contained "\\U\x\{8}" 107 syn match goEscapeError display contained +\\[^0-7xuUabfnrtv\\'"]+ 108 109 hi def link goEscapeOctal goSpecialString 110 hi def link goEscapeC goSpecialString 111 hi def link goEscapeX goSpecialString 112 hi def link goEscapeU goSpecialString 113 hi def link goEscapeBigU goSpecialString 114 hi def link goSpecialString Special 115 hi def link goEscapeError Error 116 117 " Strings and their contents 118 syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError 119 syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup 120 syn region goRawString start=+`+ end=+`+ 121 122 hi def link goString String 123 hi def link goRawString String 124 125 " Characters; their contents 126 syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU 127 syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup 128 129 hi def link goCharacter Character 130 131 " Regions 132 syn region goBlock start="{" end="}" transparent fold 133 syn region goParen start='(' end=')' transparent 134 135 " Integers 136 syn match goDecimalInt "\<\d\+\>" 137 syn match goHexadecimalInt "\<0x\x\+\>" 138 syn match goOctalInt "\<0\o\+\>" 139 syn match goOctalError "\<0\o*[89]\d*\>" 140 141 hi def link goDecimalInt Integer 142 hi def link goHexadecimalInt Integer 143 hi def link goOctalInt Integer 144 hi def link Integer Number 145 146 " Floating point 147 syn match goFloat "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>" 148 syn match goFloat "\<\.\d\+\([Ee][-+]\d\+\)\?\>" 149 syn match goFloat "\<\d\+[Ee][-+]\d\+" 150 151 hi def link goFloat Float 152 153 " Spaces after "[]" 154 if go_highlight_array_whitespace_error != 0 155 syn match goSpaceError display "\(\[\]\)\@<=\s\+" 156 endif 157 158 " Spacing errors around the 'chan' keyword 159 if go_highlight_chan_whitespace_error != 0 160 " receive-only annotation on chan type 161 syn match goSpaceError display "\(<-\)\@<=\s\+\(chan\>\)\@=" 162 " send-only annotation on chan type 163 syn match goSpaceError display "\(\<chan\)\@<=\s\+\(<-\)\@=" 164 " value-ignoring receives in a few contexts 165 syn match goSpaceError display "\(\(^\|[={(,;]\)\s*<-\)\@<=\s\+" 166 endif 167 168 " Extra types commonly seen 169 if go_highlight_extra_types != 0 170 syn match goExtraType /\<bytes\.\(Buffer\)\>/ 171 syn match goExtraType /\<io\.\(Reader\|Writer\|ReadWriter\|ReadWriteCloser\)\>/ 172 syn match goExtraType /\<\(os\.Error\)\>/ 173 syn match goExtraType /\<reflect\.\w*\(Type\|Value\)\>/ 174 syn match goExtraType /\<unsafe\.Pointer\>/ 175 endif 176 177 " Space-tab error 178 if go_highlight_space_tab_error != 0 179 syn match goSpaceError display " \+\t"me=e-1 180 endif 181 182 " Trailing white space error 183 if go_highlight_trailing_whitespace_error != 0 184 syn match goSpaceError display excludenl "\s\+$" 185 endif 186 187 hi def link goExtraType Type 188 hi def link goSpaceError Error 189 190 let b:current_syntax = "go"