misc: add vim syntax and indent files
[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 NITExprSubst "\\." contained
27 syn match NITExprSubst "{[^}]*}" contained
28
29 " Numbers and ASCII Codes
30 syn match NITNumber "\<\(\d\+\.\d\+\|\d\+\)\>"
31
32 " Identifiers
33 syn match NITClass              "\u\w*"
34 syn match NITAttribute          "\<_\h\w*"
35
36 " Literal strings
37 syn region NITString matchgroup=NITStringDelimit start="\"" end="\"" skip="\\\\\|\\\"" contains=NITExprSubst
38 syn region NITString matchgroup=NITStringDelimit start="'"  end="'"  skip="\\\\\|\\'"
39
40
41 " Fallback highlight keywords
42 syn match NITBoolean "\<\(null\)\>"
43 syn match NITControl "\<\(init\|end\|not null\|not\|var\|do\|then\|else\|with\)\>"
44 " Unmatchning error
45 syn match Error "\<end\>"
46
47 " Declarations, definitions and blocks
48 syn region NITPackageDecl matchgroup=NITDefine start="\<\(import\|package\)\>\s*" matchgroup=NONE end="\ze\(\s\|:\|(\|$\)"  oneline
49 syn region NITClassBlock matchgroup=NITDefine start="\<\(class\|universal\|interface\)\>" matchgroup=NITDefine end="\<end\>" contains=ALL fold
50 syn region NITFunctionDecl matchgroup=NITDefine start="\<\(meth\|fun\)\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline
51 syn region NITTypeDecl matchgroup=NITDefine start="\<type\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
52 syn region NITAttrDecl matchgroup=NITDefine start="\<\(var\|attr\)\>\s*\ze_" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
53 syn region NITInitDecl matchgroup=NITDefine start="\<init\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
54
55 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\)\>\ze\s*\(#\|$\)" matchgroup=NITControl end="^\s*\<\(end\|\zeelse\|with\)\>" contains=ALLBUT,NITTypeDecl,NITAttrDecl,NITInitDecl
56 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\)\>" matchgroup=NITControl end="\<end\>" oneline
57
58 if !exists("NIT_minlines")
59         let NIT_minlines = 50
60 endif
61 exec "syn sync minlines=" . NIT_minlines
62
63 " Comments and Documentation
64 syn match  NITSharpBang "\%^#!.*"
65 syn match  NITComment   "#.*" contains=NITTodo
66
67 " Keywords
68 syn keyword NITKeyword   is abstract intern extern
69 syn keyword NITDefine    private public protected intrude readable writable redef
70 syn keyword NITControl   if while for assert
71 syn keyword NITControl   and or in as isa
72 syn keyword NITControl   break continue return label abort
73 syn keyword NITKeyword   super new nullable
74 syn keyword NITInclude   special
75 syn keyword NITTodo      FIXME NOTE TODO XXX contained
76 syn keyword NITBoolean   true false self
77
78 " Define the default highlighting.
79 hi def link NITDefine                   Define
80 hi def link NITPackageDecl              Identifier
81 hi def link NITFunctionDecl             Function
82 hi def link NITTypeDecl                 Function
83 hi def link NITAttrDecl                 Function
84 hi def link NITInitDecl                 Function
85 hi def link NITControl                  Statement
86 hi def link NITInclude                  Include
87 hi def link NITNumber                   Number
88 hi def link NITBoolean                  Boolean
89 hi def link NITClass                    Type
90 hi def link NITAttribute                Identifier
91 hi def link NITSharpBang                PreProc
92 hi def link NITKeyword                  Keyword
93
94 hi def link NITString                   String
95 hi def link NITStringDelimit            Delimiter
96 hi def link NITExprSubst                Special
97
98 hi def link NITComment                  Comment
99 hi def link NITTodo                     Todo
100
101 let b:current_syntax = "Nit"