misc: adds extern class type to vim syntax highlighting
[nit.git] / misc / vim / syntax / nit.vim
1 " Vim syntax file
2 " Language:     Nit
3 " Maintainer:   Jean Privat <jean@pryen.org>
4
5 " This file is part of NIT ( http://www.nitlanguage.org ).
6 "
7 " Copyright 2009 Jean Privat <jean@pryen.org>
8 "
9 " Licensed under the Apache License, Version 2.0 (the "License");
10 " you may not use this file except in compliance with the License.
11 " You may obtain a copy of the License at
12 "
13 "     http://www.apache.org/licenses/LICENSE-2.0
14 "
15 " Unless required by applicable law or agreed to in writing, software
16 " distributed under the License is distributed on an "AS IS" BASIS,
17 " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 " See the License for the specific language governing permissions and
19 " limitations under the License.
20
21 if exists("b:current_syntax")
22         finish
23 endif
24
25 " Expression Substitution and Backslash Notation
26 syn match NITExprSubstError "{\|}" contained
27 syn match NITExprSubst "\\." contained
28 syn match NITExprSubst "{[^}]*}" contained
29
30 " Numbers and ASCII Codes
31 syn match NITNumber "\<\(\d\+\.\d\+\|\d\+\)\>"
32
33 " Identifiers
34 syn match NITClass              "\<\u\w*"
35 syn match NITAttribute          "\<_\h\w*"
36
37 " Literal strings
38 syn region NITString matchgroup=NITStringDelimit start="\"" end="\"" skip="\\\\\|\\\"" contains=NITExprSubst,NITExprSubstError
39 syn region NITString matchgroup=NITStringDelimit start="'"  end="'"  skip="\\\\\|\\'"
40
41 " Labels
42 syn match NITLabel "\<label \h\w*"
43
44 " Closures
45 syn match NITClosure "!\h\w*"
46
47 " Fallback highlight keywords
48 syn match NITNull "\<\(null\)\>"
49 syn match NITControl "\<\(init\|end\|not null\|not\|var\|do\|then\|else\|loop\)\>"
50 syn match NITKeyword "\<\(super\)\>"
51 " Unmatchning error
52 syn match Error "\<end\>"
53
54 " Declarations, definitions and blocks
55 syn region NITModuleDecl matchgroup=NITDefine start="\<\(import\|module\|package\)\>\s*" matchgroup=NONE end="\ze\(\s\|:\|(\|$\)"  oneline
56 syn region NITClassBlock matchgroup=NITDefine start="\<\(class\|enum\|universal\|interface\|extern\)\>" matchgroup=NITDefine end="\<end\>" contains=ALL fold
57 syn region NITFunctionDecl matchgroup=NITDefine start="\<fun\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline
58 syn region NITTypeDecl matchgroup=NITDefine start="\<type\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
59 syn region NITAttrDecl matchgroup=NITDefine start="\<var\>\s*\ze_" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
60 syn region NITInitDecl matchgroup=NITDefine start="\<init\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
61 syn match NITDefine "\<\(super\)\ze\s\+[A-Z]" contained containedin=NITClassBlock
62
63 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>\ze\s*\(#\|$\)" matchgroup=NITControl end="^\s*\<\(end\|\zeelse\|\ze!\)\>" contains=ALLBUT,NITTypeDecl,NITAttrDecl,NITInitDecl
64 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>" matchgroup=NITControl end="\<end\>" oneline
65
66 if !exists("NIT_minlines")
67         let NIT_minlines = 50
68 endif
69 exec "syn sync minlines=" . NIT_minlines
70
71 " Comments and Documentation
72 syn match  NITSharpBang "\%^#!.*"
73 syn match  NITComment   "#.*" contains=NITTodo
74
75 " Keywords
76 syn keyword NITKeyword   is abstract intern new
77 syn keyword NITDefine    private public protected intrude readable writable redef
78 syn keyword NITControl   if while for assert and or in as isa once break continue return abort
79 syn keyword NITClass     nullable
80 syn keyword NITInclude   special
81 syn keyword NITTodo      FIXME NOTE TODO XXX contained
82 syn keyword NITBoolean   true false
83 syn keyword NITSelf      self
84
85 " Define the default highlighting.
86 hi def link NITDefine                   Define
87 hi def link NITModuleDecl               Identifier
88 hi def link NITFunctionDecl             Function
89 hi def link NITTypeDecl                 Function
90 hi def link NITAttrDecl                 Function
91 hi def link NITInitDecl                 Function
92 hi def link NITControl                  Statement
93 hi def link NITLabel                    PreProc
94 hi def link NITInclude                  Include
95 hi def link NITNumber                   Number
96 hi def link NITBoolean                  Boolean
97 hi def link NITNull                     Constant
98 hi def link NITSelf                     Constant
99 hi def link NITClass                    Type
100 hi def link NITAttribute                Identifier
101 hi def link NITClosure                  Function
102 hi def link NITSharpBang                PreProc
103 hi def link NITKeyword                  Keyword
104
105 hi def link NITString                   String
106 hi def link NITStringDelimit            Delimiter
107 hi def link NITExprSubst                Special
108 hi def link NITExprSubstError           Error
109
110 hi def link NITComment                  Comment
111 hi def link NITTodo                     Todo
112
113 let b:current_syntax = "Nit"