Add proto buffers stuff
[cmccabe-etc] / .vim / syntax / proto.vim
1 " Protocol Buffers - Google's data interchange format
2 " Copyright 2008 Google Inc.
3 "
4 " Licensed under the Apache License, Version 2.0 (the "License");
5 " you may not use this file except in compliance with the License.
6 " You may obtain a copy of the License at
7 "
8 "      http:"www.apache.org/licenses/LICENSE-2.0
9 "
10 " Unless required by applicable law or agreed to in writing, software
11 " distributed under the License is distributed on an "AS IS" BASIS,
12 " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 " See the License for the specific language governing permissions and
14 " limitations under the License.
15
16 " This is the Vim syntax file for Google Protocol Buffers.
17 "
18 " Usage:
19 "
20 " 1. cp proto.vim ~/.vim/syntax/
21 " 2. Add the following to ~/.vimrc:
22 "
23 " augroup filetype
24 "   au! BufRead,BufNewFile *.proto setfiletype proto
25 " augroup end
26 "
27 " Or just create a new file called ~/.vim/ftdetect/proto.vim with the
28 " previous lines on it.
29
30 if version < 600
31   syntax clear
32 elseif exists("b:current_syntax")
33   finish
34 endif
35
36 syn case match
37
38 syn keyword pbTodo       contained TODO FIXME XXX
39 syn cluster pbCommentGrp contains=pbTodo
40
41 syn keyword pbSyntax     syntax import option
42 syn keyword pbStructure  package message group
43 syn keyword pbRepeat     optional required repeated
44 syn keyword pbDefault    default
45 syn keyword pbExtend     extend extensions to max
46 syn keyword pbRPC        service rpc returns
47
48 syn keyword pbType      int32 int64 uint32 uint64 sint32 sint64
49 syn keyword pbType      fixed32 fixed64 sfixed32 sfixed64
50 syn keyword pbType      float double bool string bytes
51 syn keyword pbTypedef   enum
52 syn keyword pbBool      true false
53
54 syn match   pbInt     /-\?\<\d\+\>/
55 syn match   pbInt     /\<0[xX]\x+\>/
56 syn match   pbFloat   /\<-\?\d*\(\.\d*\)\?/
57 " TODO: .proto also supports C-style block comments;
58 " see /usr/share/vim/vim70/syntax/c.vim for how it's done.
59 syn region  pbComment start="//" skip="\\$" end="$" keepend contains=@pbCommentGrp
60 syn region  pbString  start=/"/ skip=/\\"/ end=/"/
61 syn region  pbString  start=/'/ skip=/\\'/ end=/'/
62
63 if version >= 508 || !exists("did_proto_syn_inits")
64   if version < 508
65     let did_proto_syn_inits = 1
66     command -nargs=+ HiLink hi link <args>
67   else
68     command -nargs=+ HiLink hi def link <args>
69   endif
70
71   HiLink pbTodo         Todo
72
73   HiLink pbSyntax       Include
74   HiLink pbStructure    Structure
75   HiLink pbRepeat       Repeat
76   HiLink pbDefault      Keyword
77   HiLink pbExtend       Keyword
78   HiLink pbRPC          Keyword
79   HiLink pbType         Type
80   HiLink pbTypedef      Typedef
81   HiLink pbBool         Boolean
82
83   HiLink pbInt          Number
84   HiLink pbFloat        Float
85   HiLink pbComment      Comment
86   HiLink pbString       String
87
88   delcommand HiLink
89 endif
90
91 let b:current_syntax = "proto"
92