github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/misc/vim/syntax/go.vim (about)

     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 (io.Reader, 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 error
    71  syn keyword     goSignedInts        int int8 int16 int32 int64 rune
    72  syn keyword     goUnsignedInts      byte uint uint8 uint16 uint32 uint64 uintptr
    73  syn keyword     goFloats            float32 float64
    74  syn keyword     goComplexes         complex64 complex128
    75  
    76  hi def link     goType              Type
    77  hi def link     goSignedInts        Type
    78  hi def link     goUnsignedInts      Type
    79  hi def link     goFloats            Type
    80  hi def link     goComplexes         Type
    81  
    82  " Treat func specially: it's a declaration at the start of a line, but a type
    83  " elsewhere. Order matters here.
    84  syn match       goType              /\<func\>/
    85  syn match       goDeclaration       /^func\>/
    86  
    87  " Predefined functions and values
    88  syn keyword     goBuiltins          append cap close complex copy delete imag len
    89  syn keyword     goBuiltins          make new panic print println real recover
    90  syn keyword     goConstants         iota true false nil
    91  
    92  hi def link     goBuiltins          Keyword
    93  hi def link     goConstants         Keyword
    94  
    95  " Comments; their contents
    96  syn keyword     goTodo              contained TODO FIXME XXX BUG
    97  syn cluster     goCommentGroup      contains=goTodo
    98  syn region      goComment           start="/\*" end="\*/" contains=@goCommentGroup,@Spell
    99  syn region      goComment           start="//" end="$" contains=@goCommentGroup,@Spell
   100  
   101  hi def link     goComment           Comment
   102  hi def link     goTodo              Todo
   103  
   104  " Go escapes
   105  syn match       goEscapeOctal       display contained "\\[0-7]\{3}"
   106  syn match       goEscapeC           display contained +\\[abfnrtv\\'"]+
   107  syn match       goEscapeX           display contained "\\x\x\{2}"
   108  syn match       goEscapeU           display contained "\\u\x\{4}"
   109  syn match       goEscapeBigU        display contained "\\U\x\{8}"
   110  syn match       goEscapeError       display contained +\\[^0-7xuUabfnrtv\\'"]+
   111  
   112  hi def link     goEscapeOctal       goSpecialString
   113  hi def link     goEscapeC           goSpecialString
   114  hi def link     goEscapeX           goSpecialString
   115  hi def link     goEscapeU           goSpecialString
   116  hi def link     goEscapeBigU        goSpecialString
   117  hi def link     goSpecialString     Special
   118  hi def link     goEscapeError       Error
   119  
   120  " Strings and their contents
   121  syn cluster     goStringGroup       contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
   122  syn region      goString            start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
   123  syn region      goRawString         start=+`+ end=+`+
   124  
   125  hi def link     goString            String
   126  hi def link     goRawString         String
   127  
   128  " Characters; their contents
   129  syn cluster     goCharacterGroup    contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU
   130  syn region      goCharacter         start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup
   131  
   132  hi def link     goCharacter         Character
   133  
   134  " Regions
   135  syn region      goBlock             start="{" end="}" transparent fold
   136  syn region      goParen             start='(' end=')' transparent
   137  
   138  " Integers
   139  syn match       goDecimalInt        "\<\d\+\([Ee]\d\+\)\?\>"
   140  syn match       goHexadecimalInt    "\<0x\x\+\>"
   141  syn match       goOctalInt          "\<0\o\+\>"
   142  syn match       goOctalError        "\<0\o*[89]\d*\>"
   143  
   144  hi def link     goDecimalInt        Integer
   145  hi def link     goHexadecimalInt    Integer
   146  hi def link     goOctalInt          Integer
   147  hi def link     Integer             Number
   148  
   149  " Floating point
   150  syn match       goFloat             "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>"
   151  syn match       goFloat             "\<\.\d\+\([Ee][-+]\d\+\)\?\>"
   152  syn match       goFloat             "\<\d\+[Ee][-+]\d\+\>"
   153  
   154  hi def link     goFloat             Float
   155  
   156  " Imaginary literals
   157  syn match       goImaginary         "\<\d\+i\>"
   158  syn match       goImaginary         "\<\d\+\.\d*\([Ee][-+]\d\+\)\?i\>"
   159  syn match       goImaginary         "\<\.\d\+\([Ee][-+]\d\+\)\?i\>"
   160  syn match       goImaginary         "\<\d\+[Ee][-+]\d\+i\>"
   161  
   162  hi def link     goImaginary         Number
   163  
   164  " Spaces after "[]"
   165  if go_highlight_array_whitespace_error != 0
   166    syn match goSpaceError display "\(\[\]\)\@<=\s\+"
   167  endif
   168  
   169  " Spacing errors around the 'chan' keyword
   170  if go_highlight_chan_whitespace_error != 0
   171    " receive-only annotation on chan type
   172    syn match goSpaceError display "\(<-\)\@<=\s\+\(chan\>\)\@="
   173    " send-only annotation on chan type
   174    syn match goSpaceError display "\(\<chan\)\@<=\s\+\(<-\)\@="
   175    " value-ignoring receives in a few contexts
   176    syn match goSpaceError display "\(\(^\|[={(,;]\)\s*<-\)\@<=\s\+"
   177  endif
   178  
   179  " Extra types commonly seen
   180  if go_highlight_extra_types != 0
   181    syn match goExtraType /\<bytes\.\(Buffer\)\>/
   182    syn match goExtraType /\<io\.\(Reader\|Writer\|ReadWriter\|ReadWriteCloser\)\>/
   183    syn match goExtraType /\<reflect\.\(Kind\|Type\|Value\)\>/
   184    syn match goExtraType /\<unsafe\.Pointer\>/
   185  endif
   186  
   187  " Space-tab error
   188  if go_highlight_space_tab_error != 0
   189    syn match goSpaceError display " \+\t"me=e-1
   190  endif
   191  
   192  " Trailing white space error
   193  if go_highlight_trailing_whitespace_error != 0
   194    syn match goSpaceError display excludenl "\s\+$"
   195  endif
   196  
   197  hi def link     goExtraType         Type
   198  hi def link     goSpaceError        Error
   199  
   200  " Search backwards for a global declaration to start processing the syntax.
   201  "syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/
   202  
   203  " There's a bug in the implementation of grouphere. For now, use the
   204  " following as a more expensive/less precise workaround.
   205  syn sync minlines=500
   206  
   207  let b:current_syntax = "go"