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