vim: add the keyword `with`
[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("main_syntax")
22   if version < 600
23     syntax clear
24   elseif exists("b:current_syntax")
25     finish
26   endif
27   " we define it here so that included files can test for it
28   let main_syntax='nit'
29 endif
30
31 " Expression Substitution and Backslash Notation
32 syn match NITExprSubstError "{\|}" contained
33 syn match NITExprSubst "\\." contained
34 syn match NITExprSubst "{\([^}]\|\n\)*}" contained
35
36 syn match NITExprSubstLong "\\." contained
37 syn match NITExprSubstLong "{*\zs{{{\([^}]\|\n\)*}}}\ze}*" contained
38
39 " Numbers
40 syn match NITNumber "\<\([0-9_]\+\|0[bB][01_]\+\|0[oO][0-7_]\+\|0[xX][0-9a-fA-F_]\+\)\([iu]\(8\|16\|32\)\)\?\>"
41 syn match NITNumber "\<[0-9_]\+\.[0-9_]\+\>"
42
43 " Identifiers
44 syn match NITClass              "\<\u\w*"
45 syn match NITAttribute          "\<_\h\w*"
46
47 " Literal strings
48 syn region NITString matchgroup=NITStringDelimit start="\"" end="\"" skip="\\\\\|\\\"" contains=NITExprSubst,NITExprSubstError,@Spell
49 syn region NITString matchgroup=NITStringDelimit start="\"\"\"" end="\"*\zs\"\"\"" skip="\\\\\|\\\"" contains=NITExprSubstLong,@Spell
50 syn region NITString matchgroup=NITStringDelimit start="'"  end="'"  skip="\\\\\|\\'"
51
52 " Labels
53 syn match NITLabel "\<label \h\w*"
54
55 " Closures
56 syn match NITClosure "!\h\w*"
57
58 " Fallback highlight keywords
59 syn match NITNull "\<\(null\)\>"
60 syn match NITControl "\<\(init\|end\|not null\|not\|var\|do\|then\|else\|loop\|is\)\>"
61 syn match NITKeyword "\<\(super\)\>"
62 " Unmatchning error
63 syn match Error "\<end\>"
64
65 " Declarations, definitions and blocks
66 syn region NITModuleDecl matchgroup=NITDefine start="\<\(import\|module\|package\)\>\s*" matchgroup=NONE end="\ze\(\s\|:\|(\|$\)"  oneline
67 syn region NITClassBlock matchgroup=NITDefine start="\<\(class\|enum\|universal\|interface\|extern\)\>" matchgroup=NITDefine end="\<end\>" contains=ALLBUT,NITAnnotLine fold
68 syn region NITFunctionDecl matchgroup=NITDefine start="\<fun\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline
69 syn region NITTypeDecl matchgroup=NITDefine start="\<type\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
70 syn region NITAttrDecl matchgroup=NITDefine start="\<var\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
71 syn region NITInitDecl matchgroup=NITDefine start="\<init\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
72 syn match NITDefine "\<\(super\)\ze\s\+[A-Z]" contained containedin=NITClassBlock
73
74 syn region NITAnnotBlock matchgroup=NITControl start="\<is\>\ze\s*\(#\|$\)" matchgroup=NITControl end="\(\ze\<do\>\|\<end\>\)" transparent contains=ALL
75 syn match NITAnnotLine "^\s*\zs\w\+" contained containedin=NITAnnotBlock
76
77 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>\ze\s*\(#\|$\)" matchgroup=NITControl end="^\s*\<\(end\|\zeelse\|\ze!\)\>" contains=ALLBUT,NITTypeDecl,NITAttrDecl,NITInitDecl,NITAnnotLine
78 syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\|loop\)\>" matchgroup=NITControl end="\<end\>" oneline
79 if !exists("NIT_minlines")
80         let NIT_minlines = 50
81 endif
82 exec "syn sync minlines=" . NIT_minlines
83
84 " Comments and Documentation
85 syn match  NITSharpBang "\%^#!.*"
86 syn match  NITComment   "#.*" contains=NITTodo,@Spell
87
88 " Keywords
89 syn keyword NITKeyword   abstract intern new
90 syn keyword NITDefine    private public protected intrude readable writable redef
91 syn keyword NITControl   if while for with assert and or in as isa once break continue return abort
92 syn keyword NITClass     nullable
93 syn keyword NITInclude   special
94 syn keyword NITTodo      FIXME NOTE TODO XXX contained
95 syn keyword NITBoolean   true false
96 syn keyword NITSelf      self
97
98 " Define the default highlighting.
99 hi def link NITDefine                   Define
100 hi def link NITModuleDecl               Identifier
101 hi def link NITFunctionDecl             Function
102 hi def link NITTypeDecl                 Function
103 hi def link NITAttrDecl                 Function
104 hi def link NITInitDecl                 Function
105 hi def link NITControl                  Statement
106 hi def link NITAnnotLine                Statement
107 hi def link NITLabel                    PreProc
108 hi def link NITInclude                  Include
109 hi def link NITNumber                   Number
110 hi def link NITBoolean                  Boolean
111 hi def link NITNull                     Constant
112 hi def link NITSelf                     Constant
113 hi def link NITClass                    Type
114 hi def link NITAttribute                Identifier
115 hi def link NITClosure                  Function
116 hi def link NITSharpBang                PreProc
117 hi def link NITKeyword                  Keyword
118
119 hi def link NITString                   String
120 hi def link NITStringDelimit            Delimiter
121 hi def link NITExprSubst                Special
122 hi def link NITExprSubstLong            Special
123 hi def link NITExprSubstError           Error
124
125 hi def link NITComment                  Comment
126 hi def link NITTodo                     Todo
127
128 " FFI Section
129 syn match NITFFIDelimiters "\<\(`{\|`}\)\>"
130 hi def link NITFFIDelimiters            Keyword
131
132 " FFI Python
133 syntax include @FFIPython syntax/python.vim
134 unlet b:current_syntax
135 syn match NITFFILanguage        /\c"Python"\ze.*`{/ nextgroup=NITFFIBlockPython skipwhite
136 syn region NITFFIBlockPython matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIPython
137
138 " FFI Java
139 syntax include @FFIJava syntax/java.vim
140 unlet b:current_syntax
141 syn match NITFFILanguage        /\c"Java\(\| inner\)"\ze.*`{/ nextgroup=NITFFIBlockJava skipwhite
142 syn region NITFFIBlockJava matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIJava
143
144 " FFI C++
145 syntax include @FFICpp syntax/cpp.vim
146 unlet b:current_syntax
147 syn match NITFFILanguage        /\c"C++\(\| header\| body\)"\ze.*`{/ nextgroup=NITFFIBlockCpp skipwhite
148 syn region NITFFIBlockCpp matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFICpp
149
150 " FFI Objective-C
151 syntax include @FFIObjC syntax/objc.vim
152 unlet b:current_syntax
153 syn match NITFFILanguage        /\c"ObjC\(\| Header\| Body\)"\ze.*`{/ nextgroup=NITFFIBlockObjC skipwhite
154 syn region NITFFIBlockObjC matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIObjC
155
156 " FFI C (the last one is the default)
157 syntax include @FFIC syntax/c.vim
158 unlet b:current_syntax
159 syn match NITFFILanguage                /\c"C\(\| header\| body\)"\ze.*`{/      nextgroup=NITFFIBlockC skipwhite
160 syn region NITFFIBlockC matchgroup=NITFFI start='`{' matchgroup=NITFFI end='`}' keepend fold contains=@FFIC
161
162 hi def link NITFFILanguage              Define
163
164 let b:current_syntax = "Nit"